-
-
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
[FEATURE array-helper] Implement array helper RFC #318 #17054
Conversation
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.
Looking good! I left some pretty nit-picky comments inline (sorry about that), but also would like to see a few more tests:
- Confirming that passing an
array
result into a component invocation, and that component using{{#each
properly rerenders/updates as items change - Checking that the output of
array
follows the "immutable" style by having a component that we control which is passed anarray
and we inspect it for===
equality.
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
a86b037
to
4ef1df2
Compare
@rwjblue I have applied the requested changes as well added a few more tests. Please take another round of review. |
LGTM, I also pinged @mmun for review... |
4ef1df2
to
0fab6f4
Compare
Should we debug freeze the array? The empty case is frozen like hashes iirc |
Yes, probably. |
Unfortunately debug freezing is not going to be super easy. We can merge this as-is and do a follow up PR for that. I also just realized that the current version of the glimmer code seems to always return a new array/object even for the empty case. We can do something like: class DebugFreezeReference<T> implements PathReference<T> {
constructor(private inner: PathReference<T>) {
this.tag = inner.tag;
}
value(): T {
return Object.freeze(this.inner.value());
}
get(path: string): PathReference<Opaque> {
return this.inner.get(path); // or should this be `new DebugFreezeReference(this.inner.get(path))`?
}
}
function array(_vm: VM, args: Arguments): PathReference<Opaque[]> {
return new DebugFreezeReference(args.positional.capture());
}
function hash(_vm: VM, args: Arguments): PathReference<Dict<Opaque>> {
return new DebugFreezeReference(args.named.capture());
} |
0fab6f4
to
7cc684b
Compare
7cc684b
to
d6d9526
Compare
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/array-test.js
Show resolved
Hide resolved
Looking good. Probably should have a few more test testing "capturing" the array into JS values and make sure it is correct. Something like this: let captured;
this.registerHelper('capture', function([array]) {
captured = array;
return "captured";
});
this.render(`{{capture (array ...)}}`);
assert.deepEqual(captured, [...]);
this.runTask(this.set(...));
assert.deepEqual(captured, [...]);
... Basically what you already did in the last test, but more coverage around the actual values, and that it updates correctly, etc. You can probably just merge that into your last test since it's already doing similar things. |
d6d9526
to
59bd071
Compare
I have addressed the last few comments from @chancancode. This should be ready for another review. |
@josemarluedke have you tried the indentation style in #17054 (comment)? If the linter prefer you write it like this, it's nbd |
@chancancode Yes I did, I changed most of the code to that indentation style. I did not change all because some already had a line break due to component args. But if you do think I should change that as well, I'm happy to do so. |
Thank you! |
This implements the array helper.
RFC: emberjs/rfcs#318
Closes #17052.