Remove knockout.deferred.updates plugin

Acting on advice to remove the plugin, which is obsolete as of
Knockout.js v3.4.0. In v3.4.0, Knockout.js includes native support for
the functionality previously provided by this plugin. The plugin's API
now conflicts with the official API.
This commit is contained in:
Matt Brooks
2016-05-03 13:44:49 +01:00
parent 864787b164
commit 1faa6f7a7e
4 changed files with 0 additions and 300 deletions
@@ -1,252 +0,0 @@
/// <reference path="knockout.deferred.updates.d.ts" />
// Turn *off* deferred updates for computed observables and subscriptions
ko.computed.deferUpdates = false;
var myComputed = ko.computed(() => { /* ... */ });
// Turn *on* deferred updates for this computed observable
myComputed.deferUpdates = true;
var myObservable = ko.observable();
var mySubscription = myObservable.subscribe((value) => { /* ... */ });
// Turn *on* deferred updates for this subscription
mySubscription.deferUpdates = true;
// Turn *off* deferred updates for this computed observable
myComputed.extend({ deferred: false });
//
// Examples
//
function nestedComputedNoPlugin() {
var vm: any = {
a: ko.observable(0),
b: ko.observable(0),
c: ko.observable(0),
d: ko.observable(0),
e: ko.observable(0),
f: ko.observable(0)
};
var startTime = new Date().getTime();
var updateArray = [];
function firstUpdate() {
var updateList = document.getElementById('updates');
while (updateList.firstChild) updateList.removeChild(updateList.firstChild);
}
function pushUpdate(name, value, color) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(name + ' ' + value + '; ' + (new Date().getTime() - startTime) + ' ms'));
li.style.color = color;
document.getElementById('updates').appendChild(li);
}
function lastUpdate() {
}
var updateCounter = 0, plusminus = 1;
vm.doUpdate = function () {
var u = updateCounter += plusminus;
startTime = new Date().getTime();
vm.a(u);
vm.b(u);
vm.c(u);
vm.d(u);
vm.e(u);
vm.f(u);
plusminus = !u ? 1 : (u == 9) ? -1 : plusminus;
};
vm.setThrottle = function (value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
vm.C.throttleEvaluation = value;
vm.D.throttleEvaluation = value;
vm.E.throttleEvaluation = value;
vm.F.throttleEvaluation = value;
};
vm.runNormal = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runThrottle = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.doUpdate();
};
vm.A = ko.computed(function () {
var result = '' + vm.a();
firstUpdate();
pushUpdate('A', result, 'green');
return result;
}, null, { deferEvaluation: true });
vm._B = ko.computed(function () {
var result = '' + vm.A() + vm.b();
pushUpdate('B', result, 'darkturquoise');
return result;
}, null, { deferEvaluation: true });
vm.C = ko.computed(function () {
var result = '' + vm._B() + vm.c();
pushUpdate('C', result, 'royalblue');
return result;
}, null, { deferEvaluation: true });
vm.D = ko.computed(function () {
var result = '' + vm.C() + vm.d();
pushUpdate('D', result, 'indigo');
return result;
}, null, { deferEvaluation: true });
vm.E = ko.computed(function () {
var result = '' + vm.D() + vm.e();
pushUpdate('E', result, 'firebrick');
return result;
}, null, { deferEvaluation: true });
vm.F = ko.computed(function () {
var f = vm.f(), result = '' + vm.E() + f;
pushUpdate('F', result, 'orangered');
if (result === '' + f + f + f + f + f + f) lastUpdate();
return result;
}, null, { deferEvaluation: true });
vm.A();
vm._B();
vm.C();
vm.D();
vm.E();
vm.F();
ko.applyBindings(vm);
};
function nestedComputedPlugin() {
var vm: any = {
a: ko.observable(0),
b: ko.observable(0),
c: ko.observable(0),
d: ko.observable(0),
e: ko.observable(0),
f: ko.observable(0)
};
var startTime = new Date().getTime();
var updateArray = [];
function firstUpdate() {
var updateList = document.getElementById('updates');
while (updateList.firstChild)
updateList.removeChild(updateList.firstChild);
}
function pushUpdate(name, value, color) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(name + ' ' + value + '; ' + (new Date().getTime() - startTime) + ' ms'));
li.style.color = color;
document.getElementById('updates').appendChild(li);
}
function lastUpdate() {
}
var updateCounter = 0, plusminus = 1;
vm.doUpdate = function () {
var u = updateCounter += plusminus;
startTime = new Date().getTime();
vm.a(u);
vm.b(u);
vm.c(u);
vm.d(u);
vm.e(u);
vm.f(u);
plusminus = !u ? 1 : (u == 9) ? -1 : plusminus;
};
vm.setThrottle = function (value) {
vm.A.throttleEvaluation = value;
vm._B.throttleEvaluation = value;
vm.C.throttleEvaluation = value;
vm.D.throttleEvaluation = value;
vm.E.throttleEvaluation = value;
vm.F.throttleEvaluation = value;
};
vm.runNormal = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runThrottle = function () {
ko.computed.deferUpdates = false;
vm.setThrottle(1);
vm.doUpdate();
};
vm.runDefer = function () {
ko.computed.deferUpdates = true;
vm.setThrottle(undefined);
vm.doUpdate();
};
vm.runWrappedDefer = ko.tasks.makeProcessedCallback(vm.runDefer);
vm.A = ko.computed(function () {
var result = '' + vm.a();
firstUpdate();
pushUpdate('A', result, 'green');
return result;
}, null, { deferEvaluation: true });
vm._B = ko.computed(function () {
var result = '' + vm.A() + vm.b();
pushUpdate('B', result, 'darkturquoise');
return result;
}, null, { deferEvaluation: true });
vm.C = ko.computed(function () {
var result = '' + vm._B() + vm.c();
pushUpdate('C', result, 'royalblue');
return result;
}, null, { deferEvaluation: true });
vm.D = ko.computed(function () {
var result = '' + vm.C() + vm.d();
pushUpdate('D', result, 'indigo');
return result;
}, null, { deferEvaluation: true });
vm.E = ko.computed(function () {
var result = '' + vm.D() + vm.e();
pushUpdate('E', result, 'firebrick');
return result;
}, null, { deferEvaluation: true });
vm.F = ko.computed(function () {
var f = vm.f(), result = '' + vm.E() + f;
pushUpdate('F', result, 'orangered');
if (result === '' + f + f + f + f + f + f) lastUpdate();
return result;
}, null, { deferEvaluation: true });
vm.A();
vm._B();
vm.C();
vm.D();
vm.E();
vm.F();
ko.applyBindings(vm);
}
@@ -1,46 +0,0 @@
// Type definitions for Knockout Deferred Updates
// Project: https://github.com/mbest/knockout-deferred-updates
// Definitions by: Sebastián Galiano <https://github.com/sgaliano/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../knockout/knockout.d.ts" />
interface KnockoutDeferredTasks {
processImmediate(evaluator: Function, object?: any, args?: any[]): any;
processDelayed(evaluator: Function, distinct?: boolean, options?: any[]): boolean;
makeProcessedCallback(evaluator: Function): void;
}
// Knockout global
interface KnockoutStatic {
tasks: KnockoutDeferredTasks;
processAllDeferredBindingUpdates(): void;
processAllDeferredUpdates(): void;
evaluateAsynchronously(evaluator: Function, timeout?: any): number;
ignoreDependencies(callback: Function, callbackTarget: any, callbackArgs?: any[]);
}
// Observables
interface KnockoutSubscribableFunctions<T> {
deferUpdates: boolean;
}
// Computed
interface KnockoutComputedStatic {
deferUpdates: boolean;
}
interface KnockoutSubscription {
deferUpdates: boolean;
}
// Utils
interface KnockoutUtils {
objectForEach(obj: any, action: Function): void;
objectMap(source: any, mapping: Function): any;
}
// Deferred extender
interface KnockoutExtenders {
deferred(target: any, value: boolean): any;
}