pureComputed awake without an "awake" event being notified
HTML
<script src="http://knockoutjs.com/downloads/knockout-3.4.2.debug.js"></script>
<button type="button" data-bind="click: showHideObservable">Show/Hide Observable</button>
<button type="button" data-bind="click: updateObservable">Update Observable</button>
<button type="button" data-bind="click: clearLog">Clear Log</button>
<div>observable=<span data-bind="text: observable"></span></div>
<h2>Log</h2>
<ul data-bind="foreach: logMessages"><li data-bind="text: $data"></li></ul>
JavaScript
function ViewModel() {
var self = this,
logger = function (msg) { self.logMessages.push(msg); },
underlyingValue = 14;
this.observable = ko.pureComputed(function () {
logger("reading observable (value=" + underlyingValue + ", _isSleeping=" + this.observable._state.isSleeping + ", isActive=" + this.observable.isActive() + ", subscription count=" + this.observable.getSubscriptionsCount("change") + ")");
return underlyingValue;
}, this).extend({ notify: 'always' });
this.observable.subscribe(function () { logger("observable awakening (value=" + underlyingValue + ", _isSleeping=" + this.observable._state.isSleeping + ", isActive=" + this.observable.isActive() + ", subscription count=" + this.observable.getSubscriptionsCount("change") + ")"); }, this, "awake");
this.observable.subscribe(function () { logger("observable asleeping (value=" + underlyingValue + ", _isSleeping=" + this.observable._state.isSleeping + ", isActive=" + this.observable.isActive() + ", subscription count=" + this.observable.getSubscriptionsCount("change") + ")"); }, this, "asleep");
this.updateObservable = function () {
logger("updating observable (old value=" + underlyingValue + ", _isSleeping=" + this.observable._state.isSleeping + ", isActive=" + this.observable.isActive() + ", subscription count=" + this.observable.getSubscriptionsCount("change") + ")");
underlyingValue = underlyingValue + 1;
this.observable.notifySubscribers(this.observable());
};
this.isObservableShown = ko.observable(true);
this.showHideObservable = function () {
this.isObservableShown(!this.isObservableShown());
};
this.logMessages = ko.observableArray();
this.log = function (message) { this.logMessages.push(message); }
this.clearLog = function () { this.logMessages.removeAll(); }
}
ko.options.deferUpdates = true;
ko.onError = function (error) {
alert("knockout error\n" +...