-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allow normalization of results from computed properties #2111
Comments
Well, you don't have immediate access to the previous value, but I believe something like this should work, right? class {
firstTwoMemo = []
get firstTwo() : Array<Entity> {
const newValue = this.entities.slice(0, Math.min(this.entities.length, 2))
if (newValue !== this.firstTwoMemo) {
this.firstTwoMemo = newValue
}
return this.firstTwoMemo
}
} I suppose it might be more convenient having it in MobX, but unless you are willing to come up with PR, I think you will have to do with this solution. |
https://mobx.js.org/refguide/computed-decorator.html
EDIT: for arrays/objects you can use EDIT2: oh actually, I am not sure if decorator accepts options... but you can create standalone computed and use it from getter: get firstTwo() {
return this.firstTwoComputed.get();
} |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions. |
I have a:
Reduced rendering.
Everyone returning arrays or objects from
@computed
may benefit. It's no utility, just an option for@computed
.Not without getting a lot of help.
A simple property like
gets recomputed every time any entity change and returns a new array, which is quite often equal to the previous value (this example is a big simplification of what happens in a real project). It'd be nice to have something like
@computed(equals=myEquals)
, which would return the old value in casemyEquals
returns a truthy value.This normalization is something, I can't do myself, as I have no access to the old value. An alternative could be providing some global
mobx.oldComputedValue
accessible during the execution of the getter body.The text was updated successfully, but these errors were encountered: