Skip to content

Implement RFC #523 (@model argument for route templates and {{mount}})#18345

Merged
rwjblue merged 6 commits intomasterfrom
model-arg
Sep 3, 2019
Merged

Implement RFC #523 (@model argument for route templates and {{mount}})#18345
rwjblue merged 6 commits intomasterfrom
model-arg

Conversation

@chancancode
Copy link
Member

@chancancode chancancode commented Sep 2, 2019

This patch implements emberjs/rfcs#523.

See the commit messages for more details.

outlet: render.outlet,
template,
controller: render.controller,
model: render.model,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model is allowed to be undefined, so it shouldn't cause any errors if it's not present

outlet: TOP_LEVEL_OUTLET,
name: TOP_LEVEL_NAME,
controller: undefined,
model: undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'd prefer to make this more generic in the internals. As mentioned above, @ember/test-helpers uses outlet state to support rendering tests, and it would be quite nice to allow them to use named arguments (instead of requiring this.foo from the test context). It seems that making this structure a tad more generic (but preventing routes from using it) would allow that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a good future improvement 😄

(It is not exactly trivial to translate this to be more generic either, due to the way things are implemented)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, totally agree this isn't a blocker, but I would love to discuss this sometime with you (hopefully while the issue is still somewhat fresh in your mind).

@rwjblue
Copy link
Member

rwjblue commented Sep 2, 2019

Most of my comments are around the idea of not testing this.model after the feature lands (which is not good). I may have gotten carried away (🙃), but in general it seems largely fine if the goal is to:

  • optimize for the non-feature tests to be completely deleted, and therefore doing more work upfront (by effectively duplicating all of the tests that use {{model}})
  • ensure there are at least a few of each test type for this.model (to ensure we don't regress functionality)

Cleaned up a bunch of tests to use `{{this.model}}` explicitly, as opposed to
the implicit `{{model}}`.

Most of these tests just so happened to use a context variable named `model`,
but otherwise has nothing to do with controllers or routing. They probably can
be further refactored to use a different name altogether to avoid confusion.

Also took the opportunity to convert things into async functions in several
places.
This was previously not working properly for `@feature(!SOME_NAME)`.
@chancancode chancancode force-pushed the model-arg branch 3 times, most recently from eeac160 to 6439f75 Compare September 3, 2019 07:08
The key changes are in `route.ts` and `syntax/outlet.ts`.

The rest are just threading through those new values and test changes.
This is an extension to the RFC not explicitly written in the RFC text.

I missed this when writing the RFC, but we felt that `{{mount}}` with
the `model=` argument is even more clearly an argument, and that we
explicitly decided to restrict the `{{mount}}` syntax to a single
`model` argument (as opposed to arbitrary named arguments), so it is
within the spirit of the RFC to make this work also.

This also refactor the implementation of `{{mount}}` to do less custom
work (like diffing the tag) and let Glimmer VM do more of the work via
the usual paths.
This ensures `{{this.model}}` and the implicit `{{model}}` contunue
to be tested, to prevent any future regressions. It also tests the
behavior described in the RFC where `this.model` and `@model` could
diverge.
@rwjblue rwjblue merged commit 1851384 into master Sep 3, 2019
@rwjblue rwjblue deleted the model-arg branch September 3, 2019 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants