Is it possible in knockout to get the current value of an observable within a subscription to that observable, before it receives the new value?
Example:
this.myObservable = ko.observable();
this.myObservable.subscribe(function(newValue){
//I'd like to get the previous value of 'myObservable' here before it's set to newValue
});
Use the above like this:
Little change to Beagle90 answer. Always return the subscription itself to be able to access the dispose() for instance.
I have found that I can call peek() from a writable computed observable to get the before value.
Something like this (see http://jsfiddle.net/4MUWp):
There is a way to do a subscription to the before value like this:
The pull request to add this feature has some different code that winds up being better than relying on using the
beforeChange
event.All credit for the solution to Michael Best
To quote Michael: