-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
c8d70bd
to
7ba847d
Compare
7ba847d
to
c09abf8
Compare
packages/@ember/-internals/glimmer/lib/component-managers/custom.ts
Outdated
Show resolved
Hide resolved
26b5b4b
to
31dd0fa
Compare
packages/@ember/-internals/glimmer/tests/integration/components/tracked-test.js
Outdated
Show resolved
Hide resolved
this.assertText('hello!'); | ||
} | ||
|
||
'@test named args are enumerable'() { |
There was a problem hiding this comment.
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|}}
?
There was a problem hiding this comment.
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).
31dd0fa
to
fd5cff6
Compare
This PR adds the ability for computed properties and observers to watch
args
on custom components. Currently this does not work because theargs
object is not a standard object, but a proxy that forwardsproperty access to the
CapturedNamedArgs
instance for the component,and consumes its tag for autotracking.
CPs currently ignore autotracking, and have to depend on
args
manuallyvia the
chainTags
system. In the first attempt to support this we usedthe
UNKNOWN_PROPERTY_TAG
API, but that actually doesn't work for thiscase 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 towhat we do for
@each
. When the chain is looking upargs
as itssegment, 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).