Reputation: 3238
Let me explain. I have webapi controller that return some values later bind to UI with Knockout.js. One of the values I'm getting from the other controller but need to bind to the same element. In order to update ViewModel with new value, should I use subscribe method or computed? I'm new to Knockout.js, so please do not do not judge me strictly - many things making me confused even after reading docs.
Upvotes: 2
Views: 460
Reputation: 62015
In general:
Use observables for creating any view-model properties, computed or otherwise.
Code can also share the same observable object between multiple view-models, such that both literally provide the same observable. This should be done only after consideration, but it eliminates a "proxy" observable entirely.
In addition, it's also possible to use aggregation to allow a view to bind onto multiple-view models (either as siblings or through one vm being accessible as a property/observable of the other).
Use subscriptions for events and processing outside view-model properties.
In a few cases subscriptions can be useful for view-model maintenance, but they should generally not be preferred over standard view-model observables.
Upvotes: 1