[FEATURE array-helper] Implement array helper RFC #318#17054
[FEATURE array-helper] Implement array helper RFC #318#17054rwjblue merged 1 commit intoemberjs:masterfrom
Conversation
rwjblue
left a comment
There was a problem hiding this comment.
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
arrayresult into a component invocation, and that component using{{#eachproperly rerenders/updates as items change - Checking that the output of
arrayfollows the "immutable" style by having a component that we control which is passed anarrayand we inspect it for===equality.
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
|
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.