Skip to content

Commit

Permalink
Update to support Knockout 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Sep 2, 2014
1 parent da6c9d2 commit 58ce073
Show file tree
Hide file tree
Showing 23 changed files with 8,457 additions and 520 deletions.
86 changes: 0 additions & 86 deletions examples/knockout-2.1.0.js

This file was deleted.

5,299 changes: 5,299 additions & 0 deletions examples/knockout.js

Large diffs are not rendered by default.

53 changes: 47 additions & 6 deletions examples/nested-computed-noplugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Knockout - Update Test with Nested Observables</title>

<script type="text/javascript" src="knockout-2.1.0.js"></script>

<script type="text/javascript" src="knockout.js"></script>

<script type='text/javascript'>//<![CDATA[

<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var vm = {
a: ko.observable(0),
Expand Down Expand Up @@ -47,6 +47,37 @@
plusminus = !u ? 1 : (u==9) ? -1 : plusminus;
}


ko.subscribable.fn.setLimit = function() {
this.limit(function (callback) {
var timeoutInstance;
return function () {
if (!timeoutInstance) {
timeoutInstance = setTimeout(function() {
timeoutInstance = undefined;
callback();
}, 1);
}
};
});
}

ko.subscribable.fn.clearLimit = function() {
if (this._origNotifySubscribers) {
this.notifySubscribers = this._origNotifySubscribers;
this._evalRateLimited = null;
}
}

vm.setRateLimit = function(value) {
vm.A[value]();
vm._B[value]();
vm.C[value]();
vm.D[value]();
vm.E[value]();
vm.F[value]();
}

vm.setThrottle = function(value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
Expand All @@ -59,18 +90,27 @@
vm.runNormal = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.setRateLimit('clearLimit');
vm.doUpdate();
}

vm.runRateLimit = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.setRateLimit('setLimit');
vm.doUpdate();
}

vm.runThrottle = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.setRateLimit('clearLimit');
vm.doUpdate();
}

vm.A = ko.computed(function() {
var result = '' + vm.a();
firstUpdate();
var result = '' + vm.a();
pushUpdate('A', result, 'green');
return result;
}, null, {deferEvaluation:true});
Expand Down Expand Up @@ -116,7 +156,7 @@

ko.applyBindings(vm);

}//]]>
}//]]>

</script>

Expand All @@ -125,11 +165,12 @@
<body>
Update:
<input type="button" value="Normal" data-bind="click: runNormal"/>
<input type="button" value="With rateLimit (setTimeout)" data-bind="click: runRateLimit"/>
<input type="button" value="With Throttle (setTimeout)" data-bind="click: runThrottle"/>
<ol id="updates">
</ol>


</body>


Expand Down
46 changes: 44 additions & 2 deletions examples/nested-computed-plugin.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Knockout with Deferred Updates Plugin - Update Test with Nested Observables</title>

<script type="text/javascript" src="knockout-2.1.0.js"></script>
<script type="text/javascript" src="knockout.js"></script>
<script type='text/javascript' src="setImmediate.js"></script>
<script type='text/javascript' src="../knockout-deferred-updates.js"></script>

Expand Down Expand Up @@ -49,6 +49,37 @@
plusminus = !u ? 1 : (u==9) ? -1 : plusminus;
}


ko.subscribable.fn.setLimit = function() {
this.limit(function (callback) {
var timeoutInstance;
return function () {
if (!timeoutInstance) {
timeoutInstance = setTimeout(function() {
timeoutInstance = undefined;
callback();
}, 1);
}
};
});
}

ko.subscribable.fn.clearLimit = function() {
if (this._origNotifySubscribers) {
this.notifySubscribers = this._origNotifySubscribers;
this._evalRateLimited = null;
}
}

vm.setRateLimit = function(value) {
vm.A[value]();
vm._B[value]();
vm.C[value]();
vm.D[value]();
vm.E[value]();
vm.F[value]();
}

vm.setThrottle = function(value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
Expand All @@ -61,26 +92,36 @@
vm.runNormal = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.setRateLimit('clearLimit');
vm.doUpdate();
}

vm.runRateLimit = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.setRateLimit('setLimit');
vm.doUpdate();
}

vm.runThrottle = function() {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.setRateLimit('clearLimit');
vm.doUpdate();
}

vm.runDefer = function() {
ko.computed.deferUpdates = true;
vm.setThrottle(undefined);
vm.setRateLimit('clearLimit');
vm.doUpdate();
}

vm.runWrappedDefer = ko.tasks.makeProcessedCallback(vm.runDefer);

vm.A = ko.computed(function() {
var result = '' + vm.a();
firstUpdate();
var result = '' + vm.a();
pushUpdate('A', result, 'green');
return result;
}, null, {deferEvaluation:true});
Expand Down Expand Up @@ -135,6 +176,7 @@
<body>
Update:
<input type="button" value="Normal" data-bind="click: runNormal"/>
<input type="button" value="With rateLimit (setTimeout)" data-bind="click: runRateLimit"/>
<input type="button" value="With Throttle (setTimeout)" data-bind="click: runThrottle"/>
<input type="button" value="With Defer (setImmediate)" data-bind="click: runDefer"/>
<input type="button" value="With Defer (Wrapped)" data-bind="click: runWrappedDefer"/>
Expand Down
Loading

0 comments on commit 58ce073

Please sign in to comment.