Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Sep 3, 2019

Conversation

chancancode
Copy link
Member

@chancancode chancancode commented Sep 2, 2019

This patch implements emberjs/rfcs#523.

See the commit messages for more details.

packages/@ember/-internals/glimmer/lib/syntax/outlet.ts Outdated Show resolved Hide resolved
@@ -138,6 +222,7 @@ function stateFor(
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

@@ -57,6 +57,7 @@ export default class OutletView {
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).

packages/ember/tests/homepage_example_test.js Show resolved Hide resolved
packages/ember/tests/routing/substates_test.js Outdated Show resolved Hide resolved
@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