Implement trackedObject, trackedSet, trackedWeakSet, trackedMap, and trackedWeakMap#1748
Implement trackedObject, trackedSet, trackedWeakSet, trackedMap, and trackedWeakMap#1748NullVoxPopuli merged 7 commits intomainfrom
Conversation
|
9e94d43 to
f2f862f
Compare
| @test | ||
| 'get/set existing value'() { | ||
| this.assertReactivity( | ||
| class extends Component { | ||
| map = trackedMap([['foo', 456]]); | ||
|
|
||
| get value() { | ||
| return this.map.get('foo'); | ||
| } | ||
|
|
||
| update() { | ||
| this.map.set('foo', 123); | ||
| } | ||
| } | ||
| ); | ||
| } |
There was a problem hiding this comment.
is it worth adding a test asserting updating to the same value doesn't cause an update, for the default equals?
There was a problem hiding this comment.
do you mean something different from the first test in the file?
There was a problem hiding this comment.
Ah, I imagined an extra test case at the top which this idea mirrored. nvm this
| @@ -0,0 +1,125 @@ | |||
| import type { ReactiveOptions } from './types'; | |||
There was a problem hiding this comment.
❓ just curious if there are existing thoughts on a fully-managed object, where
nested objects/values would be tracked
There was a problem hiding this comment.
how do you mean?
There was a problem hiding this comment.
Thinking about something that proxies the whole object shape, to handle this type of case
const var = trackedObject({ foo: 123, bar: { zig: 'zag' } });
var.bar.zig = '...'; // reading var.bar is tracked but the write to zig isn't
const bar = var.bar; // read is tracked
bar.zig = '...'; // subsequent reads from here aren't, and update isn't
There was a problem hiding this comment.
You may be interested in this rfc:
Co-authored-by: Chandler Prall <cprall@salesforce.com>
…/weak-set-test.ts Co-authored-by: Chandler Prall <cprall@salesforce.com>
…/weak-set-test.ts Co-authored-by: Chandler Prall <cprall@salesforce.com>
| class extends Component { | ||
| collection = trackedObject({ foo: 123 }, { equals: () => false }); | ||
| update() { | ||
| this.collection.foo = 789; |
There was a problem hiding this comment.
commenting this line out has no effect, looks like the test approach isn't correct?
There was a problem hiding this comment.
Perhaps, ya. These were copied directly from tracked-built-ins -- i didn't put any thought in to them.
I would personally test reactivity a bit differently.
But i don't want to do that until we merge the ember and glimmer-vm monorepos
RFC: emberjs/rfcs#1068
Followup to: #1713
Changes from the tracked-built-ins implementation (as described by the RFC)
tracked-built-insbehavior back, you setequals: () => falseexample:
descriptionis currently unused, but @wycats has plans --descriptionis meant for debugger hintsProgress:
Tasks for self-review
equalsI found an issue with reactivity in the array implementation and I'm investigating that in a separate PR here: #1761
these other collections (for now) are more straight-forward