From a0ae5664ab5c1b2238e3611e19d2cf428149bc50 Mon Sep 17 00:00:00 2001 From: tofulm Date: Wed, 6 Apr 2022 23:49:37 +0200 Subject: [PATCH] maj de vuejs --- js/vue.js | 172 ++++++++++++++++++++++++++------------------------ js/vue.min.js | 2 +- 2 files changed, 91 insertions(+), 83 deletions(-) diff --git a/js/vue.js b/js/vue.js index d8f2eb7..e45eed3 100644 --- a/js/vue.js +++ b/js/vue.js @@ -280,13 +280,15 @@ var Vue = (function (exports) { * @private */ const toDisplayString = (val) => { - return val == null - ? '' - : isArray(val) || - (isObject(val) && - (val.toString === objectToString || !isFunction(val.toString))) - ? JSON.stringify(val, replacer, 2) - : String(val); + return isString(val) + ? val + : val == null + ? '' + : isArray(val) || + (isObject(val) && + (val.toString === objectToString || !isFunction(val.toString))) + ? JSON.stringify(val, replacer, 2) + : String(val); }; const replacer = (_key, val) => { // can't use isRef here since @vue/shared has no deps @@ -360,6 +362,7 @@ var Vue = (function (exports) { 'onVnodeBeforeMount,onVnodeMounted,' + 'onVnodeBeforeUpdate,onVnodeUpdated,' + 'onVnodeBeforeUnmount,onVnodeUnmounted'); + const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo'); const cacheStringFunction = (fn) => { const cache = Object.create(null); return ((str) => { @@ -425,7 +428,6 @@ var Vue = (function (exports) { } let activeEffectScope; - const effectScopeStack = []; class EffectScope { constructor(detached = false) { this.active = true; @@ -440,11 +442,11 @@ var Vue = (function (exports) { run(fn) { if (this.active) { try { - this.on(); + activeEffectScope = this; return fn(); } finally { - this.off(); + activeEffectScope = this.parent; } } else { @@ -452,23 +454,24 @@ var Vue = (function (exports) { } } on() { - if (this.active) { - effectScopeStack.push(this); - activeEffectScope = this; - } + activeEffectScope = this; } off() { - if (this.active) { - effectScopeStack.pop(); - activeEffectScope = effectScopeStack[effectScopeStack.length - 1]; - } + activeEffectScope = this.parent; } stop(fromParent) { if (this.active) { - this.effects.forEach(e => e.stop()); - this.cleanups.forEach(cleanup => cleanup()); + let i, l; + for (i = 0, l = this.effects.length; i < l; i++) { + this.effects[i].stop(); + } + for (i = 0, l = this.cleanups.length; i < l; i++) { + this.cleanups[i](); + } if (this.scopes) { - this.scopes.forEach(e => e.stop(true)); + for (i = 0, l = this.scopes.length; i < l; i++) { + this.scopes[i].stop(true); + } } // nested scope, dereference from parent to avoid memory leaks if (this.parent && !fromParent) { @@ -486,8 +489,7 @@ var Vue = (function (exports) { function effectScope(detached) { return new EffectScope(detached); } - function recordEffectScope(effect, scope) { - scope = scope || activeEffectScope; + function recordEffectScope(effect, scope = activeEffectScope) { if (scope && scope.active) { scope.effects.push(effect); } @@ -550,7 +552,6 @@ var Vue = (function (exports) { * When recursion depth is greater, fall back to using a full cleanup. */ const maxMarkerBits = 30; - const effectStack = []; let activeEffect; const ITERATE_KEY = Symbol('iterate' ); const MAP_KEY_ITERATE_KEY = Symbol('Map key iterate' ); @@ -560,35 +561,42 @@ var Vue = (function (exports) { this.scheduler = scheduler; this.active = true; this.deps = []; + this.parent = undefined; recordEffectScope(this, scope); } run() { if (!this.active) { return this.fn(); } - if (!effectStack.length || !effectStack.includes(this)) { - try { - effectStack.push((activeEffect = this)); - enableTracking(); - trackOpBit = 1 << ++effectTrackDepth; - if (effectTrackDepth <= maxMarkerBits) { - initDepMarkers(this); - } - else { - cleanupEffect(this); - } - return this.fn(); + let parent = activeEffect; + let lastShouldTrack = shouldTrack; + while (parent) { + if (parent === this) { + return; } - finally { - if (effectTrackDepth <= maxMarkerBits) { - finalizeDepMarkers(this); - } - trackOpBit = 1 << --effectTrackDepth; - resetTracking(); - effectStack.pop(); - const n = effectStack.length; - activeEffect = n > 0 ? effectStack[n - 1] : undefined; + parent = parent.parent; + } + try { + this.parent = activeEffect; + activeEffect = this; + shouldTrack = true; + trackOpBit = 1 << ++effectTrackDepth; + if (effectTrackDepth <= maxMarkerBits) { + initDepMarkers(this); } + else { + cleanupEffect(this); + } + return this.fn(); + } + finally { + if (effectTrackDepth <= maxMarkerBits) { + finalizeDepMarkers(this); + } + trackOpBit = 1 << --effectTrackDepth; + activeEffect = this.parent; + shouldTrack = lastShouldTrack; + this.parent = undefined; } } stop() { @@ -636,32 +644,24 @@ var Vue = (function (exports) { trackStack.push(shouldTrack); shouldTrack = false; } - function enableTracking() { - trackStack.push(shouldTrack); - shouldTrack = true; - } function resetTracking() { const last = trackStack.pop(); shouldTrack = last === undefined ? true : last; } function track(target, type, key) { - if (!isTracking()) { - return; + if (shouldTrack && activeEffect) { + let depsMap = targetMap.get(target); + if (!depsMap) { + targetMap.set(target, (depsMap = new Map())); + } + let dep = depsMap.get(key); + if (!dep) { + depsMap.set(key, (dep = createDep())); + } + const eventInfo = { effect: activeEffect, target, type, key } + ; + trackEffects(dep, eventInfo); } - let depsMap = targetMap.get(target); - if (!depsMap) { - targetMap.set(target, (depsMap = new Map())); - } - let dep = depsMap.get(key); - if (!dep) { - depsMap.set(key, (dep = createDep())); - } - const eventInfo = { effect: activeEffect, target, type, key } - ; - trackEffects(dep, eventInfo); - } - function isTracking() { - return shouldTrack && activeEffect !== undefined; } function trackEffects(dep, debuggerEventExtraInfo) { let shouldTrack = false; @@ -1346,13 +1346,10 @@ var Vue = (function (exports) { const toReadonly = (value) => isObject(value) ? readonly(value) : value; function trackRefValue(ref) { - if (isTracking()) { + if (shouldTrack && activeEffect) { ref = toRaw(ref); - if (!ref.dep) { - ref.dep = createDep(); - } { - trackEffects(ref.dep, { + trackEffects(ref.dep || (ref.dep = createDep()), { target: ref, type: "get" /* GET */, key: 'value' @@ -1374,7 +1371,7 @@ var Vue = (function (exports) { } } function isRef(r) { - return Boolean(r && r.__v_isRef === true); + return !!(r && r.__v_isRef === true); } function ref(value) { return createRef(value, false); @@ -5186,7 +5183,6 @@ var Vue = (function (exports) { [bar, this.y] ]) */ - const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo'); function validateDirectiveName(name) { if (isBuiltInDirective(name)) { warn$1('Do not use built-in directive ids as custom directive id: ' + name); @@ -5667,7 +5663,8 @@ var Vue = (function (exports) { // e.g.