Hi, using the last example posted by chriskrycho , as far as I can understand, when people
getter will be fired, it will return the this._previoudData
as a cache.
However, if inside the template we have something like this:
<OtherComponent @people={{this.people}}/>
and inside other-component.js
we have something like:
get someProperty() {
return this.doSomeHeavyComputation(this.args.people);
}
doSomeHeavyComputation
will be called right? It does not matter that people
getter served the results from cache, someProperty
getter will recompute. At least, that is what I noticed from testing.
So, this is a pretty big issue for me, because I have multiple attributes being propagated to child components, all of which are cached manually, but the child components all recompute.
I used to have an observer, something like this:
didChange: observer('userId', function() {
fetch(url, {userId: this.args.userId}).then((response) => {
this.profiles = response.profiles;
this.progress = response.progress;
this.otherStuff = response.otherStuff;
});
})
and I updated this to:
get userData() {
if(this.args.userId !== this._lastUserId) {
this._lastUserData = load(fetch(...));
this._lastUserId = this.args.userId;
}
return this._lastUserData;
}
get profiles() {
switch(this.userData.state) {
case 'LOADED':
this._profiles = this.userData.value.profiles;
break;
}
return this._profiles;
}
get progress() {
switch(this.userData.state) {
case 'LOADED':
this._progress= this.userData.value.progress;
break;
}
return this._progress;
}
The issue here is that, right after this.args.userId
updates, get userData
is called and reloads data from the server. This means that profiles
and progress
both get called, because this.userData.state
changes, and they both serve data from cache, as state is LOADING
. But this propagates to child components, and other getters/rerenders happen.
Is there a way I can avoid this, besides checking for identical values being received within each component (kinda like, applying a cache mechanism inside child components too)? The observer seemed much more simple, in this case.
Thank you so much.