-
Notifications
You must be signed in to change notification settings - Fork 192
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
Rerender an {{#each
s block only when the specific item has changed
#1100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { trackedData } from '@glimmer/validator'; | ||
|
||
export function tracked(target: object, key: string) { | ||
let { getter, setter } = trackedData<any, any>(key); | ||
|
||
Object.defineProperty(target, key, { | ||
get() { | ||
return getter(this); | ||
}, | ||
|
||
set(value: unknown) { | ||
setter(this, value); | ||
}, | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,8 +307,13 @@ export class IterationItemReference<T = unknown> implements TemplatePathReferenc | |
} | ||
|
||
update(value: T) { | ||
dirtyTag(this.tag); | ||
this.itemValue = value; | ||
let { itemValue } = this; | ||
|
||
// TODO: refactor this https://github.com/glimmerjs/glimmer-vm/issues/1101 | ||
if (value !== itemValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remind me what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This. If the "iterable" is an array, then for each value in the array you have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn’t it be the key that we are checking for stability (not the item itself)? I realize that in the default case for Ember there is no difference between the two (since Ember uses For example, imagine the case where the array and its items are always regenerated (e.g. the immutable pattern) so you’ve used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT we're not checking the stability here. The key is used when checking the stability of the array itself via There's more though. If you have an array of objects and modify some property deep inside, then all of this iterator code is skipped and just that nested Also, TBH I don't understand why we should be comparing values here at all. Aren't there tags for every value anyways? Shouldn't we be checking those instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, glad you dug in here 😄. @pzuraq - Any reason we are checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the opposite in this case - we know that the value has possibly changed, and we need to dirty the tag if so and update it. We don't have another tag to check. |
||
dirtyTag(this.tag); | ||
this.itemValue = value; | ||
} | ||
} | ||
|
||
get(key: string): TemplatePathReference { | ||
|
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.
This test was not testing what it says it was, so I updated it to test that properly (which it does) and added a couple more tests