mbest / knockout

My enhancements to Knockout
35 stars 4 forks source link

react to changes of specific observables within computed #22

Open mbest opened 11 years ago

mbest commented 11 years ago

The pattern is to have a computed observable in which sections could be set up to run only when specific observables change. Example:

var A = ko.computed(function(didChange) {
    var c = 0;
    if (didChange(a)) {    // `a` is an observable
        // do something when `a` has changed
        c = a() + 1;
    }
    // also do something with other observables such as `b`
    return b() + c;
});

Something like this would provide another way to deal with setting up independent bindings. And it's something that's been asked about in the forums.