public
Created

Knockout: Detatchable dependentObservable

  • Download Gist
detatchableObservable.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// A dependentObservable that can be written to and reverted.
ko.detatchableDependentObservable = function(value, model) {
var root_value = typeof value === 'function' ? ko.dependentObservable(value, model) : ko.observable(value);
var public_value = ko.observable(root_value());
root_value.subscribe(function(value){
public_value(value);
});
var public_ = ko.dependentObservable({read: public_value, write: function(value){ public_.isConnected(false); public_value(value); }});
public_.isConnected = ko.observable(true);
public_.reconnect = function(){ this.isConnected(true); public_value(root_value()); };
public_.disconnect = function(){ this.isConnected(false); };
 
return public_;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.