Repository navigation
Conversation
|
|
||
| If `key` is a function, then Glimmer's diffing algorithm will call this function to determine the item's key. | ||
|
|
||
| For `each`, the function would be called with arguments `keyFn(item, index)`. |
There was a problem hiding this comment.
this seems strange because in an array the index is sort of like that key, which means in one case we're passing key, value and value, key in the other case 🤔
There was a problem hiding this comment.
The arguments are intended to match the order of the block params for those helpers.
| For `each`, the function would be called with arguments `keyFn(item, index)`. | ||
| For `each-in`, the function would be called with arguments `keyFn(key, value)`. | ||
|
|
||
| The key function should not be invoked with a `this`. |
There was a problem hiding this comment.
That glimmer should call the key function as keyFn(...args) as not to bind this to any particular value.
There was a problem hiding this comment.
but with #308 would we then need to use key=this.someUnboundFunction? would seem strange if that was actually not bound to this in that case 🤔
There was a problem hiding this comment.
I don't think it's strange. For example,
is also not bound. This is generally true (albeit a bit annoying!) in Handlebars today. You have to write
There was a problem hiding this comment.
yeah, true, I guess passing around this.someUnboundFunction in JS also doesn't have to mean that it's bound...
rwjblue
left a comment
There was a problem hiding this comment.
Left a couple of small tweak suggestions inline, but I'm definitely 👍 on this...
|
|
||
| ## Motivation | ||
|
|
||
| The `key` argument to `each` and `each-in` determines the key used in the Glimmer diffing algorithm. Here is a description of the currently accepted values? |
There was a problem hiding this comment.
The ending question mark seems pretty out of place here. Is this a description of the current support, or is the RFC asking for clarification?
There was a problem hiding this comment.
There was a problem hiding this comment.
Yeah, I don't know what I was thinking?
|
|
||
| ## How we teach this | ||
|
|
||
| This feature just needs to be documented in the API docs and possibly the guides. We may want to reframe the existing (string-based) key documentation to be explained as shorthands for key functions. |
There was a problem hiding this comment.
I'd prefer to remove "just" here, otherwise 👍
|
|
||
| `key` argument | `each` key function | `each-in` key function | ||
| ---------------|------------------------------------|----------------------------------- | ||
| `@identity` | `(item, index) => guidFor(item)` | `(key, value) => guidFor(value)` |
There was a problem hiding this comment.
One possible suggestion I have is to reverse the order of the arguments in one of the functions. I believe that the value should be in the same position in both.
key argument |
each key function |
each-in key function |
|---|---|---|
@identity |
(item, index) => guidFor(item) |
(value, key) => guidFor(value) |
or
key argument |
each key function |
each-in key function |
|---|---|---|
@identity |
(index, item) => guidFor(item) |
(key, value) => guidFor(value) |
I have the feeling that it would make the table simpler:
key argument |
key function for both |
|---|---|
@identity |
(_, value) => guidFor(value) |
@index/@key |
(ref, _) => ref |
| other strings | (_, value) => get(value, path) |
However I also see the convenience on {{each}} taking the arguments in the same order that .forEach and {{each-in}} having them as (key, value)
There was a problem hiding this comment.
That order seems plausible since it's the order you get when calling the Array.prototype.entries and Map.prototype.entries iterators, however I think it still makes more sense to mirror the block param order.
Additionally, I don't like promoting array index to the first slot because you almost never want to use it as a key (unless you know the whole #each block is stateless and you know that no one will ever add a stateful component/helper into it in the future, see https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318).
There was a problem hiding this comment.
Yeah, I'm not really opposed to the proposed order, I just thought that this one presented a "chance for unification", in case that was desirable or simplified the implementation in any form. I'm happy either way.
|
I'm definitely a 👍 on this. With ember-apollo-client, we're always just passing either POJOs wrapped in an However, users typically already have to tell Apollo how to get a unique identifier from their objects by configuring a The proposal itself seems straightforward and I would love to see it built. |
|
Seem like there has been some solid interest for this. I'm going to see if we can get some better review and a proper yay or nay on it. |
|
I'm moving this FCP to close since it's had virtually no activity in the last few years. If someone wants to pick this up and make sure the RFC is up to date, we can re-open. |
Rendered
Closes #306