mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 05:29:20 +03:00
Use JavaScript Optional chaining in vendors/*
This commit is contained in:
parent
e5e4675c1b
commit
ef8b1f40e4
28 changed files with 619 additions and 750 deletions
|
|
@ -34,11 +34,11 @@ ko.dependencyDetection = {
|
|||
}
|
||||
},
|
||||
|
||||
getDependenciesCount: () => currentFrame && currentFrame.computed.getDependenciesCount(),
|
||||
getDependenciesCount: () => currentFrame?.computed.getDependenciesCount(),
|
||||
|
||||
isInitial: () => currentFrame && currentFrame.isInitial,
|
||||
isInitial: () => currentFrame?.isInitial,
|
||||
|
||||
computed: () => currentFrame && currentFrame.computed
|
||||
computed: () => currentFrame?.computed
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -41,14 +41,13 @@ ko.computed = (evaluatorFunctionOrOptions, options) => {
|
|||
// Writing a value
|
||||
writeFunction(...arguments);
|
||||
return this; // Permits chained assignments
|
||||
} else {
|
||||
// Reading the value
|
||||
state.isDisposed || ko.dependencyDetection.registerDependency(computedObservable);
|
||||
if (state.isDirty || (state.isSleeping && computedObservable.haveDependenciesChanged())) {
|
||||
computedObservable.evaluateImmediate();
|
||||
}
|
||||
return state.latestValue;
|
||||
}
|
||||
// Reading the value
|
||||
state.isDisposed || ko.dependencyDetection.registerDependency(computedObservable);
|
||||
if (state.isDirty || (state.isSleeping && computedObservable.haveDependenciesChanged())) {
|
||||
computedObservable.evaluateImmediate();
|
||||
}
|
||||
return state.latestValue;
|
||||
}
|
||||
|
||||
computedObservable[computedState] = state;
|
||||
|
|
@ -101,9 +100,7 @@ ko.computed = (evaluatorFunctionOrOptions, options) => {
|
|||
|
||||
// Utility function that disposes a given dependencyTracking entry
|
||||
function computedDisposeDependencyCallback(id, entryToDispose) {
|
||||
if (entryToDispose !== null && entryToDispose.dispose) {
|
||||
entryToDispose.dispose();
|
||||
}
|
||||
entryToDispose?.dispose?.();
|
||||
}
|
||||
|
||||
// This function gets called each time a dependency is detected while evaluating a computed.
|
||||
|
|
@ -192,8 +189,8 @@ var computedFn = {
|
|||
},
|
||||
markDirty: function () {
|
||||
// Process "dirty" events if we can handle delayed notifications
|
||||
if (this._evalDelayed && !this[computedState].isBeingEvaluated) {
|
||||
this._evalDelayed(false /*isChange*/);
|
||||
if (!this[computedState].isBeingEvaluated) {
|
||||
this._evalDelayed?.(false /*isChange*/);
|
||||
}
|
||||
},
|
||||
isActive: function () {
|
||||
|
|
@ -214,7 +211,7 @@ var computedFn = {
|
|||
evaluatePossiblyAsync: function () {
|
||||
var computedObservable = this,
|
||||
throttleEvaluationTimeout = computedObservable['throttleEvaluation'];
|
||||
if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
|
||||
if (throttleEvaluationTimeout >= 0) {
|
||||
clearTimeout(this[computedState].evaluationTimeoutInstance);
|
||||
this[computedState].evaluationTimeoutInstance = setTimeout(() =>
|
||||
computedObservable.evaluateImmediate(true /*notifyChange*/)
|
||||
|
|
@ -244,7 +241,7 @@ var computedFn = {
|
|||
return;
|
||||
}
|
||||
|
||||
if (state.disposeWhenNodeIsRemoved && !ko.utils.domNodeIsAttachedToDocument(state.disposeWhenNodeIsRemoved) || disposeWhen && disposeWhen()) {
|
||||
if (state.disposeWhenNodeIsRemoved && !ko.utils.domNodeIsAttachedToDocument(state.disposeWhenNodeIsRemoved) || disposeWhen?.()) {
|
||||
// See comment above about suppressDisposalUntilDisposeWhenReturnsFalse
|
||||
if (!state.suppressDisposalUntilDisposeWhenReturnsFalse) {
|
||||
computedObservable.dispose();
|
||||
|
|
@ -366,7 +363,7 @@ var computedFn = {
|
|||
var state = this[computedState];
|
||||
if (!state.isSleeping && state.dependencyTracking) {
|
||||
ko.utils.objectForEach(state.dependencyTracking, (id, dependency) =>
|
||||
dependency.dispose && dependency.dispose()
|
||||
dependency.dispose?.()
|
||||
);
|
||||
}
|
||||
if (state.disposeWhenNodeIsRemoved && state.domNodeDisposalCallback) {
|
||||
|
|
|
|||
10
vendors/knockout/src/subscribables/observable.js
vendored
10
vendors/knockout/src/subscribables/observable.js
vendored
|
|
@ -14,11 +14,9 @@ ko.observable = initialValue => {
|
|||
}
|
||||
return this; // Permits chained assignments
|
||||
}
|
||||
else {
|
||||
// Read
|
||||
ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
|
||||
return observable[observableLatestValue];
|
||||
}
|
||||
// Read
|
||||
ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
|
||||
return observable[observableLatestValue];
|
||||
}
|
||||
|
||||
observable[observableLatestValue] = initialValue;
|
||||
|
|
@ -40,7 +38,7 @@ ko.observable = initialValue => {
|
|||
var observableFn = {
|
||||
'toJSON': function() {
|
||||
let value = this[observableLatestValue];
|
||||
return value && value.toJSON ? value.toJSON() : value;
|
||||
return value?.toJSON?.() || value;
|
||||
},
|
||||
equalityComparer: valuesArePrimitiveAndEqual,
|
||||
peek: function() { return this[observableLatestValue]; },
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const arrayChangeEventName = 'arrayChange';
|
|||
ko.extenders['trackArrayChanges'] = (target, options) => {
|
||||
// Use the provided options--each call to trackArrayChanges overwrites the previously set options
|
||||
target.compareArrayOptions = {};
|
||||
if (options && typeof options == "object") {
|
||||
if (typeof options == "object") {
|
||||
ko.utils.extend(target.compareArrayOptions, options);
|
||||
}
|
||||
target.compareArrayOptions['sparse'] = true;
|
||||
|
|
@ -81,7 +81,7 @@ ko.extenders['trackArrayChanges'] = (target, options) => {
|
|||
cachedDiff = null;
|
||||
pendingChanges = 0;
|
||||
|
||||
if (changes && changes.length) {
|
||||
if (changes?.length) {
|
||||
target.notifySubscribers(changes, arrayChangeEventName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,4 +197,4 @@ ko.subscribable['fn'] = ko_subscribable_fn;
|
|||
|
||||
|
||||
ko.isSubscribable = instance =>
|
||||
instance != null && typeof instance.subscribe == "function" && typeof instance.notifySubscribers == "function";
|
||||
typeof instance?.subscribe == "function" && typeof instance.notifySubscribers == "function";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue