-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
feat(cachedComputedFrom): decorator for computed properties with caching #398
Conversation
…ements temporary caching for repeated fast access while dependencies remain unchanged
@jdanyow what are your thoughts on this PR? |
…le calls to the computed property with unchanged and changed dependencies.
Perhaps something like this should be the default behavior? |
@EisenbergEffect Possibly. Initially, I thought of augmenting the computeFrom decorator to have a toggle for caching but I don't think that's a good idea just because it's giving one thing too much to do. I think there should definitely be 2 different behaviours, since it's not clear the sort of functions people use as their getters, they could well be impure and be expected to cause a myriad of side effects every time they are invoked. It's always good to have a choice |
What about just making the default to not cache unless specified. (I would like it to be the other way, but as you stated people could currently be doing some additional logic in their getters) @computedFrom("") -> not cached |
@jdanyow What if we aliased |
What if you want to specify a completely different object for the caching mechanism? @computedFrom("firstName", "lastName") Analyzes a different object to determine whether or not the value needs to be refreshed. |
@EisenbergEffect hey, so whatever you guys decide is best I'd be more than happy to implement it. The intention of this pull request really was both to get feedback on my solution to a problem I faced while creating an aurelia app but also to get my foot in the door with regard to making a habit of contributing to aurelia. It's not clear to me what needs contribution but I hope this is the beginning. |
Awesome! Thanks for being so willing to join in and help. @jdanyow Do you have any thoughts on this? |
Definitely a solid idea. I think this would make a nice plugin. Couple thoughts/suggestions:
|
Did this ever ended up being implemented anywhere (as a plugin or otherwise)? |
@Truffula thanks for notifying about this. I didn't know we had a PR for this. The current state of this plugin does not guarantee it works in all scenarios, as dependencies are simply retrieved via index/keyed operator There's a plugin here that gives you the cached |
cachedComputedFrom is just a caching-enabled version of computedFrom.
cachedComputedFrom implements temporary caching for repeated fast access to the computed property while it's dependencies remain unchanged.
I did some profiling and cachedComputedFrom was more performant where it needed to be, i.e. when the the computed property is the same if it's dependencies remain unchanged.