I need a timestamp for when a value is updated. For reasons I won't go into here, the value
is a writable computed that points to a valueInstance
observable, so they basically show the same data.
If I subscribe to the observable it works as expected, only fires when the observable changes. If I subscribe to the computed it fires immediately causing a false timestamp, even though the observable is still undefined. What's up with this?
Update: looks like this only happens when the computed has deferEvaluation: true
function VM(){
var self = this;
self.valueInstance = ko.observable();
self.value = ko.computed({
read: function () {
return self.valueInstance();
},
write: function (value) {
self.valueInstance(value);
},
deferEvaluation: true
});
self.timeStamp1 = ko.observable();
self.value.subscribe(function (newValue) {
self.timeStamp1(new Date());
});
self.timeStamp2 = ko.observable();
self.valueInstance.subscribe(function (newValue) {
self.timeStamp2(new Date());
}); }