Created
October 27, 2013 09:51
-
-
Save tenntenn/7179799 to your computer and use it in GitHub Desktop.
[JS]KnockoutJS 3.0 Upgrade Noteを読む 第1弾 ref: http://qiita.com/tenntenn/items/954c7b48fe4b1ca8a368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluateImmediate() { | |
//... | |
// ここで値の更新と通知している | |
dependentObservable["notifySubscribers"](_latestValue, "beforeChange"); | |
_latestValue = newValue; | |
dependentObservable["notifySubscribers"](_latestValue); | |
//... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function evaluateImmediate() { | |
//... | |
// 変更なければ、更新も通知もしない | |
if (!dependentObservable['equalityComparer'] || !dependentObservable['equalityComparer'](_latestValue, newValue)) { | |
dependentObservable["notifySubscribers"](_latestValue, "beforeChange"); | |
_latestValue = newValue; | |
dependentObservable["notifySubscribers"](_latestValue); | |
} | |
//... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var n = ko.observable(10); | |
var evenN = ko.computed(function() { | |
var isEven = n() % 2 == 0; | |
alert(isEven); | |
console.log(isEven); | |
return isEven; | |
}); | |
evenN.subscribe(function(newValue) { | |
alert("change evenN to " + newValue); | |
console.log("change evenN to " + newValue); | |
}); | |
n(20); | |
n(21); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var n = ko.observable(10); | |
var evenN = ko.computed(function() { | |
var isEven = n() % 2 == 0; | |
alert(isEven); | |
console.log(isEven); | |
return isEven; | |
}); | |
// 必ず通知がいくようにする | |
evenN.extend({notify: 'always'}); | |
evenN.subscribe(function(newValue) { | |
alert("change evenN to " + newValue); | |
console.log("change evenN to " + newValue); | |
}); | |
n(20); | |
n(21); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment