-
-
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
parametrical computed / recursive observation (make methods observable) #147
Comments
Is this the scenario: ko view: <span data-bind="text: computeValueForIndex(idx)"></span> ko view-model: // when ko invokes this function it makes note of the two observables that are called and will update bindings using this function when either of the two observables change
computeValueForIndex(idx) {
return this.someObservable()[idx] + this.otherObservable();
} In other words, we need the equivalent of |
precisely |
@jdanyow Should we consider rolling in your computed plugin? and somehow sharing code with that to address this and other related issues? |
Why not into core? |
Something I've been musing is adding KO auto-detect as an optional observation mecanism into Aurelia. I've been thinking about something could work like that (naming could be better): class ViewModel {
// This turns x into a property with instrumented getter,
// so that read access are detected
@dependency
x: number;
// can be a property or a method, or any piece of code in fact.
// autoDependencies means that during evaluation, @dependency reads
// should be collected and turned into dependencies,
// as if they had been added with @computedFrom
@autoDependencies
computed() {
return this.x;
}
} This is basically what KO does. It could be an interesting alternative to existing mechanisms (ideally provided as an optional module). A nice API could allow:
|
What was the status on this? Can we support |
I think we'd need to add logic to CallScope and CallMember's |
Sounds good. It can certainly be in a point release. |
This is exactly what i need! I try to do this all of the time, and need to keep putting more dirty code into the template - is there a status update on this? |
For those reading, I would say the current best practice for this use case is to use a binding signaler. See the gist here: https://gist.run/?id=d6c534d7b0a1b26fc3f27366b0e5b7a2 |
The bad part about binding signalers is that all signalers should be unique, there is no way to link signalers to specific component instance :-( |
@davismj Hey, I was wondering if there's any update on this? Or is the best practice still as per the gist posted above? |
A binding signaler only works if you have some kind of "event" (like a click). That's not the same as just updating the binding when observable values change. |
@massimocode Sorry I missed your mention. @glen-84 If you pass an observable variable--that is, any variable on your view model--to a function on your view model, that will make an observable method automatically. See here: https://gist.run/?id=0aa5bd84d78994e11e435eba811ab556 @bigopon I've solved all of my problems in this issue with the above method. |
In knockout, I would bind to a function that computes a value and returns a string. The value I passed in would largely be static, like an index on an array, but the function would then look up observables to compute the final value and thus set up subscriptions on those values.
In Aurelia, there is nothing like this. I cannot make a function called
computeValueForIndex(idx)
that subscribes to (or even dirty checks!) other variables on the view model. I cannot use a a computedget computeValueForIndex(idx)
because getters cannot accept parameters.The text was updated successfully, but these errors were encountered: