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(computedFrom): support expressions #346
Conversation
Very interesting stuff. With this in place, what do you think about adding the auto-dependency checking stuff that you had in that other plugin? Is it easy to add on top of this now that it's there? Or is that completely different? |
Definitely a step towards integrating that. If we do add the aurelia-computed capability here it would probably need to be opt-in via a decorator right? The explicit nature of the decorator would allow us to throw errors when we are not able to parse the expression(s) in the getter function's toString result. The other thing related to this I'm investigating is support for #147 by adding logic to @computedFrom('some', 'stuff')
myClassMethod(myArg) {
...
} to the equivalent of something like this: _myClassMethod(myArg) {
...
}
@computedFrom('some', 'stuff')
get myClassMethod() {
return _myClassMethod.bind(this);
} Then it should "just work":tm: provided this line is added here. What do you think? |
Sounds pretty good to me. |
Should we rename |
Update on #147: my plan didn't quite work. The changes to the decorator: export function computedFrom(...rest) {
return function(target, key, descriptor) {
+ if (!descriptor.get) {
+ let innerKey = '__' + key;
+ Object.defineProperty(target, innerKey, { enumerable: false, configurable: true, value: descriptor.value });
+ descriptor.get = function() { return this[innerKey]; };
+ descriptor.set = function(newValue) { this[innerKey] = newValue; };
+ delete descriptor.value;
+ delete descriptor.writable;
+ }
descriptor.get.dependencies = rest;
return descriptor;
}
} Basically say "when the dependencies change, notify the binding system that the decorated class method changed". This doesn't work. The class method doesn't ever change. The result of invoking the class method potentially has changed. This check (which is a valid check) prevents the change event from bubbling up and causing the binding to reevaluate. Will need to think about #147 a bit more while working on the rest of this stuff. OK to merge what I have so far? |
this was merged but rebasing the branch prevented the PR from closing automatically. Closing this manually... |
Does it work well? It looks like even previously working syntax without expressions stop to work well. I got master, build it and use method like that:
and the code fall back to dirty checking and eating all cpu. |
fixes #149