mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
replaced ko.utils.array* with native
This commit is contained in:
parent
20b1e08c9b
commit
d49916731f
14 changed files with 137 additions and 230 deletions
|
|
@ -343,13 +343,12 @@
|
|||
// First add dependencies (if any) of the current binding
|
||||
if (binding['after']) {
|
||||
cyclicDependencyStack.push(bindingKey);
|
||||
ko.utils.arrayForEach(binding['after'], bindingDependencyKey => {
|
||||
binding['after'].forEach(bindingDependencyKey => {
|
||||
if (bindings[bindingDependencyKey]) {
|
||||
if (ko.utils.arrayIndexOf(cyclicDependencyStack, bindingDependencyKey) !== -1) {
|
||||
if (cyclicDependencyStack.includes(bindingDependencyKey)) {
|
||||
throw Error("Cannot combine the following bindings, because they have a cyclic dependency: " + cyclicDependencyStack.join(", "));
|
||||
} else {
|
||||
pushBinding(bindingDependencyKey);
|
||||
}
|
||||
pushBinding(bindingDependencyKey);
|
||||
}
|
||||
});
|
||||
cyclicDependencyStack.length--;
|
||||
|
|
@ -454,10 +453,8 @@
|
|||
}
|
||||
|
||||
// First put the bindings into the right order
|
||||
var orderedBindings = topologicalSortBindings(bindings);
|
||||
|
||||
// Go through the sorted bindings, calling init and update for each
|
||||
ko.utils.arrayForEach(orderedBindings, bindingKeyAndHandler => {
|
||||
topologicalSortBindings(bindings).forEach(bindingKeyAndHandler => {
|
||||
// Note that topologicalSortBindings has already filtered out any nonexistent binding handlers,
|
||||
// so bindingKeyAndHandler.handler will always be nonnull.
|
||||
var handlerInitFn = bindingKeyAndHandler.handler["init"],
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ ko.bindingHandlers['options'] = {
|
|||
} else if (previousSelectedValues.length) {
|
||||
// IE6 doesn't like us to assign selection to OPTION nodes before they're added to the document.
|
||||
// That's why we first added them without selection. Now it's time to set the selection.
|
||||
var isSelected = ko.utils.arrayIndexOf(previousSelectedValues, ko.selectExtensions.readValue(newOptions[0])) >= 0;
|
||||
var isSelected = previousSelectedValues.includes(ko.selectExtensions.readValue(newOptions[0]));
|
||||
newOptions[0].selected = isSelected;
|
||||
|
||||
// If this option was changed from being selected during a single-item update, notify the change
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ ko.bindingHandlers['textInput'] = {
|
|||
|
||||
if (DEBUG && ko.bindingHandlers['textInput']['_forceUpdateOn']) {
|
||||
// Provide a way for tests to specify exactly which events are bound
|
||||
ko.utils.arrayForEach(ko.bindingHandlers['textInput']['_forceUpdateOn'], eventName => {
|
||||
ko.bindingHandlers['textInput']['_forceUpdateOn'].forEach(eventName => {
|
||||
if (eventName.slice(0,5) == 'after') {
|
||||
onEvent(eventName.slice(5), deferUpdateModel);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ ko.bindingHandlers['value'] = {
|
|||
ko.expressionRewriting.writeValueToProperty(modelValue, allBindings, 'value', elementValue);
|
||||
}
|
||||
|
||||
ko.utils.arrayForEach(eventsToCatch, eventName => {
|
||||
eventsToCatch.forEach(eventName => {
|
||||
// The syntax "after<eventname>" means "run the handler asynchronously after the event"
|
||||
// This is useful, for example, to catch "keydown" events after the browser has updated the control
|
||||
// (otherwise, ko.selectExtensions.readValue(this) will receive the control's value *before* the key event)
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
// Replace the contents of the mappedNodes array, thereby updating the record
|
||||
// of which nodes would be deleted if valueToMap was itself later removed
|
||||
mappedNodes.length = 0;
|
||||
ko.utils.arrayPushAll(mappedNodes, newMappedNodes);
|
||||
}, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: ()=>!!ko.utils.arrayFirst(mappedNodes, ko.utils.domNodeIsAttachedToDocument) });
|
||||
mappedNodes.push(...newMappedNodes);
|
||||
}, null, { disposeWhenNodeIsRemoved: containerNode, disposeWhen: ()=>!!mappedNodes.find(ko.utils.domNodeIsAttachedToDocument) });
|
||||
return { mappedNodes : mappedNodes, dependentObservable : (dependentObservable.isActive() ? dependentObservable : undefined) };
|
||||
}
|
||||
|
||||
|
|
@ -86,15 +86,13 @@
|
|||
function callCallback(callback, items) {
|
||||
if (callback) {
|
||||
for (var i = 0, n = items.length; i < n; i++) {
|
||||
ko.utils.arrayForEach(items[i].mappedNodes, function(node) {
|
||||
callback(node, i, items[i].arrayEntry);
|
||||
});
|
||||
items[i].mappedNodes.forEach(node => callback(node, i, items[i].arrayEntry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirstExecution) {
|
||||
ko.utils.arrayForEach(array, itemAdded);
|
||||
array.forEach(itemAdded);
|
||||
} else {
|
||||
if (!editScript || (lastMappingResult && lastMappingResult['_countWaitingForRemove'])) {
|
||||
// Compare the provided array against the previous one
|
||||
|
|
@ -172,7 +170,7 @@
|
|||
callCallback(options['beforeMove'], itemsForMoveCallbacks);
|
||||
|
||||
// Next remove nodes for deleted items (or just clean if there's a beforeRemove callback)
|
||||
ko.utils.arrayForEach(nodesToDelete, options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
|
||||
nodesToDelete.forEach(options['beforeRemove'] ? ko.cleanNode : ko.removeNode);
|
||||
|
||||
var i, j, lastNode, nodeToInsert, mappedNodes, activeElement;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ ko.expressionRewriting = (() => {
|
|||
var javaScriptAssignmentTarget = /^(?:[$_a-z][$\w]*|(.+)(\.\s*[$_a-z][$\w]*|\[.+\]))$/i;
|
||||
|
||||
function getWriteableValue(expression) {
|
||||
if (ko.utils.arrayIndexOf(javaScriptReservedWords, expression) >= 0)
|
||||
if (javaScriptReservedWords.includes(expression))
|
||||
return false;
|
||||
var match = expression.match(javaScriptAssignmentTarget);
|
||||
return match === null ? false : match[1] ? ('Object(' + match[1] + ')' + match[2]) : expression;
|
||||
|
|
@ -143,7 +143,7 @@ ko.expressionRewriting = (() => {
|
|||
keyValueArray = typeof bindingsStringOrKeyValueArray === "string" ?
|
||||
parseObjectLiteral(bindingsStringOrKeyValueArray) : bindingsStringOrKeyValueArray;
|
||||
|
||||
ko.utils.arrayForEach(keyValueArray, keyValue =>
|
||||
keyValueArray.forEach(keyValue =>
|
||||
processKeyValue(keyValue.key || keyValue['unknown'], keyValue.value)
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue