Remove unused data from KnockoutJS

This commit is contained in:
djmaze 2021-09-28 14:03:07 +02:00
parent 5cb4d338a1
commit bf756c9279
6 changed files with 6 additions and 39 deletions

View file

@ -235,24 +235,6 @@
}
};
// Given a function that returns bindings, create and return a new object that contains
// binding value-accessors functions. Each accessor function calls the original function
// so that it always gets the latest value and all dependencies are captured. This is used
// by ko.applyBindingsToNode and getBindingsAndMakeAccessors.
function makeAccessorsFromFunction(callback) {
return ko.utils.objectMap(ko.dependencyDetection.ignore(callback), (value, key) =>
() => callback()[key]
);
}
// Given a bindings function or object, create and return a new object that contains
// binding value-accessors functions. This is used by ko.applyBindingsToNode.
function makeBindingAccessors(bindings, context, node) {
return (typeof bindings === 'function')
? makeAccessorsFromFunction(bindings.bind(null, context, node))
: ko.utils.objectMap(bindings, value => () => value);
}
function validateThatBindingIsAllowedForVirtualElements(bindingName) {
var validator = ko.virtualElements.allowedBindings[bindingName];
if (!validator)

View file

@ -1,6 +1,5 @@
var attrHtmlToJavaScriptMap = { 'class': 'className', 'for': 'htmlFor' };
ko.bindingHandlers['attr'] = {
'update': (element, valueAccessor, allBindings) => {
'update': (element, valueAccessor) => {
var value = ko.utils.unwrapObservable(valueAccessor()) || {};
ko.utils.objectForEach(value, function(attrName, attrValue) {
attrValue = ko.utils.unwrapObservable(attrValue);

View file

@ -4,10 +4,10 @@
function makeWithIfBinding(bindingKey, isWith, isNot) {
ko.bindingHandlers[bindingKey] = {
'init': (element, valueAccessor, allBindings, viewModel, bindingContext) => {
var didDisplayOnLastUpdate, savedNodes, contextOptions = {}, needAsyncContext;
var savedNodes, contextOptions = {}, needAsyncContext;
if (isWith) {
var as = allBindings.get('as'), noChildContext = false;
var as = allBindings.get('as');
contextOptions = { 'as': as, 'exportDependencies': true };
}
@ -52,8 +52,6 @@ function makeWithIfBinding(bindingKey, isWith, isNot) {
ko.bindingEvent.notify(element, ko.bindingEvent.childrenComplete);
}
didDisplayOnLastUpdate = shouldDisplay;
}, { disposeWhenNodeIsRemoved: element });
return { 'controlsDescendantBindings': true };

View file

@ -17,17 +17,6 @@ ko.bindingHandlers['textInput'] = {
}
};
var deferUpdateModel = event => {
if (!timeoutHandle) {
// The elementValueBeforeEvent variable is set *only* during the brief gap between an
// event firing and the updateModel function running. This allows us to ignore model
// updates that are from the previous state of the element, usually due to techniques
// such as rateLimit. Such updates, if not ignored, can cause keystrokes to be lost.
elementValueBeforeEvent = element.value;
timeoutHandle = setTimeout(updateModel, 4);
}
};
var updateView = () => {
var modelValue = ko.utils.unwrapObservable(valueAccessor());