More Knockout code to ES6

This commit is contained in:
djmaze 2021-07-29 11:43:47 +02:00
parent b7cb990b00
commit cbecdd93a0
22 changed files with 733 additions and 865 deletions

View file

@ -37,4 +37,4 @@ ko.bindingHandlers['hasfocus'] = {
}
}
};
ko.expressionRewriting.twoWayBindings['hasfocus'] = true;
ko.expressionRewriting.twoWayBindings.add('hasfocus');

View file

@ -62,7 +62,7 @@ ko.bindingHandlers['textInput'] = {
ko.computed(updateView, { disposeWhenNodeIsRemoved: element });
}
};
ko.expressionRewriting.twoWayBindings['textInput'] = true;
ko.expressionRewriting.twoWayBindings.add('textInput');
// textinput is an alias for textInput
ko.bindingHandlers['textinput'] = {

View file

@ -9,20 +9,18 @@ ko.bindingHandlers['value'] = {
return;
}
var eventsToCatch = [];
var eventsToCatch = new Set;
var requestedEventsToCatch = allBindings.get("valueUpdate");
var elementValueBeforeEvent = null;
if (requestedEventsToCatch) {
// Allow both individual event names, and arrays of event names
if (typeof requestedEventsToCatch == "string") {
eventsToCatch = [requestedEventsToCatch];
eventsToCatch.add(requestedEventsToCatch);
} else {
eventsToCatch = requestedEventsToCatch ? requestedEventsToCatch.filter((item, index) =>
requestedEventsToCatch.indexOf(item) === index
) : [];
requestedEventsToCatch.forEach(item => eventsToCatch.add(item));
}
ko.utils.arrayRemoveItem(eventsToCatch, "change"); // We'll subscribe to "change" events later
eventsToCatch.delete("change"); // We'll subscribe to "change" events later
}
var valueUpdateHandler = () => {
@ -113,4 +111,4 @@ ko.bindingHandlers['value'] = {
},
'update': () => {} // Keep for backwards compatibility with code that may have wrapped value binding
};
ko.expressionRewriting.twoWayBindings['value'] = true;
ko.expressionRewriting.twoWayBindings.add('value');