-
Notifications
You must be signed in to change notification settings - Fork 75
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
Don't recalculate derived properties until next access #233
Comments
The only issue I can think of is change listeners - any ideas on this? Should we be checking for the presence of a |
Are there many situations where you would have a derived property on a model, but would have no |
I'm not going to suggest that this has as nice an API as a derived property does - I've not tried to abstract it in any way - but an alternative way of doing this if you don't need the change events, and just want a cached getter, is to just create a cached getter, using If you do need the change events, then I'm not sure that you can avoid the current behaviour. Here's an example: |
Yes - I don't use I often use derived properties to mask and cache expensive operations that are not used often - until now I had assumed that recalculation was only done at access, not if any dep had changed. It should be relatively simple to record when change handlers have been attached. Can you think of any issues with this approach? |
I plan to submit a PR for this - opening this issue to track it.
The issue is that derived properties are often expensive, and any change to any dep causes a recalculate, even if the property has not been accessed.
Considering that derived props are already getters, dep changes should instead set a dirty flag (since
delete self._cache[name]
would cause deopt) which marks the property for recomputation.The text was updated successfully, but these errors were encountered: