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

[BUGFIX] Adds ability for computed props to depend on args #18217

Merged
merged 1 commit into from
Jul 30, 2019

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Jul 22, 2019

This PR adds the ability for computed properties and observers to watch
args on custom components. Currently this does not work because the
args object is not a standard object, but a proxy that forwards
property access to the CapturedNamedArgs instance for the component,
and consumes its tag for autotracking.

CPs currently ignore autotracking, and have to depend on args manually
via the chainTags system. In the first attempt to support this we used
the UNKNOWN_PROPERTY_TAG API, but that actually doesn't work for this
case because these aren't unknown properties, they do "exist" on the
proxy and should be enumerable.

Rather than adding another general API to the tagForProperty function,
I opted to add some special logic to the chainTags crawler, similar to
what we do for @each. When the chain is looking up args as its
segment, it'll also check to see if the value is an args proxy, and if
so it'll use the (saved) CapturedNamedArgs directly. This check should
be low overhead since it's a string comparison, and only applies to CPs
and observers rather than all code (compared to adding it to
tagForProperty, which would affect new code as well).

@pzuraq pzuraq force-pushed the bugfix/add-unknown-property-tag-to-args-proxy branch 3 times, most recently from c8d70bd to 7ba847d Compare July 24, 2019 22:10
@pzuraq pzuraq changed the title [BUGFIX] Adds UnknownPropertyTag to args proxy [BUGFIX] Adds ability for computed props to depend on args Jul 24, 2019
@pzuraq pzuraq force-pushed the bugfix/add-unknown-property-tag-to-args-proxy branch from 7ba847d to c09abf8 Compare July 24, 2019 22:47
@pzuraq pzuraq force-pushed the bugfix/add-unknown-property-tag-to-args-proxy branch 2 times, most recently from 26b5b4b to 31dd0fa Compare July 30, 2019 15:31
this.assertText('hello!');
}

'@test named args are enumerable'() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add another test for using {{#each-in this.args as |arg value|}}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good thing we added that, turns out it is necessary to support symbols in the proxy. I decided to make the guard in the get trap a bit more generic to handle that.

This PR adds the ability for computed properties and observers to watch
`args` on custom components. Currently this does not work because the
`args` object is not a standard object, but a proxy that forwards
property access to the `CapturedNamedArgs` instance for the component,
and consumes its tag for autotracking.

CPs currently ignore autotracking, and have to depend on `args` manually
via the `chainTags` system. In the first attempt to support this we used
the `UNKNOWN_PROPERTY_TAG` API, but that actually doesn't work for this
case because these _aren't_ unknown properties, they do "exist" on the
proxy and should be enumerable.

Rather than adding another general API to the `tagForProperty` function,
I opted to add some special logic to the `chainTags` crawler, similar to
what we do for `@each`. When the chain is looking up `args` as its
segment, it'll also check to see if the value is an args proxy, and if
so it'll use the (saved) CapturedNamedArgs directly. This check should
be low overhead since it's a string comparison, and only applies to CPs
and observers rather than _all_ code (compared to adding it to
`tagForProperty`, which would affect new code as well).
@pzuraq pzuraq force-pushed the bugfix/add-unknown-property-tag-to-args-proxy branch from 31dd0fa to fd5cff6 Compare July 30, 2019 17:26
@pzuraq pzuraq merged commit e629225 into master Jul 30, 2019
@delete-merged-branch delete-merged-branch bot deleted the bugfix/add-unknown-property-tag-to-args-proxy branch July 30, 2019 21:08
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.

None yet

2 participants