From f3459b564e382a7e2d3fe4506eeaf6cd1fe7fa51 Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 10 Dec 2021 22:54:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fix/fix.js | 197 +- dist/fix/fix.proxy.js | 3911 +++++++++++++++++++--------------- src/less/lib/background.less | 4 - 3 files changed, 2266 insertions(+), 1846 deletions(-) diff --git a/dist/fix/fix.js b/dist/fix/fix.js index 54ae610ef..e16bdf99f 100644 --- a/dist/fix/fix.js +++ b/dist/fix/fix.js @@ -90,12 +90,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } } - var bailRE = /[^\w.$]/; + // const bailRE = /[^\w.$]/ function parsePath(path) { - if (bailRE.test(path)) { - return; - } + // 正常表达式比较慢,能不要的就不要了 + // if (bailRE.test(path)) { + // return + // } var segments = path.split('.'); return function (obj) { for (var i = 0; i < segments.length; i++) { @@ -975,7 +976,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons options = options || {}; options.user = true; var exps = void 0; - if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { + if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && expOrFn.indexOf("*") < 0) { var watcher = new Watcher(model, expOrFn, cb, options); if (options.immediate) { cb(watcher.value); @@ -1016,45 +1017,96 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons if (_.has(operators, exp)) { return; } - //a.**或a.*形式 - if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**") { - var isGlobal = /\*\*$/.test(exp); - if (isGlobal) { - //a.**的形式 - exp = exp.replace(".**", ""); - } else { - //a.*的形式 - exp = exp.replace(".*", ""); + if (exp.indexOf("*") >= 0) { + //a.**或a.*形式 + if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**" || exp === "*") { + var isGlobal = exp.indexOf("**") >= 0; + if (isGlobal) { + //a.**的形式 + exp = exp.replace(".**", ""); + } else { + //a.*的形式 + exp = exp.replace(".*", ""); + } + var getter = exp === "**" || exp === "*" ? function (m) { + return m; + } : parsePath(exp); + var v = getter.call(model, model); + var _dep = new Dep(); + if (isGlobal) { + (v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(_dep); + } else { + (v.__ob__._deps || (v.__ob__._deps = [])).push(_dep); + } + var _w = new Watcher(model, function () { + _dep.depend(); + return NaN; + }, function (newValue, oldValue, attrs) { + callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); + }, options); + watchers.push(function unwatchFn() { + _w.teardown(); + v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, _dep); + v.__ob__._deps && remove(v.__ob__._deps, _dep); + }); + return; } - var getter = exp === "**" ? function (m) { - return m; - } : parsePath(exp); - var v = getter.call(model, model); - var dep = new Dep(); - if (isGlobal) { - (v.__ob__._scopeDeps || (v.__ob__._scopeDeps = [])).push(dep); - } else { - (v.__ob__._deps || (v.__ob__._deps = [])).push(dep); + // **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了 + if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { + //先获取到能获取到的对象 + var _paths = exp.split("."); + var _currentModel = model[_paths[1]]; + exp = _paths[1] + ".**"; + //补全路径 + var _parent = _currentModel.__ob__.parent, + _root = _currentModel.__ob__; + while (_parent) { + exp = '*.' + exp; + _root = _parent; + _parent = _parent.parent; + } + var _regStr = routeToRegExp(exp); + var _dep2 = new Dep(); + _root._globalDeps || (_root._globalDeps = {}); + if (_.isArray(_root._globalDeps[_regStr])) { + _root._globalDeps[_regStr].push(_dep2); + } else { + _root._globalDeps[_regStr] = [_dep2]; + } + + var _w2 = new Watcher(_currentModel, function () { + _dep2.depend(); + return NaN; + }, function (newValue, oldValue, attrs) { + callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); + }, options); + watchers.push(function unwatchFn() { + if (_root._globalDeps) { + remove(_root._globalDeps[_regStr], _dep2); + + if (_root._globalDeps[_regStr].length === 0) { + delete _root._globalDeps[_regStr]; + _w2.teardown(); + } + } + }); + return; } - var w = new Watcher(model, function () { - dep.depend(); - return NaN; - }, function (newValue, oldValue, attrs) { - callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); - }, options); - watchers.push(function unwatchFn() { - w.teardown(); - v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, dep); - v.__ob__._deps && remove(v.__ob__._deps, dep); - }); - return; - } - // **.a.**的情况,场景:a.b.c, 如果用b.**监听, a被重新赋值b上的_scopeDes就不存在了 - if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { + // 再有结尾有*的就不支持了 + if (exp[exp.length - 1] === "*") { + throw new Error('not support'); + } + //其他含有*的情况,如*.a,*.*.a,a.*.a + var currentModel = model; //先获取到能获取到的对象 var paths = exp.split("."); - var currentModel = model[paths[1]]; - exp = paths[1] + ".**"; + for (var _i = 0, len = paths.length; _i < len; _i++) { + if (paths[_i] === "*") { + break; + } + currentModel = model[paths[_i]]; + } + exp = exp.substr(exp.indexOf("*")); //补全路径 var parent = currentModel.__ob__.parent, root = currentModel.__ob__; @@ -1064,77 +1116,26 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons parent = parent.parent; } var regStr = routeToRegExp(exp); - var _dep = new Dep(); + var dep = new Dep(); root._globalDeps || (root._globalDeps = {}); if (_.isArray(root._globalDeps[regStr])) { - root._globalDeps[regStr].push(_dep); + root._globalDeps[regStr].push(dep); } else { - root._globalDeps[regStr] = [_dep]; + root._globalDeps[regStr] = [dep]; } - var _w = new Watcher(currentModel, function () { - _dep.depend(); + var w = new Watcher(currentModel, function () { + dep.depend(); return NaN; }, function (newValue, oldValue, attrs) { callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); }, options); watchers.push(function unwatchFn() { if (root._globalDeps) { - remove(root._globalDeps[regStr], _dep); - + remove(root._globalDeps[regStr], dep); if (root._globalDeps[regStr].length === 0) { delete root._globalDeps[regStr]; - _w.teardown(); - } - } - }); - return; - } - if (/\*\*$|\*$/.test(exp)) { - throw new Error('not support'); - } - //其他含有*的情况,如*.a,*.*.a,a.*.a - if (/\*/.test(exp)) { - var _currentModel = model; - //先获取到能获取到的对象 - var _paths = exp.split("."); - for (var _i = 0, len = _paths.length; _i < len; _i++) { - if (_paths[_i] === "*") { - break; - } - _currentModel = model[_paths[_i]]; - } - exp = exp.substr(exp.indexOf("*")); - //补全路径 - var _parent = _currentModel.__ob__.parent, - _root = _currentModel.__ob__; - while (_parent) { - exp = '*.' + exp; - _root = _parent; - _parent = _parent.parent; - } - var _regStr = routeToRegExp(exp); - var _dep2 = new Dep(); - _root._globalDeps || (_root._globalDeps = {}); - if (_.isArray(_root._globalDeps[_regStr])) { - _root._globalDeps[_regStr].push(_dep2); - } else { - _root._globalDeps[_regStr] = [_dep2]; - } - - var _w2 = new Watcher(_currentModel, function () { - _dep2.depend(); - return NaN; - }, function (newValue, oldValue, attrs) { - callback(i, newValue, oldValue, _.extend({ index: i }, attrs)); - }, options); - watchers.push(function unwatchFn() { - if (_root._globalDeps) { - remove(_root._globalDeps[_regStr], _dep2); - - if (_root._globalDeps[_regStr].length === 0) { - delete _root._globalDeps[_regStr]; - _w2.teardown(); + w.teardown(); } } }); diff --git a/dist/fix/fix.proxy.js b/dist/fix/fix.proxy.js index 513db8d93..d760047bd 100644 --- a/dist/fix/fix.proxy.js +++ b/dist/fix/fix.proxy.js @@ -1,2035 +1,2458 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Fix = {})); + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Fix = {})); }(this, (function (exports) { 'use strict'; - function _typeof(obj) { - "@babel/helpers - typeof"; - - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; + function _typeof(obj) { + "@babel/helpers - typeof"; + + if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { + _typeof = function (obj) { + return typeof obj; + }; + } else { + _typeof = function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + } + + return _typeof(obj); + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _slicedToArray(arr, i) { + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); + } + + function _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); + } + + function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + } + + function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; + } + + function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); + } + + function _iterableToArrayLimit(arr, i) { + if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; + var _arr = []; + var _n = true; + var _d = false; + var _e = undefined; + + try { + for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { + _arr.push(_s.value); + + if (i && _arr.length === i) break; + } + } catch (err) { + _d = true; + _e = err; + } finally { + try { + if (!_n && _i["return"] != null) _i["return"](); + } finally { + if (_d) throw _e; + } + } + + return _arr; + } + + function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + + function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; + + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; + + return arr2; + } + + function _nonIterableSpread() { + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + } + + function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + } + + function _createForOfIteratorHelper(o, allowArrayLike) { + var it; + + if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { + if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { + if (it) o = it; + var i = 0; + + var F = function () {}; + + return { + s: F, + n: function () { + if (i >= o.length) return { + done: true }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + return { + done: false, + value: o[i++] }; - } - - return _typeof(obj); - } - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } - - function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; - } - - return obj; - } - - var EMPTY_OBJ = Object.freeze({}); - Object.freeze([]); - var extend = Object.assign; - var hasOwnProperty = Object.prototype.hasOwnProperty; - - var hasOwn = function hasOwn(val, key) { - return hasOwnProperty.call(val, key); + }, + e: function (e) { + throw e; + }, + f: F + }; + } + + throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + } + + var normalCompletion = true, + didErr = false, + err; + return { + s: function () { + it = o[Symbol.iterator](); + }, + n: function () { + var step = it.next(); + normalCompletion = step.done; + return step; + }, + e: function (e) { + didErr = true; + err = e; + }, + f: function () { + try { + if (!normalCompletion && it.return != null) it.return(); + } finally { + if (didErr) throw err; + } + } }; - - var isArray = Array.isArray; - - var isMap$1 = function isMap(val) { - return toTypeString$1(val) === "[object Map]"; + } + + /** + * Make a map and return a function for checking if a key + * is in that map. + * IMPORTANT: all calls of this function must be prefixed with + * \/\*#\_\_PURE\_\_\*\/ + * So that rollup can tree-shake them if necessary. + */ + function makeMap(str, expectsLowerCase) { + var map = Object.create(null); + var list = str.split(','); + + for (var i = 0; i < list.length; i++) { + map[list[i]] = true; + } + + return expectsLowerCase ? function (val) { + return !!map[val.toLowerCase()]; + } : function (val) { + return !!map[val]; }; + } - var isFunction = function isFunction(val) { - return typeof val === "function"; - }; + Object.freeze({}); + Object.freeze([]); + var extend = Object.assign; + var hasOwnProperty = Object.prototype.hasOwnProperty; - var isString = function isString(val) { - return typeof val === "string"; - }; + var hasOwn = function hasOwn(val, key) { + return hasOwnProperty.call(val, key); + }; - var isSymbol = function isSymbol(val) { - return _typeof(val) === "symbol"; - }; + var isArray = Array.isArray; - var isObject = function isObject(val) { - return val !== null && _typeof(val) === "object"; - }; + var isMap$1 = function isMap(val) { + return toTypeString$1(val) === '[object Map]'; + }; - var objectToString$1 = Object.prototype.toString; + var isFunction = function isFunction(val) { + return typeof val === 'function'; + }; - var toTypeString$1 = function toTypeString(value) { - return objectToString$1.call(value); - }; + var isString = function isString(val) { + return typeof val === 'string'; + }; - var toRawType = function toRawType(value) { - return (// extract "RawType" from strings like "[object RawType]" - toTypeString$1(value).slice(8, -1) - ); - }; + var isSymbol = function isSymbol(val) { + return _typeof(val) === 'symbol'; + }; - var isIntegerKey = function isIntegerKey(key) { - return isString(key) && key !== "NaN" && key[0] !== "-" && "".concat(parseInt(key, 10)) === key; - }; + var isObject = function isObject(val) { + return val !== null && _typeof(val) === 'object'; + }; - var cacheStringFunction = function cacheStringFunction(fn) { - var cache = Object.create(null); - return function (str) { - var hit = cache[str]; - return hit || (cache[str] = fn(str)); - }; - }; - /** - * @private - */ + var objectToString$1 = Object.prototype.toString; + var toTypeString$1 = function toTypeString(value) { + return objectToString$1.call(value); + }; - var capitalize = cacheStringFunction(function (str) { - return str.charAt(0).toUpperCase() + str.slice(1); - }); // compare whether a value has changed, accounting for NaN. + var toRawType = function toRawType(value) { + // extract "RawType" from strings like "[object RawType]" + return toTypeString$1(value).slice(8, -1); + }; - var hasChanged$1 = function hasChanged(value, oldValue) { - return value !== oldValue && (value === value || oldValue === oldValue); - }; + var isIntegerKey = function isIntegerKey(key) { + return isString(key) && key !== 'NaN' && key[0] !== '-' && '' + parseInt(key, 10) === key; + }; - var targetMap = new WeakMap(); - var effectStack = []; - var activeEffect; - var ITERATE_KEY = Symbol("iterate"); - var MAP_KEY_ITERATE_KEY = Symbol("Map key iterate"); + var cacheStringFunction = function cacheStringFunction(fn) { + var cache = Object.create(null); + return function (str) { + var hit = cache[str]; + return hit || (cache[str] = fn(str)); + }; + }; + /** + * @private + */ - function isEffect(fn) { - return fn && fn._isEffect === true; - } - function effect(fn) { - var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EMPTY_OBJ; + var capitalize = cacheStringFunction(function (str) { + return str.charAt(0).toUpperCase() + str.slice(1); + }); // compare whether a value has changed, accounting for NaN. - if (isEffect(fn)) { - fn = fn.raw; - } + var hasChanged$1 = function hasChanged(value, oldValue) { + return !Object.is(value, oldValue); + }; - var effect = createReactiveEffect(fn, options); + var activeEffectScope; - if (!options.lazy) { - effect(); - } + function recordEffectScope(effect, scope) { + scope = scope || activeEffectScope; - return effect; + if (scope && scope.active) { + scope.effects.push(effect); } + } - function stop(effect) { - if (effect.active) { - cleanup(effect); + var createDep = function createDep(effects) { + var dep = new Set(effects); + dep.w = 0; + dep.n = 0; + return dep; + }; - if (effect.options.onStop) { - effect.options.onStop(); - } + var wasTracked = function wasTracked(dep) { + return (dep.w & trackOpBit) > 0; + }; - effect.active = false; - } - } - - var uid$1 = 0; + var newTracked = function newTracked(dep) { + return (dep.n & trackOpBit) > 0; + }; - function createReactiveEffect(fn, options) { - var effect = function reactiveEffect() { - if (!effect.active) { - return options.scheduler ? undefined : fn(); - } - - if (!effectStack.includes(effect)) { - cleanup(effect); - - try { - enableTracking(); - effectStack.push(effect); - activeEffect = effect; - return fn(); - } finally { - effectStack.pop(); - resetTracking(); - activeEffect = effectStack[effectStack.length - 1]; - } - } - }; + var initDepMarkers = function initDepMarkers(_ref) { + var deps = _ref.deps; - effect.id = uid$1++; - effect.allowRecurse = !!options.allowRecurse; - effect._isEffect = true; - effect.active = true; - effect.raw = fn; - effect.deps = []; - effect.options = options; - return effect; + if (deps.length) { + for (var i = 0; i < deps.length; i++) { + deps[i].w |= trackOpBit; // set was tracked + } } + }; - function cleanup(effect) { - var deps = effect.deps; + var finalizeDepMarkers = function finalizeDepMarkers(effect) { + var deps = effect.deps; - if (deps.length) { - for (var i = 0; i < deps.length; i++) { - deps[i].delete(effect); - } + if (deps.length) { + var ptr = 0; - deps.length = 0; - } - } + for (var i = 0; i < deps.length; i++) { + var dep = deps[i]; - var shouldTrack = true; - var trackStack = []; + if (wasTracked(dep) && !newTracked(dep)) { + dep.delete(effect); + } else { + deps[ptr++] = dep; + } // clear bits - function pauseTracking() { - trackStack.push(shouldTrack); - shouldTrack = false; - } - function enableTracking() { - trackStack.push(shouldTrack); - shouldTrack = true; - } + dep.w &= ~trackOpBit; + dep.n &= ~trackOpBit; + } - function resetTracking() { - var last = trackStack.pop(); - shouldTrack = last === undefined ? true : last; + deps.length = ptr; } + }; - function track(target, type, key) { - if (!shouldTrack || activeEffect === undefined) { - return; - } + var targetMap = new WeakMap(); // The number of effects currently being tracked recursively. - var depsMap = targetMap.get(target); + var effectTrackDepth = 0; + var trackOpBit = 1; + /** + * The bitwise track markers support at most 30 levels of recursion. + * This value is chosen to enable modern JS engines to use a SMI on all platforms. + * When recursion depth is greater, fall back to using a full cleanup. + */ - if (!depsMap) { - targetMap.set(target, depsMap = new Map()); - } + var maxMarkerBits = 30; + var effectStack = []; + var activeEffect; + var ITERATE_KEY = Symbol('iterate'); + var MAP_KEY_ITERATE_KEY = Symbol('Map key iterate'); - var dep = depsMap.get(key); + var ReactiveEffect = /*#__PURE__*/function () { + function ReactiveEffect(fn) { + var scheduler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; + var scope = arguments.length > 2 ? arguments[2] : undefined; - if (!dep) { - depsMap.set(key, dep = new Set()); - } + _classCallCheck(this, ReactiveEffect); - if (!dep.has(activeEffect)) { - dep.add(activeEffect); - activeEffect.deps.push(dep); - - if (activeEffect.options.onTrack) { - activeEffect.options.onTrack({ - effect: activeEffect, - target: target, - type: type, - key: key - }); - } - } + this.fn = fn; + this.scheduler = scheduler; + this.active = true; + this.deps = []; + recordEffectScope(this, scope); } - function trigger(target, type, key, newValue, oldValue, oldTarget) { - var depsMap = targetMap.get(target); - - if (!depsMap) { - // never been tracked - return; - } - - var effects = new Set(); - - var add = function add(effectsToAdd) { - if (effectsToAdd) { - effectsToAdd.forEach(function (effect) { - if (effect !== activeEffect || effect.allowRecurse) { - effects.add(effect); - } - }); - } - }; - - if (type === "clear" - /* CLEAR */ - ) { - // collection being cleared - // trigger all effects for target - depsMap.forEach(add); - } else if (key === "length" && isArray(target)) { - depsMap.forEach(function (dep, key) { - if (key === "length" || key >= newValue) { - add(dep); - } - }); - } else { - // schedule runs for SET | ADD | DELETE - if (key !== void 0) { - add(depsMap.get(key)); - } // also run for iteration key on ADD | DELETE | Map.SET - - - switch (type) { - case "add" - /* ADD */ - : - if (!isArray(target)) { - add(depsMap.get(ITERATE_KEY)); - - if (isMap$1(target)) { - add(depsMap.get(MAP_KEY_ITERATE_KEY)); - } - } else if (isIntegerKey(key)) { - // new index added to array -> length changes - add(depsMap.get("length")); - } - - break; - - case "delete" - /* DELETE */ - : - if (!isArray(target)) { - add(depsMap.get(ITERATE_KEY)); - - if (isMap$1(target)) { - add(depsMap.get(MAP_KEY_ITERATE_KEY)); - } - } - - break; - - case "set" - /* SET */ - : - if (isMap$1(target)) { - add(depsMap.get(ITERATE_KEY)); - } - - break; - } + _createClass(ReactiveEffect, [{ + key: "run", + value: function run() { + if (!this.active) { + return this.fn(); } - var run = function run(effect) { - if (effect.options.onTrigger) { - effect.options.onTrigger({ - effect: effect, - target: target, - key: key, - type: type, - newValue: newValue, - oldValue: oldValue, - oldTarget: oldTarget - }); - } + if (!effectStack.includes(this)) { + try { + effectStack.push(activeEffect = this); + enableTracking(); + trackOpBit = 1 << ++effectTrackDepth; - if (effect.options.scheduler) { - effect.options.scheduler(effect); + if (effectTrackDepth <= maxMarkerBits) { + initDepMarkers(this); } else { - effect(); + cleanupEffect(this); } - }; - - effects.forEach(run); - } - - var builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol).map(function (key) { - return Symbol[key]; - }).filter(isSymbol)); - var get = /* #__PURE__*/createGetter(); - var shallowGet = /* #__PURE__*/createGetter(false, true); - var readonlyGet = /* #__PURE__*/createGetter(true); - var shallowReadonlyGet = /* #__PURE__*/createGetter(true, true); - var arrayInstrumentations = {}; - ["includes", "indexOf", "lastIndexOf"].forEach(function (key) { - var method = Array.prototype[key]; - - arrayInstrumentations[key] = function () { - var arr = toRaw(this); - - for (var i = 0, l = this.length; i < l; i++) { - track(arr, "get" - /* GET */ - , "".concat(i)); - } // we run the method using the original args first (which may be reactive) - - for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) { - args[_key2] = arguments[_key2]; + return this.fn(); + } finally { + if (effectTrackDepth <= maxMarkerBits) { + finalizeDepMarkers(this); } - var res = method.apply(arr, args); - - if (res === -1 || res === false) { - // if that didn't work, run it again using raw values. - return method.apply(arr, args.map(toRaw)); - } else { - return res; - } - }; - }); - ["push", "pop", "shift", "unshift", "splice"].forEach(function (key) { - var method = Array.prototype[key]; - - arrayInstrumentations[key] = function () { - pauseTracking(); - - for (var _len2 = arguments.length, args = new Array(_len2), _key3 = 0; _key3 < _len2; _key3++) { - args[_key3] = arguments[_key3]; - } - - var res = method.apply(this, args); + trackOpBit = 1 << --effectTrackDepth; resetTracking(); - return res; - }; - }); - - function createGetter() { - var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; - var shallow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - return function get(target, key, receiver) { - if (key === "__v_isReactive" - /* IS_REACTIVE */ - ) { - return !isReadonly; - } else if (key === "__v_isReadonly" - /* IS_READONLY */ - ) { - return isReadonly; - } else if (key === "__v_raw" - /* RAW */ - && receiver === (isReadonly ? readonlyMap : reactiveMap).get(target)) { - return target; - } + effectStack.pop(); + var n = effectStack.length; + activeEffect = n > 0 ? effectStack[n - 1] : undefined; + } + } + } + }, { + key: "stop", + value: function stop() { + if (this.active) { + cleanupEffect(this); - var targetIsArray = isArray(target); + if (this.onStop) { + this.onStop(); + } - if (targetIsArray && hasOwn(arrayInstrumentations, key)) { - return Reflect.get(arrayInstrumentations, key, receiver); - } + this.active = false; + } + } + }]); - var res = Reflect.get(target, key, receiver); + return ReactiveEffect; + }(); - if (isSymbol(key) ? builtInSymbols.has(key) : key === "__proto__" || key === "__v_isRef") { - return res; - } + function cleanupEffect(effect) { + var deps = effect.deps; - if (!isReadonly) { - track(target, "get" - /* GET */ - , key); - } + if (deps.length) { + for (var i = 0; i < deps.length; i++) { + deps[i].delete(effect); + } - if (shallow) { - return res; - } + deps.length = 0; + } + } - if (isRef(res)) { - // ref unwrapping - does not apply for Array + integer key. - var shouldUnwrap = !targetIsArray || !isIntegerKey(key); - return shouldUnwrap ? res.value : res; - } + function effect(fn, options) { + if (fn.effect) { + fn = fn.effect.fn; + } - if (isObject(res)) { - // Convert returned value into a proxy as well. we do the isObject check - // here to avoid invalid value warning. Also need to lazy access readonly - // and reactive here to avoid circular dependency. - return isReadonly ? readonly(res) : reactive(res); - } + var _effect = new ReactiveEffect(fn); - return res; - }; + if (options) { + extend(_effect, options); + if (options.scope) recordEffectScope(_effect, options.scope); } - var set$1 = /* #__PURE__*/createSetter(); - var shallowSet = /* #__PURE__*/createSetter(true); + if (!options || !options.lazy) { + _effect.run(); + } - function createSetter() { - var shallow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; - return function set(target, key, value, receiver) { - var oldValue = target[key]; + var runner = _effect.run.bind(_effect); - if (!shallow) { - value = toRaw(value); + runner.effect = _effect; + return runner; + } - if (!isArray(target) && isRef(oldValue) && !isRef(value)) { - oldValue.value = value; - return true; - } - } + function stop(runner) { + runner.effect.stop(); + } - var hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key); - var result = Reflect.set(target, key, value, receiver); // don't trigger if target is something up in the prototype chain of original - - if (target === toRaw(receiver)) { - if (!hadKey) { - trigger(target, "add" - /* ADD */ - , key, value); - } else if (hasChanged$1(value, oldValue) || key === "length") { - trigger(target, "set" - /* SET */ - , key, value, oldValue); - } - } + var shouldTrack = true; + var trackStack = []; - return result; - }; - } + function pauseTracking() { + trackStack.push(shouldTrack); + shouldTrack = false; + } - function deleteProperty(target, key) { - var hadKey = hasOwn(target, key); - var oldValue = target[key]; - var result = Reflect.deleteProperty(target, key); + function enableTracking() { + trackStack.push(shouldTrack); + shouldTrack = true; + } - if (result && hadKey) { - trigger(target, "delete" - /* DELETE */ - , key, undefined, oldValue); - } + function resetTracking() { + var last = trackStack.pop(); + shouldTrack = last === undefined ? true : last; + } - return result; + function track(target, type, key) { + if (!isTracking()) { + return; } - function has$1(target, key) { - var result = Reflect.has(target, key); - - if (!isSymbol(key) || !builtInSymbols.has(key)) { - track(target, "has" - /* HAS */ - , key); - } + var depsMap = targetMap.get(target); - return result; + if (!depsMap) { + targetMap.set(target, depsMap = new Map()); } - function ownKeys(target) { - track(target, "iterate" - /* ITERATE */ - , isArray(target) ? "length" : ITERATE_KEY); - return Reflect.ownKeys(target); - } - - var mutableHandlers = { - get: get, - set: set$1, - deleteProperty: deleteProperty, - has: has$1, - ownKeys: ownKeys - }; - var readonlyHandlers = { - get: readonlyGet, - set: function set(target, key) { - { - console.warn("Set operation on key \"".concat(String(key), "\" failed: target is readonly."), target); - } - return true; - }, - deleteProperty: function deleteProperty(target, key) { - { - console.warn("Delete operation on key \"".concat(String(key), "\" failed: target is readonly."), target); - } - return true; - } - }; - extend({}, mutableHandlers, { - get: shallowGet, - set: shallowSet - }); // Props handlers are special in the sense that it should not unwrap top-level - // refs (in order to allow refs to be explicitly passed down), but should - // retain the reactivity of the normal readonly object. - - extend({}, readonlyHandlers, { - get: shallowReadonlyGet - }); - - var toReactive = function toReactive(value) { - return isObject(value) ? reactive(value) : value; - }; + var dep = depsMap.get(key); - var toReadonly = function toReadonly(value) { - return isObject(value) ? readonly(value) : value; - }; - - var toShallow = function toShallow(value) { - return value; - }; + if (!dep) { + depsMap.set(key, dep = createDep()); + } - var getProto = function getProto(v) { - return Reflect.getPrototypeOf(v); + var eventInfo = { + effect: activeEffect, + target: target, + type: type, + key: key }; + trackEffects(dep, eventInfo); + } - function get$1(target, key) { - var isReadonly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var isShallow = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; - // #1772: readonly(reactive(Map)) should return readonly + reactive version - // of the value - target = target["__v_raw" - /* RAW */ - ]; - var rawTarget = toRaw(target); - var rawKey = toRaw(key); - - if (key !== rawKey) { - !isReadonly && track(rawTarget, "get" - /* GET */ - , key); - } - - !isReadonly && track(rawTarget, "get" - /* GET */ - , rawKey); + function isTracking() { + return shouldTrack && activeEffect !== undefined; + } - var _getProto = getProto(rawTarget), - has = _getProto.has; + function trackEffects(dep, debuggerEventExtraInfo) { + var shouldTrack = false; - var wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive; + if (effectTrackDepth <= maxMarkerBits) { + if (!newTracked(dep)) { + dep.n |= trackOpBit; // set newly tracked - if (has.call(rawTarget, key)) { - return wrap(target.get(key)); - } else if (has.call(rawTarget, rawKey)) { - return wrap(target.get(rawKey)); - } + shouldTrack = !wasTracked(dep); + } + } else { + // Full cleanup mode. + shouldTrack = !dep.has(activeEffect); } - function has$1$1(key) { - var isReadonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - var target = this["__v_raw" - /* RAW */ - ]; - var rawTarget = toRaw(target); - var rawKey = toRaw(key); - - if (key !== rawKey) { - !isReadonly && track(rawTarget, "has" - /* HAS */ - , key); - } + if (shouldTrack) { + dep.add(activeEffect); + activeEffect.deps.push(dep); - !isReadonly && track(rawTarget, "has" - /* HAS */ - , rawKey); - return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey); + if (activeEffect.onTrack) { + activeEffect.onTrack(Object.assign({ + effect: activeEffect + }, debuggerEventExtraInfo)); + } } + } + + function trigger(target, type, key, newValue, oldValue, oldTarget) { + var depsMap = targetMap.get(target); - function size(target) { - var isReadonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - target = target["__v_raw" - /* RAW */ - ]; - !isReadonly && track(toRaw(target), "iterate" - /* ITERATE */ - , ITERATE_KEY); - return Reflect.get(target, "size", target); + if (!depsMap) { + // never been tracked + return; } - function add(value) { - value = toRaw(value); - var target = toRaw(this); - var proto = getProto(target); - var hadKey = proto.has.call(target, value); - var result = target.add(value); + var deps = []; - if (!hadKey) { - trigger(target, "add" - /* ADD */ - , value, value); + if (type === "clear" + /* CLEAR */ + ) { + // collection being cleared + // trigger all effects for target + deps = _toConsumableArray(depsMap.values()); + } else if (key === 'length' && isArray(target)) { + depsMap.forEach(function (dep, key) { + if (key === 'length' || key >= newValue) { + deps.push(dep); } + }); + } else { + // schedule runs for SET | ADD | DELETE + if (key !== void 0) { + deps.push(depsMap.get(key)); + } // also run for iteration key on ADD | DELETE | Map.SET - return result; - } - function set$1$1(key, value) { - value = toRaw(value); - var target = toRaw(this); - - var _getProto2 = getProto(target), - has = _getProto2.has, - get = _getProto2.get; + switch (type) { + case "add" + /* ADD */ + : + if (!isArray(target)) { + deps.push(depsMap.get(ITERATE_KEY)); - var hadKey = has.call(target, key); + if (isMap$1(target)) { + deps.push(depsMap.get(MAP_KEY_ITERATE_KEY)); + } + } else if (isIntegerKey(key)) { + // new index added to array -> length changes + deps.push(depsMap.get('length')); + } - if (!hadKey) { - key = toRaw(key); - hadKey = has.call(target, key); - } else { - checkIdentityKeys(target, has, key); - } + break; - var oldValue = get.call(target, key); - var result = target.set(key, value); + case "delete" + /* DELETE */ + : + if (!isArray(target)) { + deps.push(depsMap.get(ITERATE_KEY)); - if (!hadKey) { - trigger(target, "add" - /* ADD */ - , key, value); - } else if (hasChanged$1(value, oldValue) || key === "length") { - trigger(target, "set" - /* SET */ - , key, value, oldValue); - } + if (isMap$1(target)) { + deps.push(depsMap.get(MAP_KEY_ITERATE_KEY)); + } + } - return result; - } + break; - function deleteEntry(key) { - var target = toRaw(this); + case "set" + /* SET */ + : + if (isMap$1(target)) { + deps.push(depsMap.get(ITERATE_KEY)); + } - var _getProto3 = getProto(target), - has = _getProto3.has, - get = _getProto3.get; + break; + } + } - var hadKey = has.call(target, key); + var eventInfo = { + target: target, + type: type, + key: key, + newValue: newValue, + oldValue: oldValue, + oldTarget: oldTarget + }; - if (!hadKey) { - key = toRaw(key); - hadKey = has.call(target, key); + if (deps.length === 1) { + if (deps[0]) { + { + triggerEffects(deps[0], eventInfo); + } + } + } else { + var effects = []; + + var _iterator = _createForOfIteratorHelper(deps), + _step; + + try { + for (_iterator.s(); !(_step = _iterator.n()).done;) { + var dep = _step.value; + + if (dep) { + effects.push.apply(effects, _toConsumableArray(dep)); + } + } + } catch (err) { + _iterator.e(err); + } finally { + _iterator.f(); + } + + { + triggerEffects(createDep(effects), eventInfo); + } + } + } + + function triggerEffects(dep, debuggerEventExtraInfo) { + // spread into array for stabilization + var _iterator2 = _createForOfIteratorHelper(isArray(dep) ? dep : _toConsumableArray(dep)), + _step2; + + try { + for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { + var _effect2 = _step2.value; + + if (_effect2 !== activeEffect || _effect2.allowRecurse) { + if (_effect2.onTrigger) { + _effect2.onTrigger(extend({ + effect: _effect2 + }, debuggerEventExtraInfo)); + } + + if (_effect2.scheduler) { + _effect2.scheduler(); + } else { + _effect2.run(); + } + } + } + } catch (err) { + _iterator2.e(err); + } finally { + _iterator2.f(); + } + } + + var isNonTrackableKeys = /*#__PURE__*/makeMap("__proto__,__v_isRef,__isVue"); + var builtInSymbols = new Set(Object.getOwnPropertyNames(Symbol).map(function (key) { + return Symbol[key]; + }).filter(isSymbol)); + var get = /*#__PURE__*/createGetter(); + var readonlyGet = /*#__PURE__*/createGetter(true); + var arrayInstrumentations = /*#__PURE__*/createArrayInstrumentations(); + + function createArrayInstrumentations() { + var instrumentations = {}; + ['includes', 'indexOf', 'lastIndexOf'].forEach(function (key) { + instrumentations[key] = function () { + var arr = toRaw(this); + + for (var i = 0, l = this.length; i < l; i++) { + track(arr, "get" + /* GET */ + , i + ''); + } // we run the method using the original args first (which may be reactive) + + + for (var _len2 = arguments.length, args = new Array(_len2), _key3 = 0; _key3 < _len2; _key3++) { + args[_key3] = arguments[_key3]; + } + + var res = arr[key].apply(arr, args); + + if (res === -1 || res === false) { + // if that didn't work, run it again using raw values. + return arr[key].apply(arr, _toConsumableArray(args.map(toRaw))); } else { - checkIdentityKeys(target, has, key); + return res; } + }; + }); + ['push', 'pop', 'shift', 'unshift', 'splice'].forEach(function (key) { + instrumentations[key] = function () { + pauseTracking(); - var oldValue = get ? get.call(target, key) : undefined; // forward the operation before queueing reactions - - var result = target.delete(key); - - if (hadKey) { - trigger(target, "delete" - /* DELETE */ - , key, undefined, oldValue); + for (var _len3 = arguments.length, args = new Array(_len3), _key4 = 0; _key4 < _len3; _key4++) { + args[_key4] = arguments[_key4]; } - return result; - } + var res = toRaw(this)[key].apply(this, args); + resetTracking(); + return res; + }; + }); + return instrumentations; + } + + function createGetter() { + var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + var shallow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + return function get(target, key, receiver) { + if (key === "__v_isReactive" + /* IS_REACTIVE */ + ) { + return !isReadonly; + } else if (key === "__v_isReadonly" + /* IS_READONLY */ + ) { + return isReadonly; + } else if (key === "__v_raw" + /* RAW */ + && receiver === (isReadonly ? shallow ? shallowReadonlyMap : readonlyMap : shallow ? shallowReactiveMap : reactiveMap).get(target)) { + return target; + } + + var targetIsArray = isArray(target); + + if (!isReadonly && targetIsArray && hasOwn(arrayInstrumentations, key)) { + return Reflect.get(arrayInstrumentations, key, receiver); + } + + var res = Reflect.get(target, key, receiver); + + if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) { + return res; + } + + if (!isReadonly) { + track(target, "get" + /* GET */ + , key); + } + + if (shallow) { + return res; + } + + if (isRef(res)) { + // ref unwrapping - does not apply for Array + integer key. + var shouldUnwrap = !targetIsArray || !isIntegerKey(key); + return shouldUnwrap ? res.value : res; + } + + if (isObject(res)) { + // Convert returned value into a proxy as well. we do the isObject check + // here to avoid invalid value warning. Also need to lazy access readonly + // and reactive here to avoid circular dependency. + return isReadonly ? readonly(res) : reactive(res); + } + + return res; + }; + } + + var set$1 = /*#__PURE__*/createSetter(); - function clear() { - var target = toRaw(this); - var hadItems = target.size !== 0; - var oldTarget = isMap$1(target) ? new Map(target) : new Set(target); // forward the operation before queueing reactions + function createSetter() { + var shallow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + return function set(target, key, value, receiver) { + var oldValue = target[key]; - var result = target.clear(); + if (!shallow && !isReadonly(value)) { + value = toRaw(value); + oldValue = toRaw(oldValue); - if (hadItems) { - trigger(target, "clear" - /* CLEAR */ - , undefined, undefined, oldTarget); + if (!isArray(target) && isRef(oldValue) && !isRef(value)) { + oldValue.value = value; + return true; } + } - return result; - } - - function createForEach(isReadonly, isShallow) { - return function forEach(callback, thisArg) { - var observed = this; - var target = observed["__v_raw" - /* RAW */ - ]; - var rawTarget = toRaw(target); - var wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive; - !isReadonly && track(rawTarget, "iterate" - /* ITERATE */ - , ITERATE_KEY); - return target.forEach(function (value, key) { - return (// important: make sure the callback is - // 1. invoked with the reactive map as `this` and 3rd arg - // 2. the value received should be a corresponding reactive/readonly. - callback.call(thisArg, wrap(value), wrap(key), observed) - ); - }); - }; - } + var hadKey = isArray(target) && isIntegerKey(key) ? Number(key) < target.length : hasOwn(target, key); + var result = Reflect.set(target, key, value, receiver); // don't trigger if target is something up in the prototype chain of original - function createIterableMethod(method, isReadonly, isShallow) { - return function () { - var target = this["__v_raw" - /* RAW */ - ]; - var rawTarget = toRaw(target); - var targetIsMap = isMap$1(rawTarget); - var isPair = method === "entries" || method === Symbol.iterator && targetIsMap; - var isKeyOnly = method === "keys" && targetIsMap; - var innerIterator = target[method].apply(target, arguments); - var wrap = isReadonly ? toReadonly : isShallow ? toShallow : toReactive; - !isReadonly && track(rawTarget, "iterate" - /* ITERATE */ - , isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); // return a wrapped iterator which returns observed versions of the - // values emitted from the real iterator - - return _defineProperty({ - // iterator protocol - next: function next() { - var _innerIterator$next = innerIterator.next(), - value = _innerIterator$next.value, - done = _innerIterator$next.done; - - return done ? { - value: value, - done: done - } : { - value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value), - done: done - }; - } - }, Symbol.iterator, function () { - return this; - }); - }; - } - - function createReadonlyMethod(type) { - return function () { - { - var key = (arguments.length <= 0 ? undefined : arguments[0]) ? "on key \"".concat(arguments.length <= 0 ? undefined : arguments[0], "\" ") : ""; - console.warn("".concat(capitalize(type), " operation ").concat(key, "failed: target is readonly."), toRaw(this)); - } - return type === "delete" - /* DELETE */ - ? false : this; - }; - } + if (target === toRaw(receiver)) { + if (!hadKey) { + trigger(target, "add" + /* ADD */ + , key, value); + } else if (hasChanged$1(value, oldValue)) { + trigger(target, "set" + /* SET */ + , key, value, oldValue); + } + } - var mutableInstrumentations = { - get: function get(key) { - return get$1(this, key); - }, + return result; + }; + } + + function deleteProperty(target, key) { + var hadKey = hasOwn(target, key); + var oldValue = target[key]; + var result = Reflect.deleteProperty(target, key); + + if (result && hadKey) { + trigger(target, "delete" + /* DELETE */ + , key, undefined, oldValue); + } + + return result; + } + + function has$1(target, key) { + var result = Reflect.has(target, key); + + if (!isSymbol(key) || !builtInSymbols.has(key)) { + track(target, "has" + /* HAS */ + , key); + } + + return result; + } + + function ownKeys(target) { + track(target, "iterate" + /* ITERATE */ + , isArray(target) ? 'length' : ITERATE_KEY); + return Reflect.ownKeys(target); + } + + var mutableHandlers = { + get: get, + set: set$1, + deleteProperty: deleteProperty, + has: has$1, + ownKeys: ownKeys + }; + var readonlyHandlers = { + get: readonlyGet, + set: function set(target, key) { + { + console.warn("Set operation on key \"".concat(String(key), "\" failed: target is readonly."), target); + } + return true; + }, + deleteProperty: function deleteProperty(target, key) { + { + console.warn("Delete operation on key \"".concat(String(key), "\" failed: target is readonly."), target); + } + return true; + } + }; + + var toShallow = function toShallow(value) { + return value; + }; + + var getProto = function getProto(v) { + return Reflect.getPrototypeOf(v); + }; + + function get$1(target, key) { + var isReadonly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var isShallow = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + // #1772: readonly(reactive(Map)) should return readonly + reactive version + // of the value + target = target["__v_raw" + /* RAW */ + ]; + var rawTarget = toRaw(target); + var rawKey = toRaw(key); + + if (key !== rawKey) { + !isReadonly && track(rawTarget, "get" + /* GET */ + , key); + } + + !isReadonly && track(rawTarget, "get" + /* GET */ + , rawKey); + + var _getProto = getProto(rawTarget), + has = _getProto.has; + + var wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; + + if (has.call(rawTarget, key)) { + return wrap(target.get(key)); + } else if (has.call(rawTarget, rawKey)) { + return wrap(target.get(rawKey)); + } else if (target !== rawTarget) { + // #3602 readonly(reactive(Map)) + // ensure that the nested reactive `Map` can do tracking for itself + target.get(key); + } + } + + function has$1$1(key) { + var isReadonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var target = this["__v_raw" + /* RAW */ + ]; + var rawTarget = toRaw(target); + var rawKey = toRaw(key); + + if (key !== rawKey) { + !isReadonly && track(rawTarget, "has" + /* HAS */ + , key); + } + + !isReadonly && track(rawTarget, "has" + /* HAS */ + , rawKey); + return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey); + } + + function size(target) { + var isReadonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + target = target["__v_raw" + /* RAW */ + ]; + !isReadonly && track(toRaw(target), "iterate" + /* ITERATE */ + , ITERATE_KEY); + return Reflect.get(target, 'size', target); + } + + function add(value) { + value = toRaw(value); + var target = toRaw(this); + var proto = getProto(target); + var hadKey = proto.has.call(target, value); + + if (!hadKey) { + target.add(value); + trigger(target, "add" + /* ADD */ + , value, value); + } + + return this; + } + + function set$1$1(key, value) { + value = toRaw(value); + var target = toRaw(this); + + var _getProto2 = getProto(target), + has = _getProto2.has, + get = _getProto2.get; + + var hadKey = has.call(target, key); + + if (!hadKey) { + key = toRaw(key); + hadKey = has.call(target, key); + } else { + checkIdentityKeys(target, has, key); + } + + var oldValue = get.call(target, key); + target.set(key, value); + + if (!hadKey) { + trigger(target, "add" + /* ADD */ + , key, value); + } else if (hasChanged$1(value, oldValue)) { + trigger(target, "set" + /* SET */ + , key, value, oldValue); + } + + return this; + } + + function deleteEntry(key) { + var target = toRaw(this); + + var _getProto3 = getProto(target), + has = _getProto3.has, + get = _getProto3.get; + + var hadKey = has.call(target, key); + + if (!hadKey) { + key = toRaw(key); + hadKey = has.call(target, key); + } else { + checkIdentityKeys(target, has, key); + } + + var oldValue = get ? get.call(target, key) : undefined; // forward the operation before queueing reactions + + var result = target.delete(key); + + if (hadKey) { + trigger(target, "delete" + /* DELETE */ + , key, undefined, oldValue); + } + + return result; + } + + function clear() { + var target = toRaw(this); + var hadItems = target.size !== 0; + var oldTarget = isMap$1(target) ? new Map(target) : new Set(target); // forward the operation before queueing reactions + + var result = target.clear(); + + if (hadItems) { + trigger(target, "clear" + /* CLEAR */ + , undefined, undefined, oldTarget); + } + + return result; + } - get size() { - return size(this); - }, + function createForEach(isReadonly, isShallow) { + return function forEach(callback, thisArg) { + var observed = this; + var target = observed["__v_raw" + /* RAW */ + ]; + var rawTarget = toRaw(target); + var wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; + !isReadonly && track(rawTarget, "iterate" + /* ITERATE */ + , ITERATE_KEY); + return target.forEach(function (value, key) { + // important: make sure the callback is + // 1. invoked with the reactive map as `this` and 3rd arg + // 2. the value received should be a corresponding reactive/readonly. + return callback.call(thisArg, wrap(value), wrap(key), observed); + }); + }; + } + + function createIterableMethod(method, isReadonly, isShallow) { + return function () { + var target = this["__v_raw" + /* RAW */ + ]; + var rawTarget = toRaw(target); + var targetIsMap = isMap$1(rawTarget); + var isPair = method === 'entries' || method === Symbol.iterator && targetIsMap; + var isKeyOnly = method === 'keys' && targetIsMap; + var innerIterator = target[method].apply(target, arguments); + var wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive; + !isReadonly && track(rawTarget, "iterate" + /* ITERATE */ + , isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY); // return a wrapped iterator which returns observed versions of the + // values emitted from the real iterator + + return _defineProperty({ + // iterator protocol + next: function next() { + var _innerIterator$next = innerIterator.next(), + value = _innerIterator$next.value, + done = _innerIterator$next.done; + + return done ? { + value: value, + done: done + } : { + value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value), + done: done + }; + } + }, Symbol.iterator, function () { + return this; + }); + }; + } + + function createReadonlyMethod(type) { + return function () { + { + var key = (arguments.length <= 0 ? undefined : arguments[0]) ? "on key \"".concat(arguments.length <= 0 ? undefined : arguments[0], "\" ") : ""; + console.warn("".concat(capitalize(type), " operation ").concat(key, "failed: target is readonly."), toRaw(this)); + } + return type === "delete" + /* DELETE */ + ? false : this; + }; + } - has: has$1$1, - add: add, - set: set$1$1, - delete: deleteEntry, - clear: clear, - forEach: createForEach(false, false) + function createInstrumentations() { + var mutableInstrumentations = { + get: function get(key) { + return get$1(this, key); + }, + + get size() { + return size(this); + }, + + has: has$1$1, + add: add, + set: set$1$1, + delete: deleteEntry, + clear: clear, + forEach: createForEach(false, false) }; var shallowInstrumentations = { - get: function get(key) { - return get$1(this, key, false, true); - }, - - get size() { - return size(this); - }, - - has: has$1$1, - add: add, - set: set$1$1, - delete: deleteEntry, - clear: clear, - forEach: createForEach(false, true) + get: function get(key) { + return get$1(this, key, false, true); + }, + + get size() { + return size(this); + }, + + has: has$1$1, + add: add, + set: set$1$1, + delete: deleteEntry, + clear: clear, + forEach: createForEach(false, true) }; var readonlyInstrumentations = { - get: function get(key) { - return get$1(this, key, true); - }, - - get size() { - return size(this, true); - }, - - has: function has(key) { - return has$1$1.call(this, key, true); - }, - add: createReadonlyMethod("add" - /* ADD */ - ), - set: createReadonlyMethod("set" - /* SET */ - ), - delete: createReadonlyMethod("delete" - /* DELETE */ - ), - clear: createReadonlyMethod("clear" - /* CLEAR */ - ), - forEach: createForEach(true, false) + get: function get(key) { + return get$1(this, key, true); + }, + + get size() { + return size(this, true); + }, + + has: function has(key) { + return has$1$1.call(this, key, true); + }, + add: createReadonlyMethod("add" + /* ADD */ + ), + set: createReadonlyMethod("set" + /* SET */ + ), + delete: createReadonlyMethod("delete" + /* DELETE */ + ), + clear: createReadonlyMethod("clear" + /* CLEAR */ + ), + forEach: createForEach(true, false) + }; + var shallowReadonlyInstrumentations = { + get: function get(key) { + return get$1(this, key, true, true); + }, + + get size() { + return size(this, true); + }, + + has: function has(key) { + return has$1$1.call(this, key, true); + }, + add: createReadonlyMethod("add" + /* ADD */ + ), + set: createReadonlyMethod("set" + /* SET */ + ), + delete: createReadonlyMethod("delete" + /* DELETE */ + ), + clear: createReadonlyMethod("clear" + /* CLEAR */ + ), + forEach: createForEach(true, true) }; - var iteratorMethods = ["keys", "values", "entries", Symbol.iterator]; + var iteratorMethods = ['keys', 'values', 'entries', Symbol.iterator]; iteratorMethods.forEach(function (method) { - mutableInstrumentations[method] = createIterableMethod(method, false, false); - readonlyInstrumentations[method] = createIterableMethod(method, true, false); - shallowInstrumentations[method] = createIterableMethod(method, false, true); + mutableInstrumentations[method] = createIterableMethod(method, false, false); + readonlyInstrumentations[method] = createIterableMethod(method, true, false); + shallowInstrumentations[method] = createIterableMethod(method, false, true); + shallowReadonlyInstrumentations[method] = createIterableMethod(method, true, true); }); - - function createInstrumentationGetter(isReadonly, shallow) { - var instrumentations = shallow ? shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations; - return function (target, key, receiver) { - if (key === "__v_isReactive" - /* IS_REACTIVE */ - ) { - return !isReadonly; - } else if (key === "__v_isReadonly" - /* IS_READONLY */ - ) { - return isReadonly; - } else if (key === "__v_raw" - /* RAW */ - ) { - return target; - } - - return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver); - }; - } - - var mutableCollectionHandlers = { - get: createInstrumentationGetter(false, false) + return [mutableInstrumentations, readonlyInstrumentations, shallowInstrumentations, shallowReadonlyInstrumentations]; + } + + var _createInstrumentatio = /* #__PURE__*/createInstrumentations(), + _createInstrumentatio2 = _slicedToArray(_createInstrumentatio, 4), + mutableInstrumentations = _createInstrumentatio2[0], + readonlyInstrumentations = _createInstrumentatio2[1], + shallowInstrumentations = _createInstrumentatio2[2], + shallowReadonlyInstrumentations = _createInstrumentatio2[3]; + + function createInstrumentationGetter(isReadonly, shallow) { + var instrumentations = shallow ? isReadonly ? shallowReadonlyInstrumentations : shallowInstrumentations : isReadonly ? readonlyInstrumentations : mutableInstrumentations; + return function (target, key, receiver) { + if (key === "__v_isReactive" + /* IS_REACTIVE */ + ) { + return !isReadonly; + } else if (key === "__v_isReadonly" + /* IS_READONLY */ + ) { + return isReadonly; + } else if (key === "__v_raw" + /* RAW */ + ) { + return target; + } + + return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver); }; - var readonlyCollectionHandlers = { - get: createInstrumentationGetter(true, false) - }; - - function checkIdentityKeys(target, has, key) { - var rawKey = toRaw(key); - - if (rawKey !== key && has.call(target, rawKey)) { - var type = toRawType(target); - console.warn("Reactive ".concat(type, " contains both the raw and reactive ") + "versions of the same object".concat(type === "Map" ? " as keys" : "", ", ") + "which can lead to inconsistencies. " + "Avoid differentiating between the raw and reactive versions " + "of an object and only use the reactive version if possible."); - } + } + + var mutableCollectionHandlers = { + get: /*#__PURE__*/createInstrumentationGetter(false, false) + }; + var readonlyCollectionHandlers = { + get: /*#__PURE__*/createInstrumentationGetter(true, false) + }; + + function checkIdentityKeys(target, has, key) { + var rawKey = toRaw(key); + + if (rawKey !== key && has.call(target, rawKey)) { + var type = toRawType(target); + console.warn("Reactive ".concat(type, " contains both the raw and reactive ") + "versions of the same object".concat(type === "Map" ? " as keys" : "", ", ") + "which can lead to inconsistencies. " + "Avoid differentiating between the raw and reactive versions " + "of an object and only use the reactive version if possible."); + } + } + + var reactiveMap = new WeakMap(); + var shallowReactiveMap = new WeakMap(); + var readonlyMap = new WeakMap(); + var shallowReadonlyMap = new WeakMap(); + + function targetTypeMap(rawType) { + switch (rawType) { + case 'Object': + case 'Array': + return 1 + /* COMMON */ + ; + + case 'Map': + case 'Set': + case 'WeakMap': + case 'WeakSet': + return 2 + /* COLLECTION */ + ; + + default: + return 0 + /* INVALID */ + ; + } + } + + function getTargetType(value) { + return value["__v_skip" + /* SKIP */ + ] || !Object.isExtensible(value) ? 0 + /* INVALID */ + : targetTypeMap(toRawType(value)); + } + + function reactive(target) { + // if trying to observe a readonly proxy, return the readonly version. + if (target && target["__v_isReadonly" + /* IS_READONLY */ + ]) { + return target; + } + + return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap); + } + /** + * Creates a readonly copy of the original object. Note the returned copy is not + * made reactive, but `readonly` can be called on an already reactive object. + */ + + + function readonly(target) { + return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap); + } + + function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) { + if (!isObject(target)) { + { + console.warn("value cannot be made reactive: ".concat(String(target))); + } + return target; + } // target is already a Proxy, return it. + // exception: calling readonly() on a reactive object + + + if (target["__v_raw" + /* RAW */ + ] && !(isReadonly && target["__v_isReactive" + /* IS_REACTIVE */ + ])) { + return target; + } // target already has corresponding Proxy + + + var existingProxy = proxyMap.get(target); + + if (existingProxy) { + return existingProxy; + } // only a whitelist of value types can be observed. + + + var targetType = getTargetType(target); + + if (targetType === 0 + /* INVALID */ + ) { + return target; + } + + var proxy = new Proxy(target, targetType === 2 + /* COLLECTION */ + ? collectionHandlers : baseHandlers); + proxyMap.set(target, proxy); + return proxy; + } + + function isReactive(value) { + if (isReadonly(value)) { + return isReactive(value["__v_raw" + /* RAW */ + ]); + } + + return !!(value && value["__v_isReactive" + /* IS_REACTIVE */ + ]); + } + + function isReadonly(value) { + return !!(value && value["__v_isReadonly" + /* IS_READONLY */ + ]); + } + + function toRaw(observed) { + var raw = observed && observed["__v_raw" + /* RAW */ + ]; + return raw ? toRaw(raw) : observed; + } + + var toReactive = function toReactive(value) { + return isObject(value) ? reactive(value) : value; + }; + + var toReadonly = function toReadonly(value) { + return isObject(value) ? readonly(value) : value; + }; + + function trackRefValue(ref) { + if (isTracking()) { + ref = toRaw(ref); + + if (!ref.dep) { + ref.dep = createDep(); + } + + { + trackEffects(ref.dep, { + target: ref, + type: "get" + /* GET */ + , + key: 'value' + }); + } + } + } + + function triggerRefValue(ref, newVal) { + ref = toRaw(ref); + + if (ref.dep) { + { + triggerEffects(ref.dep, { + target: ref, + type: "set" + /* SET */ + , + key: 'value', + newValue: newVal + }); + } } + } - var reactiveMap = new WeakMap(); - var readonlyMap = new WeakMap(); + function isRef(r) { + return Boolean(r && r.__v_isRef === true); + } - function targetTypeMap(rawType) { - switch (rawType) { - case "Object": - case "Array": - return 1; + var ComputedRefImpl = /*#__PURE__*/function () { + function ComputedRefImpl(getter, _setter, isReadonly) { + var _this2 = this; - case "Map": - case "Set": - case "WeakMap": - case "WeakSet": - return 2; + _classCallCheck(this, ComputedRefImpl); - default: - return 0; + this._setter = _setter; + this.dep = undefined; + this._dirty = true; + this.__v_isRef = true; + this.effect = new ReactiveEffect(getter, function () { + if (!_this2._dirty) { + _this2._dirty = true; + triggerRefValue(_this2); } - } - - function getTargetType(value) { - return value["__v_skip" - /* SKIP */ - ] || !Object.isExtensible(value) ? 0 - /* INVALID */ - : targetTypeMap(toRawType(value)); - } + }); + this["__v_isReadonly" + /* IS_READONLY */ + ] = isReadonly; + } + + _createClass(ComputedRefImpl, [{ + key: "value", + get: function get() { + // the computed ref may get wrapped by other proxies e.g. readonly() #3376 + var self = toRaw(this); + trackRefValue(self); + + if (self._dirty) { + self._dirty = false; + self._value = self.effect.run(); + } + + return self._value; + }, + set: function set(newValue) { + this._setter(newValue); + } + }]); + + return ComputedRefImpl; + }(); + + function computed(getterOrOptions, debugOptions) { + var getter; + var setter; + var onlyGetter = isFunction(getterOrOptions); + + if (onlyGetter) { + getter = getterOrOptions; + + setter = function setter() { + console.warn('Write operation failed: computed value is readonly'); + }; + } else { + getter = getterOrOptions.get; + setter = getterOrOptions.set; + } + + var cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter); + + if (debugOptions) { + cRef.effect.onTrack = debugOptions.onTrack; + cRef.effect.onTrigger = debugOptions.onTrigger; + } + + return cRef; + } + + function noop() {} + function isNative(Ctor) { + return typeof Ctor === "function" && /native code/.test(Ctor.toString()); + } + var isIE = function isIE() { + if (typeof navigator === "undefined") { + return false; + } + + return /(msie|trident)/i.test(navigator.userAgent.toLowerCase()); + }; + var getIEVersion = function getIEVersion() { + var version = 0; + + if (typeof navigator === "undefined") { + return false; + } + + var agent = navigator.userAgent.toLowerCase(); + var v1 = agent.match(/(?:msie\s([\w.]+))/); + var v2 = agent.match(/(?:trident.*rv:([\w.]+))/); + + if (v1 && v2 && v1[1] && v2[1]) { + version = Math.max(v1[1] * 1, v2[1] * 1); + } else if (v1 && v1[1]) { + version = v1[1] * 1; + } else if (v2 && v2[1]) { + version = v2[1] * 1; + } else { + version = 0; + } + + return version; + }; + isIE() && getIEVersion() < 9; + var _toString = Object.prototype.toString; + function isPlainObject(obj) { + return _toString.call(obj) === "[object Object]"; + } + + function parsePath(path) { + // if (bailRE.test(path)) { + // return; + // } + var segments = path.length > 0 ? path.split(".") : []; + return function (obj) { + for (var i = 0; i < segments.length; i++) { + if (!obj) return; + obj = obj[segments[i]]; + } - function reactive(target) { - // if trying to observe a readonly proxy, return the readonly version. - if (target && target["__v_isReadonly" - /* IS_READONLY */ - ]) { - return target; + return obj; + }; + } + var nextTick = function () { + var callbacks = []; + var pending = false; + var timerFunc; + + function nextTickHandler() { + pending = false; + var copies = callbacks.slice(0); + callbacks.length = 0; + + for (var i = 0; i < copies.length; i++) { + copies[i](); + } + } // An asynchronous deferring mechanism. + // In pre 2.4, we used to use microtasks (Promise/MutationObserver) + // but microtasks actually has too high a priority and fires in between + // supposedly sequential events (e.g. #4521, #6690) or even between + // bubbling of the same event (#6566). Technically setImmediate should be + // the ideal choice, but it's not available everywhere; and the only polyfill + // that consistently queues the callback after all DOM events triggered in the + // same loop is by using MessageChannel. + + /* istanbul ignore if */ + + + if (typeof setImmediate !== "undefined" && isNative(setImmediate)) { + timerFunc = function timerFunc() { + setImmediate(nextTickHandler); + }; + } else if (typeof MessageChannel !== "undefined" && (isNative(MessageChannel) || // PhantomJS + MessageChannel.toString() === "[object MessageChannelConstructor]")) { + var channel = new MessageChannel(); + var port = channel.port2; + channel.port1.onmessage = nextTickHandler; + + timerFunc = function timerFunc() { + port.postMessage(1); + }; + } else if (typeof Promise !== "undefined" && isNative(Promise)) { + /* istanbul ignore next */ + // use microtask in non-DOM environments, e.g. Weex + var p = Promise.resolve(); + + timerFunc = function timerFunc() { + p.then(nextTickHandler); + }; + } else { + // fallback to setTimeout + timerFunc = function timerFunc() { + setTimeout(nextTickHandler, 0); + }; + } + + return function queueNextTick(cb, ctx) { + var _resolve; + + callbacks.push(function () { + if (cb) { + try { + cb.call(ctx); + } catch (e) { + console.error(e); + } + } else if (_resolve) { + _resolve(ctx); } + }); - return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers); - } // Return a reactive-copy of the original object, where only the root level - - function readonly(target) { - return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers); - } // Return a reactive-copy of the original object, where only the root level - - function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers) { - if (!isObject(target)) { - { - console.warn("value cannot be made reactive: ".concat(String(target))); - } - return target; - } // target is already a Proxy, return it. - // exception: calling readonly() on a reactive object - - - if (target["__v_raw" - /* RAW */ - ] && !(isReadonly && target["__v_isReactive" - /* IS_REACTIVE */ - ])) { - return target; - } // target already has corresponding Proxy - - - var proxyMap = isReadonly ? readonlyMap : reactiveMap; - var existingProxy = proxyMap.get(target); - - if (existingProxy) { - return existingProxy; - } // only a whitelist of value types can be observed. + if (!pending) { + pending = true; + timerFunc(); + } // $flow-disable-line - var targetType = getTargetType(target); - - if (targetType === 0 - /* INVALID */ - ) { - return target; - } - - var proxy = new Proxy(target, targetType === 2 - /* COLLECTION */ - ? collectionHandlers : baseHandlers); - proxyMap.set(target, proxy); - return proxy; - } + if (!cb && typeof Promise !== "undefined") { + return new Promise(function (resolve) { + _resolve = resolve; + }); + } + }; + }(); + + var mixinInjection = {}; + function getMixins(type) { + return mixinInjection[type]; + } + function mixin(xtype, cls) { + mixinInjection[xtype] = _.cloneDeep(cls); + } + + var queue = []; + var activatedChildren = []; + var has = {}; + var waiting = false; + var flushing = false; + var index = 0; + + function resetSchedulerState() { + index = queue.length = activatedChildren.length = 0; + has = {}; + waiting = flushing = false; + } + + function flushSchedulerQueue() { + flushing = true; + var watcher; + var id; + var options; // Sort queue before flush. + // This ensures that: + // 1. Components are updated from parent to child. (because parent is always + // created before the child) + // 2. A component's user watchers are run before its render watcher (because + // user watchers are created before the render watcher) + // 3. If a component is destroyed during a parent component's watcher run, + // its watchers can be skipped. + + queue.sort(function (a, b) { + return a.id - b.id; + }); // do not cache length because more watchers might be pushed + // as we run existing watchers + + for (index = 0; index < queue.length; index++) { + watcher = queue[index].watcher; + options = queue[index].options; + id = watcher.id; + has[id] = null; + watcher(options); + } + + resetSchedulerState(); + } + + function queueWatcher(watcher, options) { + var id = watcher.id; + + if (has[id] == null) { + has[id] = true; + + if (!flushing) { + queue.push({ + watcher: watcher, + options: options + }); + } else { + // if already flushing, splice the watcher based on its id + // if already past its id, it will be run next immediately. + var i = queue.length - 1; - function isReactive(value) { - if (isReadonly(value)) { - return isReactive(value["__v_raw" - /* RAW */ - ]); + while (i > index && queue[i].watcher.id > watcher.id) { + i--; } - return !!(value && value["__v_isReactive" - /* IS_REACTIVE */ - ]); - } + queue.splice(i + 1, 0, { + watcher: watcher, + options: options + }); + } // queue the flush - function isReadonly(value) { - return !!(value && value["__v_isReadonly" - /* IS_READONLY */ - ]); - } - function toRaw(observed) { - return observed && toRaw(observed["__v_raw" - /* RAW */ - ]) || observed; + if (!waiting) { + waiting = true; + nextTick(flushSchedulerQueue); + } } + } - function isRef(r) { - return Boolean(r && r.__v_isRef === true); + function innerWatch(source, cb, options) { + if (!_.isFunction(cb)) { + console.warn("`watch(fn, options?)` signature has been moved to a separate API. " + "Use `watchEffect(fn, options?)` instead. `watch` now only " + "supports `watch(source, cb, options?) signature."); } - var ComputedRefImpl = /*#__PURE__*/function () { - function ComputedRefImpl(getter, _setter, isReadonly) { - var _this2 = this; + return doWatch(source, cb, options); + } + var INITIAL_WATCHER_VALUE = {}; + var objectToString = Object.prototype.toString; - _classCallCheck(this, ComputedRefImpl); + var toTypeString = function toTypeString(value) { + return objectToString.call(value); + }; - this._setter = _setter; - this._dirty = true; - this.__v_isRef = true; - this.effect = effect(getter, { - lazy: true, - scheduler: function scheduler() { - if (!_this2._dirty) { - _this2._dirty = true; - trigger(toRaw(_this2), "set" - /* SET */ - , "value"); - } - } - }); - this["__v_isReadonly" - /* IS_READONLY */ - ] = isReadonly; - } + var isMap = function isMap(val) { + return toTypeString(val) === "[object Map]"; + }; - _createClass(ComputedRefImpl, [{ - key: "value", - get: function get() { - if (this._dirty) { - this._value = this.effect(); - this._dirty = false; - } - - track(toRaw(this), "get" - /* GET */ - , "value"); - return this._value; - }, - set: function set(newValue) { - this._setter(newValue); - } - }]); + var isSet = function isSet(val) { + return toTypeString(val) === "[object Set]"; + }; - return ComputedRefImpl; - }(); + var hasChanged = function hasChanged(value, oldValue) { + return value !== oldValue && (value === value || oldValue === oldValue); + }; - function computed(getterOrOptions) { - var getter; - var setter; + var uid = 0; - if (isFunction(getterOrOptions)) { - getter = getterOrOptions; + function doWatch(source, cb, options, instance) { + options = options || {}; + var _options = options, + immediate = _options.immediate, + deep = _options.deep, + sync = _options.sync, + onTrack = _options.onTrack, + onTrigger = _options.onTrigger; - setter = function setter() { - console.warn("Write operation failed: computed value is readonly"); - }; - } else { - getter = getterOrOptions.get; - setter = getterOrOptions.set; - } + if (!cb) { + if (immediate !== undefined) { + console.warn("watch() \"immediate\" option is only respected when using the " + "watch(source, callback, options?) signature."); + } - return new ComputedRefImpl(getter, setter, isFunction(getterOrOptions) || !getterOrOptions.set); + if (deep !== undefined) { + console.warn("watch() \"deep\" option is only respected when using the " + "watch(source, callback, options?) signature."); + } } - function noop() {} - function isNative(Ctor) { - return typeof Ctor === "function" && /native code/.test(Ctor.toString()); - } - var isIE = function isIE() { - if (typeof navigator === "undefined") { - return false; - } - - return /(msie|trident)/i.test(navigator.userAgent.toLowerCase()); + var warnInvalidSource = function warnInvalidSource(s) { + console.warn("Invalid watch source: ", s, "A watch source can only be a getter/effect function, a ref, " + "a reactive object, or an array of these types."); }; - var getIEVersion = function getIEVersion() { - var version = 0; - if (typeof navigator === "undefined") { - return false; - } - - var agent = navigator.userAgent.toLowerCase(); - var v1 = agent.match(/(?:msie\s([\w.]+))/); - var v2 = agent.match(/(?:trident.*rv:([\w.]+))/); - - if (v1 && v2 && v1[1] && v2[1]) { - version = Math.max(v1[1] * 1, v2[1] * 1); - } else if (v1 && v1[1]) { - version = v1[1] * 1; - } else if (v2 && v2[1]) { - version = v2[1] * 1; - } else { - version = 0; - } - - return version; - }; - isIE() && getIEVersion() < 9; - var _toString = Object.prototype.toString; - function isPlainObject(obj) { - return _toString.call(obj) === "[object Object]"; - } - var bailRE = /[^\w.$]/; - function parsePath(path) { - if (bailRE.test(path)) { - return; - } - - var segments = path.split("."); - return function (obj) { - for (var i = 0; i < segments.length; i++) { - if (!obj) return; - obj = obj[segments[i]]; - } - - return obj; + var getter; + var forceTrigger = false; + + if (isRef(source)) { + getter = function getter() { + return source.value; + }; + + forceTrigger = !!source._shallow; + } else if (isReactive(source)) { + getter = function getter() { + return source; + }; + + deep = true; + } else if (_.isArray(source)) { + getter = function getter() { + return source.map(function (s) { + if (isRef(s)) { + return s.value; + } else if (isReactive(s)) { + return traverse(s); + } else if (_.isFunction(s)) { + return s.call(instance); + } else { + warnInvalidSource(s); + } + }); + }; + } else if (_.isFunction(source)) { + if (cb) { + // getter with cb + getter = function getter() { + return source.call(instance); }; - } - var nextTick = function () { - var callbacks = []; - var pending = false; - var timerFunc; - - function nextTickHandler() { - pending = false; - var copies = callbacks.slice(0); - callbacks.length = 0; - - for (var i = 0; i < copies.length; i++) { - copies[i](); - } - } // An asynchronous deferring mechanism. - // In pre 2.4, we used to use microtasks (Promise/MutationObserver) - // but microtasks actually has too high a priority and fires in between - // supposedly sequential events (e.g. #4521, #6690) or even between - // bubbling of the same event (#6566). Technically setImmediate should be - // the ideal choice, but it's not available everywhere; and the only polyfill - // that consistently queues the callback after all DOM events triggered in the - // same loop is by using MessageChannel. - - /* istanbul ignore if */ - - - if (typeof setImmediate !== "undefined" && isNative(setImmediate)) { - timerFunc = function timerFunc() { - setImmediate(nextTickHandler); - }; - } else if (typeof MessageChannel !== "undefined" && (isNative(MessageChannel) || // PhantomJS - MessageChannel.toString() === "[object MessageChannelConstructor]")) { - var channel = new MessageChannel(); - var port = channel.port2; - channel.port1.onmessage = nextTickHandler; - - timerFunc = function timerFunc() { - port.postMessage(1); - }; - } else if (typeof Promise !== "undefined" && isNative(Promise)) { - /* istanbul ignore next */ - // use microtask in non-DOM environments, e.g. Weex - var p = Promise.resolve(); - - timerFunc = function timerFunc() { - p.then(nextTickHandler); - }; - } else { - // fallback to setTimeout - timerFunc = function timerFunc() { - setTimeout(nextTickHandler, 0); - }; - } - - return function queueNextTick(cb, ctx) { - var _resolve; - - callbacks.push(function () { - if (cb) { - try { - cb.call(ctx); - } catch (e) { - console.error(e); - } - } else if (_resolve) { - _resolve(ctx); - } - }); - - if (!pending) { - pending = true; - timerFunc(); - } // $flow-disable-line + } else { + // no cb -> simple effect + getter = function getter() { + if (instance && instance.isUnmounted) { + return; + } + if (cleanup) { + cleanup(); + } - if (!cb && typeof Promise !== "undefined") { - return new Promise(function (resolve) { - _resolve = resolve; - }); - } + return source.call(instance, onInvalidate); }; - }(); - - var mixinInjection = {}; - function getMixins(type) { - return mixinInjection[type]; - } - function mixin(xtype, cls) { - mixinInjection[xtype] = _.cloneDeep(cls); - } - - var queue = []; - var activatedChildren = []; - var has = {}; - var waiting = false; - var flushing = false; - var index = 0; - - function resetSchedulerState() { - index = queue.length = activatedChildren.length = 0; - has = {}; - waiting = flushing = false; - } - - function flushSchedulerQueue() { - flushing = true; - var watcher; - var id; - var options; // Sort queue before flush. - // This ensures that: - // 1. Components are updated from parent to child. (because parent is always - // created before the child) - // 2. A component's user watchers are run before its render watcher (because - // user watchers are created before the render watcher) - // 3. If a component is destroyed during a parent component's watcher run, - // its watchers can be skipped. - - queue.sort(function (a, b) { - return a.id - b.id; - }); // do not cache length because more watchers might be pushed - // as we run existing watchers - - for (index = 0; index < queue.length; index++) { - watcher = queue[index].watcher; - options = queue[index].options; - id = watcher.id; - has[id] = null; - watcher(options); - } + } + } else { + getter = function getter() {}; - resetSchedulerState(); + warnInvalidSource(source); } - function queueWatcher(watcher, options) { - var id = watcher.id; - - if (has[id] == null) { - has[id] = true; - - if (!flushing) { - queue.push({ - watcher: watcher, - options: options - }); - } else { - // if already flushing, splice the watcher based on its id - // if already past its id, it will be run next immediately. - var i = queue.length - 1; - - while (i > index && queue[i].watcher.id > watcher.id) { - i--; - } - - queue.splice(i + 1, 0, { - watcher: watcher, - options: options - }); - } // queue the flush + if (cb && deep) { + var baseGetter = getter; - - if (!waiting) { - waiting = true; - nextTick(flushSchedulerQueue); - } - } + getter = function getter() { + return traverse(baseGetter()); + }; } - function innerWatch(source, cb, options) { - if (!_.isFunction(cb)) { - console.warn("`watch(fn, options?)` signature has been moved to a separate API. " + "Use `watchEffect(fn, options?)` instead. `watch` now only " + "supports `watch(source, cb, options?) signature."); - } + var cleanup; - return doWatch(source, cb, options); - } - var INITIAL_WATCHER_VALUE = {}; - var objectToString = Object.prototype.toString; - - var toTypeString = function toTypeString(value) { - return objectToString.call(value); + var onInvalidate = function onInvalidate(fn) { + cleanup = runner.options.onStop = function () { + fn.call(instance); + }; }; - var isMap = function isMap(val) { - return toTypeString(val) === "[object Map]"; + var oldValue = _.isArray(source) ? [] : INITIAL_WATCHER_VALUE; + + var job = function job() { + // 这里去掉的原因是,新增属性没有生效也会触发变化监听 + // if (!runner.active) { + // return; + // } + if (cb) { + // watch(source, cb) + var newValue = runner(); + + if (deep || forceTrigger || hasChanged(newValue, oldValue)) { + // cleanup before running cb again + if (cleanup) { + cleanup(); + } + + cb.apply(instance, [newValue, // pass undefined as the old value when it's changed for the first time + oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, onInvalidate]); + oldValue = newValue; + } + } else { + // watchEffect + runner(); + } + }; // important: mark the job as a watcher callback so that scheduler knows + // it is allowed to self-trigger (#1727) + + + job.allowRecurse = !!cb; + job.id = ++uid; + var scheduler; + + if (sync === true) { + scheduler = job; + } else { + scheduler = function scheduler() { + return queueWatcher(job); + }; + } + + var runner = effect(function () { + try { + return getter(); + } catch (e) {// 吞掉异常 + } + }, { + lazy: true, + onTrack: onTrack, + onTrigger: onTrigger, + scheduler: scheduler + }); // initial run + + if (cb) { + if (immediate) { + job(); + } else { + oldValue = runner(); + } + } else { + runner(); + } + + return function () { + stop(runner); }; + } - var isSet = function isSet(val) { - return toTypeString(val) === "[object Set]"; - }; + function traverse(value) { + var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set(); - var hasChanged = function hasChanged(value, oldValue) { - return value !== oldValue && (value === value || oldValue === oldValue); - }; + if (!_.isObject(value) || seen.has(value)) { + return value; + } - var uid = 0; + seen.add(value); - function doWatch(source, cb, options, instance) { - options = options || {}; - var _options = options, - immediate = _options.immediate, - deep = _options.deep, - sync = _options.sync, - onTrack = _options.onTrack, - onTrigger = _options.onTrigger; + if (isRef(value)) { + traverse(value.value, seen); + } else if (_.isArray(value)) { + for (var i = 0; i < value.length; i++) { + traverse(value[i], seen); + } + } else if (isSet(value) || isMap(value)) { + value.forEach(function (v) { + traverse(v, seen); + }); + } else { + for (var key in value) { + traverse(value[key], seen); + } + } - if (!cb) { - if (immediate !== undefined) { - console.warn("watch() \"immediate\" option is only respected when using the " + "watch(source, callback, options?) signature."); - } + return value; + } - if (deep !== undefined) { - console.warn("watch() \"deep\" option is only respected when using the " + "watch(source, callback, options?) signature."); - } - } + var falsy; + var operators = { + "||": falsy, + "&&": falsy, + "(": falsy, + ")": falsy + }; - var warnInvalidSource = function warnInvalidSource(s) { - console.warn("Invalid watch source: ", s, "A watch source can only be a getter/effect function, a ref, " + "a reactive object, or an array of these types."); - }; + function runBinaryFunction(binarys) { + var expr = ""; - var getter; - var forceTrigger = false; + for (var i = 0, len = binarys.length; i < len; i++) { + if (_.isBoolean(binarys[i]) || _.has(operators, binarys[i])) { + expr += binarys[i]; + } else { + expr += "false"; + } + } - if (isRef(source)) { - getter = function getter() { - return source.value; - }; + return new Function("return " + expr)(); + } - forceTrigger = !!source._shallow; - } else if (isReactive(source)) { - getter = function getter() { - return source; - }; + function watchExp(model, getter) { + var result = getter.call(model, model); - deep = true; - } else if (_.isArray(source)) { - getter = function getter() { - return source.map(function (s) { - if (isRef(s)) { - return s.value; - } else if (isReactive(s)) { - return traverse(s); - } else if (_.isFunction(s)) { - return s.call(instance); - } else { - warnInvalidSource(s); - } - }); - }; - } else if (_.isFunction(source)) { - if (cb) { - // getter with cb - getter = function getter() { - return source.call(instance); - }; - } else { - // no cb -> simple effect - getter = function getter() { - if (instance && instance.isUnmounted) { - return; - } - - if (cleanup) { - cleanup(); - } - - return source.call(instance, onInvalidate); - }; - } - } else { - getter = function getter() {}; + if (_.isArray(result)) { + return result.concat(); + } - warnInvalidSource(source); - } + return result; + } - if (cb && deep) { - var baseGetter = getter; + function watch(model, expOrFn, cb, options) { + if (isPlainObject(cb)) { + options = cb; + cb = cb.handler; + } - getter = function getter() { - return traverse(baseGetter()); - }; - } + if (typeof cb === "string") { + cb = model[cb]; + } - var cleanup; + options = options || {}; + options.user = true; + var exps; - var onInvalidate = function onInvalidate(fn) { - cleanup = runner.options.onStop = function () { - fn.call(instance); - }; - }; + if (_.isFunction(expOrFn)) { + var watcher = innerWatch(expOrFn, cb, options); + return function unwatchFn() { + watcher(); + }; + } - var oldValue = _.isArray(source) ? [] : INITIAL_WATCHER_VALUE; + if (!(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { + var paths = expOrFn.split("."); + var prePaths = paths.slice(0, paths.length - 1); + var preGetter = parsePath(prePaths.join(".")); + var v = preGetter.call(model, model); + var getter = parsePath(paths[paths.length - 1]); - var job = function job() { - if (!runner.active) { - return; - } + var _watcher = innerWatch(function () { + return watchExp(v, getter); + }, cb, options); - if (cb) { - // watch(source, cb) - var newValue = runner(); + return function unwatchFn() { + _watcher(); + }; + } - if (deep || forceTrigger || hasChanged(newValue, oldValue)) { - // cleanup before running cb again - if (cleanup) { - cleanup(); - } + var watchers = []; + var fns = exps.slice(); + var complete = false, + running = false; - cb.apply(instance, [newValue, // pass undefined as the old value when it's changed for the first time - oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue, onInvalidate]); - oldValue = newValue; - } - } else { - // watchEffect - runner(); - } - }; // important: mark the job as a watcher callback so that scheduler knows - // it is allowed to self-trigger (#1727) + var callback = function callback(index, newValue, oldValue, attrs) { + if (complete === true) { + return; + } + fns[index] = true; - job.allowRecurse = !!cb; - job.id = ++uid; - var scheduler; + if (runBinaryFunction(fns)) { + complete = true; + cb(newValue, oldValue, attrs); + } - if (sync === true) { - scheduler = job; - } else { - scheduler = function scheduler() { - return queueWatcher(job); - }; + if (options && options.sync) { + complete = false; + running = false; + fns = exps.slice(); + } else { + if (!running) { + running = true; + nextTick(function () { + complete = false; + running = false; + fns = exps.slice(); + }); } + } + }; - var runner = effect(getter, { - lazy: true, - onTrack: onTrack, - onTrigger: onTrigger, - scheduler: scheduler - }); // initial run - - if (cb) { - if (immediate) { - job(); + _.each(exps, function (exp, i) { + if (_.has(operators, exp)) { + return; + } + + if (exp.indexOf("*") >= 0) { + // eslint-disable-next-line no-inner-declarations + var travers = function travers(root, deps, parent, key, res) { + if (deps.length === _paths.length) { + root !== undefined && res.push({ + parent: parent, + k: key + }); + return; + } + + if (root) { + if (_paths[deps.length] === "*") { + // 遍历所有节点 + for (var k in root) { + travers(root[k], deps.concat([k]), root, k, res); + } } else { - oldValue = runner(); + var nextKey = _paths[deps.length]; + travers(root[nextKey], deps.concat([nextKey]), root, nextKey, res); } - } else { - runner(); - } - - return function () { - stop(runner); + } }; - } - - function traverse(value) { - var seen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Set(); - if (!_.isObject(value) || seen.has(value)) { - return value; - } + //a.**形式 + if (/^[1-9a-zA-Z.]+\*\*$/.test(exp) || exp === "**") { + exp = exp.replace(".**", ""); - seen.add(value); + var _paths2 = exp.split("."); - if (isRef(value)) { - traverse(value.value, seen); - } else if (_.isArray(value)) { - for (var i = 0; i < value.length; i++) { - traverse(value[i], seen); - } - } else if (isSet(value) || isMap(value)) { - value.forEach(function (v) { - traverse(v, seen); - }); - } else { - for (var key in value) { - traverse(value[key], seen); - } - } + var _prePaths2 = _paths2.slice(0, _paths2.length - 1); - return value; - } + var _preGetter = parsePath(_prePaths2.join(".")); - var falsy; - var operators = { - "||": falsy, - "&&": falsy, - "(": falsy, - ")": falsy - }; + var _v2 = _preGetter.call(model, model); - function runBinaryFunction(binarys) { - var expr = ""; + var _getter = exp === "**" ? function (m) { + return m; + } : parsePath(_paths2[_paths2.length - 1]); - for (var i = 0, len = binarys.length; i < len; i++) { - if (_.isBoolean(binarys[i]) || _.has(operators, binarys[i])) { - expr += binarys[i]; - } else { - expr += "false"; - } + watchers.push(innerWatch(function () { + return watchExp(_v2, _getter); + }, function (newValue, oldValue) { + callback(i, newValue, oldValue, _.extend({ + index: i + })); + }, _.extend({ + deep: true + }, options))); + return; } - return new Function("return " + expr)(); - } + if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { + throw new Error("not support"); + } //含有*的情况,如a.*,如*.a,*.*.a,a.*.a + //先获取到能获取到的对象 - function watchExp(model, exp) { - var getter = parsePath(exp); - var result = getter.call(model, model); - if (_.isArray(result)) { - return result.concat(); - } + var _paths = exp.split("."); - return result; - } + var _prePaths = []; - function watch(model, expOrFn, cb, options) { - if (isPlainObject(cb)) { - options = cb; - cb = cb.handler; - } + for (var _i = 0, len = _paths.length; _i < len; _i++) { + if (_paths[_i] === "*") { + break; + } - if (typeof cb === "string") { - cb = model[cb]; + _prePaths[_i] = _paths[_i]; } - options = options || {}; - options.user = true; - var exps; + var _v; - if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { - var watcher = innerWatch(_.isFunction(expOrFn) ? expOrFn : function () { - return watchExp(model, expOrFn); - }, cb, options); - return function unwatchFn() { - watcher(); - }; - } + if (_prePaths.length > 0) { + var _getter2 = parsePath(_prePaths.join(".")); - var watchers = []; - var fns = exps.slice(); - var complete = false, - running = false; + _v = _getter2.call(model, model); + } else { + _v = model; + } - var callback = function callback(index, newValue, oldValue, attrs) { - if (complete === true) { - return; - } + _paths = _paths.slice(_prePaths.length); + var changes = []; + watchers.push(innerWatch(function () { + var routes = []; + travers(_v, [], _v, null, routes); - fns[index] = true; + for (var _i2 = 0, _len = routes.length; _i2 < _len; _i2++) { + var _routes$_i = routes[_i2], + parent = _routes$_i.parent, + k = _routes$_i.k; - if (runBinaryFunction(fns)) { - complete = true; - cb(newValue, oldValue, attrs); - } + for (var j = 0, l = changes.length; j < l; j++) { + var _changes$j = changes[j], + target = _changes$j.target, + key = _changes$j.key; - if (options && options.sync) { - complete = false; - running = false; - fns = exps.slice(); - } else { - if (!running) { - running = true; - nextTick(function () { - complete = false; - running = false; - fns = exps.slice(); - }); - } - } - }; - - _.each(exps, function (exp, i) { - if (_.has(operators, exp)) { - return; - } //a.**形式 - - - if (/^[1-9a-zA-Z.]+\*\*$/.test(exp) || exp === "**") { - exp = exp.replace(".**", ""); - var getter = exp === "**" ? function (m) { - return m; - } : parsePath(exp); - var v = getter.call(model, model); - watchers.push(innerWatch(v, function (newValue, oldValue) { - callback(i, newValue, oldValue, _.extend({ - index: i - })); - })); - return; - } - - if (/^(\*\*\.)+[1-9a-zA-Z]+(\.\*\*$)/.test(exp)) { - throw new Error("not support"); - } //含有*的情况,如a.*,如*.a,*.*.a,a.*.a - - - if (/\*/.test(exp)) { - // eslint-disable-next-line no-inner-declarations - var travers = function travers(root, deps, parent, key, res) { - if (deps.length === paths.length) { - root !== undefined && res.push({ - parent: parent, - k: key - }); - return; - } - - if (root) { - if (paths[deps.length] === "*") { - // 遍历所有节点 - for (var k in root) { - travers(root[k], deps.concat([k]), root, k, res); - } - } else { - var nextKey = paths[deps.length]; - travers(root[nextKey], deps.concat([nextKey]), root, nextKey, res); - } - } - }; - - //先获取到能获取到的对象 - var paths = exp.split("."); - var prePaths = []; - - for (var _i = 0, len = paths.length; _i < len; _i++) { - if (paths[_i] === "*") { - break; - } - - prePaths[_i] = paths[_i]; - } - - var _v; - - if (prePaths.length > 0) { - var _getter = parsePath(prePaths.join(".")); - - _v = _getter.call(model, model); - } else { - _v = model; - } - - paths = paths.slice(prePaths.length); - var changes = []; - watchers.push(innerWatch(function () { - var routes = []; - travers(_v, [], _v, null, routes); - - for (var _i2 = 0, _len = routes.length; _i2 < _len; _i2++) { - var _routes$_i = routes[_i2], - parent = _routes$_i.parent, - k = _routes$_i.k; - - for (var j = 0, l = changes.length; j < l; j++) { - var _changes$j = changes[j], - target = _changes$j.target, - key = _changes$j.key; - - if (target === toRaw(parent) && key === k) { - return true; - } - } - } - }, function (newValue) { - changes = []; - - if (newValue === true) { - callback(i, undefined, undefined, _.extend({ - index: i - })); - } - }, { - deep: true, - onTrigger: function onTrigger(_ref) { - var target = _ref.target, - key = _ref.key; - changes.push({ - target: target, - key: key - }); - } - })); - return; + if (target === toRaw(parent) && key === k) { + return true; + } } + } + }, function (newValue) { + changes = []; - watchers.push(innerWatch(function () { - return watchExp(model, exp); - }, function (newValue, oldValue) { - callback(i, newValue, oldValue, _.extend({ - index: i - })); + if (newValue === true) { + callback(i, undefined, undefined, _.extend({ + index: i })); - }); + } + }, BI.extend({}, options, { + deep: true, + onTrigger: function onTrigger(_ref) { + var target = _ref.target, + key = _ref.key; + changes.push({ + target: target, + key: key + }); + } + }))); + return; + } + + var getter = parsePath(exp); + watchers.push(innerWatch(function () { + return watchExp(model, getter); + }, function (newValue, oldValue) { + callback(i, newValue, oldValue, _.extend({ + index: i + })); + }, options)); + }); - return watchers; - } + return watchers; + } - var REACTIVE = true; + var REACTIVE = true; - function initState(vm, state) { - if (state) { - vm.$$state = REACTIVE ? reactive(state) : state; - } + function initState(vm, state) { + if (state) { + vm.$$state = REACTIVE ? reactive(state) : state; } + } - function initComputed(vm, c) { - var $$computed = vm.$$computed = {}; + function initComputed(vm, c) { + var $$computed = vm.$$computed = {}; - for (var key in c) { - $$computed[key] = computed(_.bind(c[key], vm)); - } + for (var key in c) { + $$computed[key] = computed(_.bind(c[key], vm)); } + } - function initWatch(vm, watch) { - vm._watchers || (vm._watchers = []); + function initWatch(vm, watch) { + vm._watchers || (vm._watchers = []); - for (var key in watch) { - var handler = watch[key]; + for (var key in watch) { + var handler = watch[key]; - if (_.isArray(handler)) { - for (var i = 0; i < handler.length; i++) { - vm._watchers.push(createWatcher(vm, key, handler[i])); - } - } else { - vm._watchers.push(createWatcher(vm, key, handler)); - } + if (_.isArray(handler)) { + for (var i = 0; i < handler.length; i++) { + vm._watchers.push(createWatcher(vm, key, handler[i])); } + } else { + vm._watchers.push(createWatcher(vm, key, handler)); + } } + } - function createWatcher(vm, keyOrFn, cb, options) { - if (isPlainObject(cb)) { - options = cb; - cb = cb.handler; - } - - if (typeof cb === "string") { - cb = vm[cb]; - } - - return watch(vm.model, keyOrFn, _.bind(cb, vm), options); + function createWatcher(vm, keyOrFn, cb, options) { + if (isPlainObject(cb)) { + options = cb; + cb = cb.handler; } - function initMethods(vm, methods) { - for (var key in methods) { - vm[key] = methods[key] == null ? noop : _.bind(methods[key], vm); - } + if (typeof cb === "string") { + cb = vm[cb]; } - function initMixins(vm, mixins) { - mixins = (mixins || []).slice(0); + return watch(vm.model, keyOrFn, _.bind(cb, vm), options); + } - _.each(mixins.reverse(), function (mixinType) { - var mixin = getMixins(mixinType); - - for (var key in mixin) { - if (typeof mixin[key] !== "function") continue; - if (_.has(vm, key)) continue; - vm[key] = _.bind(mixin[key], vm); - } - }); + function initMethods(vm, methods) { + for (var key in methods) { + vm[key] = methods[key] == null ? noop : _.bind(methods[key], vm); } + } - function defineProps(vm) { - vm.model = new Proxy({}, { - get: function get(target, key) { - if (vm.$$computed && key in vm.$$computed) { - try { - return vm.$$computed[key].value; - } catch (e) {// 吞掉异常 - } - - return; - } + function initMixins(vm, mixins) { + mixins = (mixins || []).slice(0); - if (vm.$$state && key in vm.$$state) { - return vm.$$state[key]; - } + _.each(mixins.reverse(), function (mixinType) { + var mixin = getMixins(mixinType); - var p = vm._parent; - - while (p) { - if (p.$$context && key in p.$$context) { - return p.$$context[key]; - } - - p = p._parent; - } - }, - set: function set(target, key, value) { - if (vm.$$state && key in vm.$$state) { - vm.$$state[key] = value; - return true; - } + for (var key in mixin) { + if (typeof mixin[key] !== "function") continue; + if (_.has(vm, key)) continue; + vm[key] = _.bind(mixin[key], vm); + } + }); + } - var p = vm._parent; + function defineProps(vm) { + vm.model = new Proxy({}, { + get: function get(target, key) { + if (vm.$$computed && key in vm.$$computed) { + try { + return vm.$$computed[key].value; + } catch (e) {// 吞掉异常 + } - while (p) { - if (p.$$context && key in p.$$context) { - p.$$context[key] = value; - return true; - } + return; + } - p = p._parent; - } + if (vm.$$state && key in vm.$$state) { + return vm.$$state[key]; + } - return true; - } - }); - } + var p = vm._parent; - function defineContext(vm, keys) { - var props = {}; - - var _loop = function _loop(i, len) { - var key = keys[i]; - props[key] = { - enumerable: true, - configurable: true, - get: function get() { - return vm.model[key]; - }, - set: function set(val) { - return vm.model[key] = val; - } - }; - }; + while (p) { + if (p.$$context && key in p.$$context) { + return p.$$context[key]; + } - for (var i = 0, len = keys.length; i < len; i++) { - _loop(i); + p = p._parent; + } + }, + set: function set(target, key, value) { + if (vm.$$state && key in vm.$$state) { + vm.$$state[key] = value; + return true; } - vm.$$context = Object.defineProperties({}, props); - } - - function getInjectValue(vm, key) { var p = vm._parent; while (p) { - if (p.$$context && key in p.$$context) { - return p.$$context[key]; - } + if (p.$$context && key in p.$$context) { + p.$$context[key] = value; + return true; + } + + p = p._parent; + } - p = p._parent; + return true; + } + }); + } + + function defineContext(vm, keys) { + var props = {}; + + var _loop = function _loop(i, len) { + var key = keys[i]; + props[key] = { + enumerable: true, + configurable: true, + get: function get() { + return vm.model[key]; + }, + set: function set(val) { + return vm.model[key] = val; } + }; + }; + + for (var i = 0, len = keys.length; i < len; i++) { + _loop(i); } - function getInjectValues(vm) { - var inject = vm.inject || []; - var result = {}; + vm.$$context = Object.defineProperties({}, props); + } - _.each(inject, function (key) { - result[key] = getInjectValue(vm, key); - }); + function getInjectValue(vm, key) { + var p = vm._parent; + + while (p) { + if (p.$$context && key in p.$$context) { + return p.$$context[key]; + } - return result; + p = p._parent; } + } - var Model = /*#__PURE__*/function () { - function Model() { - _classCallCheck(this, Model); - } + function getInjectValues(vm) { + var inject = vm.inject || []; + var result = {}; - _createClass(Model, [{ - key: "_constructor", - value: function _constructor(options, destroyHandler) { - this.options = options || {}; - this._parent = Model.target; - var state = _.isFunction(this.state) ? this.state() : this.state; - var computed = this.computed; - var context = this.context; - var inject = this.inject; - var childContext = this.childContext; - var watch = this.watch; - var actions = this.actions; - - _.keys(state).concat(_.keys(computed)).concat(inject || []).concat(context || []); - - var mixins = this.mixins; - defineProps(this); - childContext && defineContext(this, childContext); - initMixins(this, mixins); - this.init(); - initState(this, _.extend(getInjectValues(this), state)); - initComputed(this, computed); - REACTIVE && initWatch(this, watch); - initMethods(this, actions); - this.created && this.created(); - this._destroyHandler = destroyHandler; - } - }, { - key: "_init", - value: function _init() {} - }, { - key: "init", - value: function init() { - this._init(); - } - }, { - key: "destroy", - value: function destroy() { - _.each(this._watchers, function (unwatches) { - unwatches = _.isArray(unwatches) ? unwatches : [unwatches]; - - _.each(unwatches, function (unwatch) { - unwatch(); - }); - }); - - this._watchers && (this._watchers = []); - this.destroyed && this.destroyed(); - this.$$computed = null; - this.$$state = null; - this._destroyHandler && this._destroyHandler(); - } - }]); - - return Model; - }(); - function set(target, key, val) { - if (_.isArray(target)) { - target.length = Math.max(target.length, key); - target.splice(key, 1, val); - return val; - } + _.each(inject, function (key) { + result[key] = getInjectValue(vm, key); + }); - target[key] = val; - } - function del(target, key) { - if (_.isArray(target)) { - target.splice(key, 1); - return; - } + return result; + } + + var Model = /*#__PURE__*/function () { + function Model() { + _classCallCheck(this, Model); + } + + _createClass(Model, [{ + key: "_constructor", + value: function _constructor(options, destroyHandler) { + this.options = options || {}; + this._parent = Model.target; + var state = _.isFunction(this.state) ? this.state() : this.state; + var computed = this.computed; + var context = this.context; + var inject = this.inject; + var childContext = this.childContext; + var watch = this.watch; + var actions = this.actions; + + _.keys(state).concat(_.keys(computed)).concat(inject || []).concat(context || []); + + var mixins = this.mixins; + defineProps(this); + childContext && defineContext(this, childContext); + initMixins(this, mixins); + this.init(); + initState(this, _.extend(getInjectValues(this), state)); + initComputed(this, computed); + REACTIVE && initWatch(this, watch); + initMethods(this, actions); + this.created && this.created(); + this._destroyHandler = destroyHandler; + } + }, { + key: "_init", + value: function _init() {} + }, { + key: "init", + value: function init() { + this._init(); + } + }, { + key: "destroy", + value: function destroy() { + _.each(this._watchers, function (unwatches) { + unwatches = _.isArray(unwatches) ? unwatches : [unwatches]; + + _.each(unwatches, function (unwatch) { + unwatch(); + }); + }); - if (!_.has(target, key)) { - return; - } + this._watchers && (this._watchers = []); + this.destroyed && this.destroyed(); + this.$$computed = null; + this.$$state = null; + this._destroyHandler && this._destroyHandler(); + } + }]); - delete target[key]; + return Model; + }(); + function set(target, key, val) { + if (_.isArray(target)) { + target.length = Math.max(target.length, key); + target.splice(key, 1, val); + return val; } - function define(model) { - return REACTIVE ? reactive(model) : model; + + target[key] = val; + } + function del(target, key) { + if (_.isArray(target)) { + target.splice(key, 1); + return; } - function config(options) { - options || (options = {}); - if ("reactive" in options) { - REACTIVE = options.reactive; - } + if (!_.has(target, key)) { + return; } - function toJSON(model) { - var result; + delete target[key]; + } + function define(model) { + return REACTIVE ? reactive(model) : model; + } + function config(options) { + options || (options = {}); + + if ("reactive" in options) { + REACTIVE = options.reactive; + } + } - if (_.isArray(model)) { - result = []; + function toJSON(model) { + var result; - for (var i = 0, len = model.length; i < len; i++) { - result[i] = toJSON(model[i]); - } - } else if (model && isPlainObject(model)) { - result = {}; + if (_.isArray(model)) { + result = []; - for (var key in model) { - result[key] = toJSON(model[key]); - } - } else { - result = model; - } + for (var i = 0, len = model.length; i < len; i++) { + result[i] = toJSON(model[i]); + } + } else if (model && isPlainObject(model)) { + result = {}; - return result; + for (var key in model) { + result[key] = toJSON(model[key]); + } + } else { + result = model; } - var version = "3.0"; + return result; + } + + var version = "3.0"; - exports.Model = Model; - exports.config = config; - exports.define = define; - exports.del = del; - exports.mixin = mixin; - exports.set = set; - exports.toJSON = toJSON; - exports.version = version; - exports.watch = watch; + exports.Model = Model; + exports.config = config; + exports.define = define; + exports.del = del; + exports.mixin = mixin; + exports.set = set; + exports.toJSON = toJSON; + exports.version = version; + exports.watch = watch; - Object.defineProperty(exports, '__esModule', { value: true }); + Object.defineProperty(exports, '__esModule', { value: true }); }))); diff --git a/src/less/lib/background.less b/src/less/lib/background.less index 1f291a5fe..a331a88da 100644 --- a/src/less/lib/background.less +++ b/src/less/lib/background.less @@ -8,7 +8,3 @@ @background-trans-color-disabled: "background/trans_disable.png"; @background-auto-color-square-normal: "icon/auto_square_normal.png"; @background-auto-color-no-square-normal: "icon/auto_no_square_normal.png"; - -@background-farbtastic-wheel:"background/wheel.png"; -@background-farbtastic-overlay:"background/mask.png"; -@background-farbtastic-marker:"background/marker.png";