1 | var niceErrors = {
|
2 | 0: "Invalid value for configuration 'enforceActions', expected 'never', 'always' or 'observed'",
|
3 | 1: function _(annotationType, key) {
|
4 | return "Cannot apply '" + annotationType + "' to '" + key.toString() + "': Field not found.";
|
5 | },
|
6 | |
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | 5: "'keys()' can only be used on observable objects, arrays, sets and maps",
|
18 | 6: "'values()' can only be used on observable objects, arrays, sets and maps",
|
19 | 7: "'entries()' can only be used on observable objects, arrays and maps",
|
20 | 8: "'set()' can only be used on observable objects, arrays and maps",
|
21 | 9: "'remove()' can only be used on observable objects, arrays and maps",
|
22 | 10: "'has()' can only be used on observable objects, arrays and maps",
|
23 | 11: "'get()' can only be used on observable objects, arrays and maps",
|
24 | 12: "Invalid annotation",
|
25 | 13: "Dynamic observable objects cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
26 | 14: "Intercept handlers should return nothing or a change object",
|
27 | 15: "Observable arrays cannot be frozen. If you're passing observables to 3rd party component/function that calls Object.freeze, pass copy instead: toJS(observable)",
|
28 | 16: "Modification exception: the internal structure of an observable array was changed.",
|
29 | 17: function _(index, length) {
|
30 | return "[mobx.array] Index out of bounds, " + index + " is larger than " + length;
|
31 | },
|
32 | 18: "mobx.map requires Map polyfill for the current browser. Check babel-polyfill or core-js/es6/map.js",
|
33 | 19: function _(other) {
|
34 | return "Cannot initialize from classes that inherit from Map: " + other.constructor.name;
|
35 | },
|
36 | 20: function _(other) {
|
37 | return "Cannot initialize map from " + other;
|
38 | },
|
39 | 21: function _(dataStructure) {
|
40 | return "Cannot convert to map from '" + dataStructure + "'";
|
41 | },
|
42 | 22: "mobx.set requires Set polyfill for the current browser. Check babel-polyfill or core-js/es6/set.js",
|
43 | 23: "It is not possible to get index atoms from arrays",
|
44 | 24: function _(thing) {
|
45 | return "Cannot obtain administration from " + thing;
|
46 | },
|
47 | 25: function _(property, name) {
|
48 | return "the entry '" + property + "' does not exist in the observable map '" + name + "'";
|
49 | },
|
50 | 26: "please specify a property",
|
51 | 27: function _(property, name) {
|
52 | return "no observable property '" + property.toString() + "' found on the observable object '" + name + "'";
|
53 | },
|
54 | 28: function _(thing) {
|
55 | return "Cannot obtain atom from " + thing;
|
56 | },
|
57 | 29: "Expecting some object",
|
58 | 30: "invalid action stack. did you forget to finish an action?",
|
59 | 31: "missing option for computed: get",
|
60 | 32: function _(name, derivation) {
|
61 | return "Cycle detected in computation " + name + ": " + derivation;
|
62 | },
|
63 | 33: function _(name) {
|
64 | return "The setter of computed value '" + name + "' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?";
|
65 | },
|
66 | 34: function _(name) {
|
67 | return "[ComputedValue '" + name + "'] It is not possible to assign a new value to a computed value.";
|
68 | },
|
69 | 35: "There are multiple, different versions of MobX active. Make sure MobX is loaded only once or use `configure({ isolateGlobalState: true })`",
|
70 | 36: "isolateGlobalState should be called before MobX is running any reactions",
|
71 | 37: function _(method) {
|
72 | return "[mobx] `observableArray." + method + "()` mutates the array in-place, which is not allowed inside a derivation. Use `array.slice()." + method + "()` instead";
|
73 | },
|
74 | 38: "'ownKeys()' can only be used on observable objects",
|
75 | 39: "'defineProperty()' can only be used on observable objects"
|
76 | };
|
77 | var errors = process.env.NODE_ENV !== "production" ? niceErrors : {};
|
78 | function die(error) {
|
79 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
80 | args[_key - 1] = arguments[_key];
|
81 | }
|
82 | if (process.env.NODE_ENV !== "production") {
|
83 | var e = typeof error === "string" ? error : errors[error];
|
84 | if (typeof e === "function") e = e.apply(null, args);
|
85 | throw new Error("[MobX] " + e);
|
86 | }
|
87 | throw new Error(typeof error === "number" ? "[MobX] minified error nr: " + error + (args.length ? " " + args.map(String).join(",") : "") + ". Find the full error at: https://github.com/mobxjs/mobx/blob/main/packages/mobx/src/errors.ts" : "[MobX] " + error);
|
88 | }
|
89 |
|
90 | var mockGlobal = {};
|
91 | function getGlobal() {
|
92 | if (typeof globalThis !== "undefined") {
|
93 | return globalThis;
|
94 | }
|
95 | if (typeof window !== "undefined") {
|
96 | return window;
|
97 | }
|
98 | if (typeof global !== "undefined") {
|
99 | return global;
|
100 | }
|
101 | if (typeof self !== "undefined") {
|
102 | return self;
|
103 | }
|
104 | return mockGlobal;
|
105 | }
|
106 |
|
107 |
|
108 | var assign = Object.assign;
|
109 | var getDescriptor = Object.getOwnPropertyDescriptor;
|
110 | var defineProperty = Object.defineProperty;
|
111 | var objectPrototype = Object.prototype;
|
112 | var EMPTY_ARRAY = [];
|
113 | Object.freeze(EMPTY_ARRAY);
|
114 | var EMPTY_OBJECT = {};
|
115 | Object.freeze(EMPTY_OBJECT);
|
116 | var hasProxy = typeof Proxy !== "undefined";
|
117 | var plainObjectString = Object.toString();
|
118 | function assertProxies() {
|
119 | if (!hasProxy) {
|
120 | die(process.env.NODE_ENV !== "production" ? "`Proxy` objects are not available in the current environment. Please configure MobX to enable a fallback implementation.`" : "Proxy not available");
|
121 | }
|
122 | }
|
123 | function warnAboutProxyRequirement(msg) {
|
124 | if (process.env.NODE_ENV !== "production" && globalState.verifyProxies) {
|
125 | die("MobX is currently configured to be able to run in ES5 mode, but in ES5 MobX won't be able to " + msg);
|
126 | }
|
127 | }
|
128 | function getNextId() {
|
129 | return ++globalState.mobxGuid;
|
130 | }
|
131 |
|
132 |
|
133 |
|
134 | function once(func) {
|
135 | var invoked = false;
|
136 | return function () {
|
137 | if (invoked) {
|
138 | return;
|
139 | }
|
140 | invoked = true;
|
141 | return func.apply(this, arguments);
|
142 | };
|
143 | }
|
144 | var noop = function noop() {};
|
145 | function isFunction(fn) {
|
146 | return typeof fn === "function";
|
147 | }
|
148 | function isStringish(value) {
|
149 | var t = typeof value;
|
150 | switch (t) {
|
151 | case "string":
|
152 | case "symbol":
|
153 | case "number":
|
154 | return true;
|
155 | }
|
156 | return false;
|
157 | }
|
158 | function isObject(value) {
|
159 | return value !== null && typeof value === "object";
|
160 | }
|
161 | function isPlainObject(value) {
|
162 | if (!isObject(value)) {
|
163 | return false;
|
164 | }
|
165 | var proto = Object.getPrototypeOf(value);
|
166 | if (proto == null) {
|
167 | return true;
|
168 | }
|
169 | var protoConstructor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
170 | return typeof protoConstructor === "function" && protoConstructor.toString() === plainObjectString;
|
171 | }
|
172 |
|
173 | function isGenerator(obj) {
|
174 | var constructor = obj == null ? void 0 : obj.constructor;
|
175 | if (!constructor) {
|
176 | return false;
|
177 | }
|
178 | if ("GeneratorFunction" === constructor.name || "GeneratorFunction" === constructor.displayName) {
|
179 | return true;
|
180 | }
|
181 | return false;
|
182 | }
|
183 | function addHiddenProp(object, propName, value) {
|
184 | defineProperty(object, propName, {
|
185 | enumerable: false,
|
186 | writable: true,
|
187 | configurable: true,
|
188 | value: value
|
189 | });
|
190 | }
|
191 | function addHiddenFinalProp(object, propName, value) {
|
192 | defineProperty(object, propName, {
|
193 | enumerable: false,
|
194 | writable: false,
|
195 | configurable: true,
|
196 | value: value
|
197 | });
|
198 | }
|
199 | function createInstanceofPredicate(name, theClass) {
|
200 | var propName = "isMobX" + name;
|
201 | theClass.prototype[propName] = true;
|
202 | return function (x) {
|
203 | return isObject(x) && x[propName] === true;
|
204 | };
|
205 | }
|
206 | function isES6Map(thing) {
|
207 | return thing instanceof Map;
|
208 | }
|
209 | function isES6Set(thing) {
|
210 | return thing instanceof Set;
|
211 | }
|
212 | var hasGetOwnPropertySymbols = typeof Object.getOwnPropertySymbols !== "undefined";
|
213 |
|
214 |
|
215 |
|
216 | function getPlainObjectKeys(object) {
|
217 | var keys = Object.keys(object);
|
218 |
|
219 | if (!hasGetOwnPropertySymbols) {
|
220 | return keys;
|
221 | }
|
222 | var symbols = Object.getOwnPropertySymbols(object);
|
223 | if (!symbols.length) {
|
224 | return keys;
|
225 | }
|
226 | return [].concat(keys, symbols.filter(function (s) {
|
227 | return objectPrototype.propertyIsEnumerable.call(object, s);
|
228 | }));
|
229 | }
|
230 |
|
231 |
|
232 | var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : hasGetOwnPropertySymbols ? function (obj) {
|
233 | return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
|
234 | } : Object.getOwnPropertyNames;
|
235 | function stringifyKey(key) {
|
236 | if (typeof key === "string") {
|
237 | return key;
|
238 | }
|
239 | if (typeof key === "symbol") {
|
240 | return key.toString();
|
241 | }
|
242 | return new String(key).toString();
|
243 | }
|
244 | function toPrimitive(value) {
|
245 | return value === null ? null : typeof value === "object" ? "" + value : value;
|
246 | }
|
247 | function hasProp(target, prop) {
|
248 | return objectPrototype.hasOwnProperty.call(target, prop);
|
249 | }
|
250 |
|
251 | var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors(target) {
|
252 |
|
253 | var res = {};
|
254 |
|
255 | ownKeys(target).forEach(function (key) {
|
256 | res[key] = getDescriptor(target, key);
|
257 | });
|
258 | return res;
|
259 | };
|
260 |
|
261 | function _defineProperties(target, props) {
|
262 | for (var i = 0; i < props.length; i++) {
|
263 | var descriptor = props[i];
|
264 | descriptor.enumerable = descriptor.enumerable || false;
|
265 | descriptor.configurable = true;
|
266 | if ("value" in descriptor) descriptor.writable = true;
|
267 | Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
268 | }
|
269 | }
|
270 | function _createClass(Constructor, protoProps, staticProps) {
|
271 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
272 | if (staticProps) _defineProperties(Constructor, staticProps);
|
273 | Object.defineProperty(Constructor, "prototype", {
|
274 | writable: false
|
275 | });
|
276 | return Constructor;
|
277 | }
|
278 | function _extends() {
|
279 | _extends = Object.assign ? Object.assign.bind() : function (target) {
|
280 | for (var i = 1; i < arguments.length; i++) {
|
281 | var source = arguments[i];
|
282 | for (var key in source) {
|
283 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
284 | target[key] = source[key];
|
285 | }
|
286 | }
|
287 | }
|
288 | return target;
|
289 | };
|
290 | return _extends.apply(this, arguments);
|
291 | }
|
292 | function _inheritsLoose(subClass, superClass) {
|
293 | subClass.prototype = Object.create(superClass.prototype);
|
294 | subClass.prototype.constructor = subClass;
|
295 | _setPrototypeOf(subClass, superClass);
|
296 | }
|
297 | function _setPrototypeOf(o, p) {
|
298 | _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
299 | o.__proto__ = p;
|
300 | return o;
|
301 | };
|
302 | return _setPrototypeOf(o, p);
|
303 | }
|
304 | function _assertThisInitialized(self) {
|
305 | if (self === void 0) {
|
306 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
307 | }
|
308 | return self;
|
309 | }
|
310 | function _unsupportedIterableToArray(o, minLen) {
|
311 | if (!o) return;
|
312 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
313 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
314 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
315 | if (n === "Map" || n === "Set") return Array.from(o);
|
316 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
317 | }
|
318 | function _arrayLikeToArray(arr, len) {
|
319 | if (len == null || len > arr.length) len = arr.length;
|
320 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
321 | return arr2;
|
322 | }
|
323 | function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
324 | var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
325 | if (it) return (it = it.call(o)).next.bind(it);
|
326 | if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
327 | if (it) o = it;
|
328 | var i = 0;
|
329 | return function () {
|
330 | if (i >= o.length) return {
|
331 | done: true
|
332 | };
|
333 | return {
|
334 | done: false,
|
335 | value: o[i++]
|
336 | };
|
337 | };
|
338 | }
|
339 | throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
340 | }
|
341 | function _toPrimitive(input, hint) {
|
342 | if (typeof input !== "object" || input === null) return input;
|
343 | var prim = input[Symbol.toPrimitive];
|
344 | if (prim !== undefined) {
|
345 | var res = prim.call(input, hint || "default");
|
346 | if (typeof res !== "object") return res;
|
347 | throw new TypeError("@@toPrimitive must return a primitive value.");
|
348 | }
|
349 | return (hint === "string" ? String : Number)(input);
|
350 | }
|
351 | function _toPropertyKey(arg) {
|
352 | var key = _toPrimitive(arg, "string");
|
353 | return typeof key === "symbol" ? key : String(key);
|
354 | }
|
355 |
|
356 | var storedAnnotationsSymbol = Symbol("mobx-stored-annotations");
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 | function createDecoratorAnnotation(annotation) {
|
363 | function decorator(target, property) {
|
364 | storeAnnotation(target, property, annotation);
|
365 | }
|
366 | return Object.assign(decorator, annotation);
|
367 | }
|
368 |
|
369 |
|
370 |
|
371 |
|
372 | function storeAnnotation(prototype, key, annotation) {
|
373 | if (!hasProp(prototype, storedAnnotationsSymbol)) {
|
374 | addHiddenProp(prototype, storedAnnotationsSymbol, _extends({}, prototype[storedAnnotationsSymbol]));
|
375 | }
|
376 |
|
377 | if (process.env.NODE_ENV !== "production" && isOverride(annotation) && !hasProp(prototype[storedAnnotationsSymbol], key)) {
|
378 | var fieldName = prototype.constructor.name + ".prototype." + key.toString();
|
379 | die("'" + fieldName + "' is decorated with 'override', " + "but no such decorated member was found on prototype.");
|
380 | }
|
381 |
|
382 | assertNotDecorated(prototype, annotation, key);
|
383 |
|
384 | if (!isOverride(annotation)) {
|
385 | prototype[storedAnnotationsSymbol][key] = annotation;
|
386 | }
|
387 | }
|
388 | function assertNotDecorated(prototype, annotation, key) {
|
389 | if (process.env.NODE_ENV !== "production" && !isOverride(annotation) && hasProp(prototype[storedAnnotationsSymbol], key)) {
|
390 | var fieldName = prototype.constructor.name + ".prototype." + key.toString();
|
391 | var currentAnnotationType = prototype[storedAnnotationsSymbol][key].annotationType_;
|
392 | var requestedAnnotationType = annotation.annotationType_;
|
393 | die("Cannot apply '@" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already decorated with '@" + currentAnnotationType + "'.") + "\nRe-decorating fields is not allowed." + "\nUse '@override' decorator for methods overridden by subclass.");
|
394 | }
|
395 | }
|
396 |
|
397 |
|
398 |
|
399 | function collectStoredAnnotations(target) {
|
400 | if (!hasProp(target, storedAnnotationsSymbol)) {
|
401 | if (process.env.NODE_ENV !== "production" && !target[storedAnnotationsSymbol]) {
|
402 | die("No annotations were passed to makeObservable, but no decorated members have been found either");
|
403 | }
|
404 |
|
405 | addHiddenProp(target, storedAnnotationsSymbol, _extends({}, target[storedAnnotationsSymbol]));
|
406 | }
|
407 | return target[storedAnnotationsSymbol];
|
408 | }
|
409 |
|
410 | var $mobx = Symbol("mobx administration");
|
411 | var Atom = function () {
|
412 |
|
413 |
|
414 | |
415 |
|
416 |
|
417 |
|
418 | function Atom(name_) {
|
419 | if (name_ === void 0) {
|
420 | name_ = process.env.NODE_ENV !== "production" ? "Atom@" + getNextId() : "Atom";
|
421 | }
|
422 | this.name_ = void 0;
|
423 | this.isPendingUnobservation_ = false;
|
424 | this.isBeingObserved_ = false;
|
425 | this.observers_ = new Set();
|
426 | this.diffValue_ = 0;
|
427 | this.lastAccessedBy_ = 0;
|
428 | this.lowestObserverState_ = IDerivationState_.NOT_TRACKING_;
|
429 | this.onBOL = void 0;
|
430 | this.onBUOL = void 0;
|
431 | this.name_ = name_;
|
432 | }
|
433 |
|
434 | var _proto = Atom.prototype;
|
435 | _proto.onBO = function onBO() {
|
436 | if (this.onBOL) {
|
437 | this.onBOL.forEach(function (listener) {
|
438 | return listener();
|
439 | });
|
440 | }
|
441 | };
|
442 | _proto.onBUO = function onBUO() {
|
443 | if (this.onBUOL) {
|
444 | this.onBUOL.forEach(function (listener) {
|
445 | return listener();
|
446 | });
|
447 | }
|
448 | }
|
449 | |
450 |
|
451 |
|
452 | ;
|
453 | _proto.reportObserved = function reportObserved$1() {
|
454 | return reportObserved(this);
|
455 | }
|
456 | |
457 |
|
458 | ;
|
459 | _proto.reportChanged = function reportChanged() {
|
460 | startBatch();
|
461 | propagateChanged(this);
|
462 |
|
463 |
|
464 | globalState.stateVersion = globalState.stateVersion < Number.MAX_SAFE_INTEGER ? globalState.stateVersion + 1 : Number.MIN_SAFE_INTEGER;
|
465 | endBatch();
|
466 | };
|
467 | _proto.toString = function toString() {
|
468 | return this.name_;
|
469 | };
|
470 | return Atom;
|
471 | }();
|
472 | var isAtom = createInstanceofPredicate("Atom", Atom);
|
473 | function createAtom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
|
474 | if (onBecomeObservedHandler === void 0) {
|
475 | onBecomeObservedHandler = noop;
|
476 | }
|
477 | if (onBecomeUnobservedHandler === void 0) {
|
478 | onBecomeUnobservedHandler = noop;
|
479 | }
|
480 | var atom = new Atom(name);
|
481 |
|
482 | if (onBecomeObservedHandler !== noop) {
|
483 | onBecomeObserved(atom, onBecomeObservedHandler);
|
484 | }
|
485 | if (onBecomeUnobservedHandler !== noop) {
|
486 | onBecomeUnobserved(atom, onBecomeUnobservedHandler);
|
487 | }
|
488 | return atom;
|
489 | }
|
490 |
|
491 | function identityComparer(a, b) {
|
492 | return a === b;
|
493 | }
|
494 | function structuralComparer(a, b) {
|
495 | return deepEqual(a, b);
|
496 | }
|
497 | function shallowComparer(a, b) {
|
498 | return deepEqual(a, b, 1);
|
499 | }
|
500 | function defaultComparer(a, b) {
|
501 | if (Object.is) {
|
502 | return Object.is(a, b);
|
503 | }
|
504 | return a === b ? a !== 0 || 1 / a === 1 / b : a !== a && b !== b;
|
505 | }
|
506 | var comparer = {
|
507 | identity: identityComparer,
|
508 | structural: structuralComparer,
|
509 | "default": defaultComparer,
|
510 | shallow: shallowComparer
|
511 | };
|
512 |
|
513 | function deepEnhancer(v, _, name) {
|
514 |
|
515 | if (isObservable(v)) {
|
516 | return v;
|
517 | }
|
518 |
|
519 | if (Array.isArray(v)) {
|
520 | return observable.array(v, {
|
521 | name: name
|
522 | });
|
523 | }
|
524 | if (isPlainObject(v)) {
|
525 | return observable.object(v, undefined, {
|
526 | name: name
|
527 | });
|
528 | }
|
529 | if (isES6Map(v)) {
|
530 | return observable.map(v, {
|
531 | name: name
|
532 | });
|
533 | }
|
534 | if (isES6Set(v)) {
|
535 | return observable.set(v, {
|
536 | name: name
|
537 | });
|
538 | }
|
539 | if (typeof v === "function" && !isAction(v) && !isFlow(v)) {
|
540 | if (isGenerator(v)) {
|
541 | return flow(v);
|
542 | } else {
|
543 | return autoAction(name, v);
|
544 | }
|
545 | }
|
546 | return v;
|
547 | }
|
548 | function shallowEnhancer(v, _, name) {
|
549 | if (v === undefined || v === null) {
|
550 | return v;
|
551 | }
|
552 | if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v) || isObservableSet(v)) {
|
553 | return v;
|
554 | }
|
555 | if (Array.isArray(v)) {
|
556 | return observable.array(v, {
|
557 | name: name,
|
558 | deep: false
|
559 | });
|
560 | }
|
561 | if (isPlainObject(v)) {
|
562 | return observable.object(v, undefined, {
|
563 | name: name,
|
564 | deep: false
|
565 | });
|
566 | }
|
567 | if (isES6Map(v)) {
|
568 | return observable.map(v, {
|
569 | name: name,
|
570 | deep: false
|
571 | });
|
572 | }
|
573 | if (isES6Set(v)) {
|
574 | return observable.set(v, {
|
575 | name: name,
|
576 | deep: false
|
577 | });
|
578 | }
|
579 | if (process.env.NODE_ENV !== "production") {
|
580 | die("The shallow modifier / decorator can only used in combination with arrays, objects, maps and sets");
|
581 | }
|
582 | }
|
583 | function referenceEnhancer(newValue) {
|
584 |
|
585 | return newValue;
|
586 | }
|
587 | function refStructEnhancer(v, oldValue) {
|
588 | if (process.env.NODE_ENV !== "production" && isObservable(v)) {
|
589 | die("observable.struct should not be used with observable values");
|
590 | }
|
591 | if (deepEqual(v, oldValue)) {
|
592 | return oldValue;
|
593 | }
|
594 | return v;
|
595 | }
|
596 |
|
597 | var OVERRIDE = "override";
|
598 | var override = createDecoratorAnnotation({
|
599 | annotationType_: OVERRIDE,
|
600 | make_: make_,
|
601 | extend_: extend_
|
602 | });
|
603 | function isOverride(annotation) {
|
604 | return annotation.annotationType_ === OVERRIDE;
|
605 | }
|
606 | function make_(adm, key) {
|
607 |
|
608 | if (process.env.NODE_ENV !== "production" && adm.isPlainObject_) {
|
609 | die("Cannot apply '" + this.annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + this.annotationType_ + "' cannot be used on plain objects."));
|
610 | }
|
611 |
|
612 | if (process.env.NODE_ENV !== "production" && !hasProp(adm.appliedAnnotations_, key)) {
|
613 | die("'" + adm.name_ + "." + key.toString() + "' is annotated with '" + this.annotationType_ + "', " + "but no such annotated member was found on prototype.");
|
614 | }
|
615 | return 0 ;
|
616 | }
|
617 |
|
618 | function extend_(adm, key, descriptor, proxyTrap) {
|
619 | die("'" + this.annotationType_ + "' can only be used with 'makeObservable'");
|
620 | }
|
621 |
|
622 | function createActionAnnotation(name, options) {
|
623 | return {
|
624 | annotationType_: name,
|
625 | options_: options,
|
626 | make_: make_$1,
|
627 | extend_: extend_$1
|
628 | };
|
629 | }
|
630 | function make_$1(adm, key, descriptor, source) {
|
631 | var _this$options_;
|
632 |
|
633 | if ((_this$options_ = this.options_) != null && _this$options_.bound) {
|
634 | return this.extend_(adm, key, descriptor, false) === null ? 0 : 1 ;
|
635 | }
|
636 |
|
637 | if (source === adm.target_) {
|
638 | return this.extend_(adm, key, descriptor, false) === null ? 0 : 2 ;
|
639 | }
|
640 |
|
641 | if (isAction(descriptor.value)) {
|
642 |
|
643 |
|
644 | return 1 ;
|
645 | }
|
646 |
|
647 | var actionDescriptor = createActionDescriptor(adm, this, key, descriptor, false);
|
648 | defineProperty(source, key, actionDescriptor);
|
649 | return 2 ;
|
650 | }
|
651 |
|
652 | function extend_$1(adm, key, descriptor, proxyTrap) {
|
653 | var actionDescriptor = createActionDescriptor(adm, this, key, descriptor);
|
654 | return adm.defineProperty_(key, actionDescriptor, proxyTrap);
|
655 | }
|
656 | function assertActionDescriptor(adm, _ref, key, _ref2) {
|
657 | var annotationType_ = _ref.annotationType_;
|
658 | var value = _ref2.value;
|
659 | if (process.env.NODE_ENV !== "production" && !isFunction(value)) {
|
660 | die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' can only be used on properties with a function value."));
|
661 | }
|
662 | }
|
663 | function createActionDescriptor(adm, annotation, key, descriptor,
|
664 | // provides ability to disable safeDescriptors for prototypes
|
665 | safeDescriptors) {
|
666 | var _annotation$options_, _annotation$options_$, _annotation$options_2, _annotation$options_$2, _annotation$options_3, _annotation$options_4, _adm$proxy_2;
|
667 | if (safeDescriptors === void 0) {
|
668 | safeDescriptors = globalState.safeDescriptors;
|
669 | }
|
670 | assertActionDescriptor(adm, annotation, key, descriptor);
|
671 | var value = descriptor.value;
|
672 | if ((_annotation$options_ = annotation.options_) != null && _annotation$options_.bound) {
|
673 | var _adm$proxy_;
|
674 | value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
675 | }
|
676 | return {
|
677 | value: createAction((_annotation$options_$ = (_annotation$options_2 = annotation.options_) == null ? void 0 : _annotation$options_2.name) != null ? _annotation$options_$ : key.toString(), value, (_annotation$options_$2 = (_annotation$options_3 = annotation.options_) == null ? void 0 : _annotation$options_3.autoAction) != null ? _annotation$options_$2 : false,
|
678 |
|
679 | (_annotation$options_4 = annotation.options_) != null && _annotation$options_4.bound ? (_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_ : undefined),
|
680 |
|
681 |
|
682 | configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
683 |
|
684 | enumerable: false,
|
685 |
|
686 |
|
687 | writable: safeDescriptors ? false : true
|
688 | };
|
689 | }
|
690 |
|
691 | function createFlowAnnotation(name, options) {
|
692 | return {
|
693 | annotationType_: name,
|
694 | options_: options,
|
695 | make_: make_$2,
|
696 | extend_: extend_$2
|
697 | };
|
698 | }
|
699 | function make_$2(adm, key, descriptor, source) {
|
700 | var _this$options_;
|
701 |
|
702 | if (source === adm.target_) {
|
703 | return this.extend_(adm, key, descriptor, false) === null ? 0 : 2 ;
|
704 | }
|
705 |
|
706 |
|
707 | if ((_this$options_ = this.options_) != null && _this$options_.bound && (!hasProp(adm.target_, key) || !isFlow(adm.target_[key]))) {
|
708 | if (this.extend_(adm, key, descriptor, false) === null) {
|
709 | return 0 ;
|
710 | }
|
711 | }
|
712 |
|
713 | if (isFlow(descriptor.value)) {
|
714 |
|
715 |
|
716 | return 1 ;
|
717 | }
|
718 |
|
719 | var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, false, false);
|
720 | defineProperty(source, key, flowDescriptor);
|
721 | return 2 ;
|
722 | }
|
723 |
|
724 | function extend_$2(adm, key, descriptor, proxyTrap) {
|
725 | var _this$options_2;
|
726 | var flowDescriptor = createFlowDescriptor(adm, this, key, descriptor, (_this$options_2 = this.options_) == null ? void 0 : _this$options_2.bound);
|
727 | return adm.defineProperty_(key, flowDescriptor, proxyTrap);
|
728 | }
|
729 | function assertFlowDescriptor(adm, _ref, key, _ref2) {
|
730 | var annotationType_ = _ref.annotationType_;
|
731 | var value = _ref2.value;
|
732 | if (process.env.NODE_ENV !== "production" && !isFunction(value)) {
|
733 | die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' can only be used on properties with a generator function value."));
|
734 | }
|
735 | }
|
736 | function createFlowDescriptor(adm, annotation, key, descriptor, bound,
|
737 | // provides ability to disable safeDescriptors for prototypes
|
738 | safeDescriptors) {
|
739 | if (safeDescriptors === void 0) {
|
740 | safeDescriptors = globalState.safeDescriptors;
|
741 | }
|
742 | assertFlowDescriptor(adm, annotation, key, descriptor);
|
743 | var value = descriptor.value;
|
744 |
|
745 | if (!isFlow(value)) {
|
746 | value = flow(value);
|
747 | }
|
748 | if (bound) {
|
749 | var _adm$proxy_;
|
750 |
|
751 | value = value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
752 |
|
753 | value.isMobXFlow = true;
|
754 | }
|
755 | return {
|
756 | value: value,
|
757 |
|
758 |
|
759 | configurable: safeDescriptors ? adm.isPlainObject_ : true,
|
760 |
|
761 | enumerable: false,
|
762 |
|
763 |
|
764 | writable: safeDescriptors ? false : true
|
765 | };
|
766 | }
|
767 |
|
768 | function createComputedAnnotation(name, options) {
|
769 | return {
|
770 | annotationType_: name,
|
771 | options_: options,
|
772 | make_: make_$3,
|
773 | extend_: extend_$3
|
774 | };
|
775 | }
|
776 | function make_$3(adm, key, descriptor) {
|
777 | return this.extend_(adm, key, descriptor, false) === null ? 0 : 1 ;
|
778 | }
|
779 |
|
780 | function extend_$3(adm, key, descriptor, proxyTrap) {
|
781 | assertComputedDescriptor(adm, this, key, descriptor);
|
782 | return adm.defineComputedProperty_(key, _extends({}, this.options_, {
|
783 | get: descriptor.get,
|
784 | set: descriptor.set
|
785 | }), proxyTrap);
|
786 | }
|
787 | function assertComputedDescriptor(adm, _ref, key, _ref2) {
|
788 | var annotationType_ = _ref.annotationType_;
|
789 | var get = _ref2.get;
|
790 | if (process.env.NODE_ENV !== "production" && !get) {
|
791 | die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' can only be used on getter(+setter) properties."));
|
792 | }
|
793 | }
|
794 |
|
795 | function createObservableAnnotation(name, options) {
|
796 | return {
|
797 | annotationType_: name,
|
798 | options_: options,
|
799 | make_: make_$4,
|
800 | extend_: extend_$4
|
801 | };
|
802 | }
|
803 | function make_$4(adm, key, descriptor) {
|
804 | return this.extend_(adm, key, descriptor, false) === null ? 0 : 1 ;
|
805 | }
|
806 |
|
807 | function extend_$4(adm, key, descriptor, proxyTrap) {
|
808 | var _this$options_$enhanc, _this$options_;
|
809 | assertObservableDescriptor(adm, this, key, descriptor);
|
810 | return adm.defineObservableProperty_(key, descriptor.value, (_this$options_$enhanc = (_this$options_ = this.options_) == null ? void 0 : _this$options_.enhancer) != null ? _this$options_$enhanc : deepEnhancer, proxyTrap);
|
811 | }
|
812 | function assertObservableDescriptor(adm, _ref, key, descriptor) {
|
813 | var annotationType_ = _ref.annotationType_;
|
814 | if (process.env.NODE_ENV !== "production" && !("value" in descriptor)) {
|
815 | die("Cannot apply '" + annotationType_ + "' to '" + adm.name_ + "." + key.toString() + "':" + ("\n'" + annotationType_ + "' cannot be used on getter/setter properties"));
|
816 | }
|
817 | }
|
818 |
|
819 | var AUTO = "true";
|
820 | var autoAnnotation = createAutoAnnotation();
|
821 | function createAutoAnnotation(options) {
|
822 | return {
|
823 | annotationType_: AUTO,
|
824 | options_: options,
|
825 | make_: make_$5,
|
826 | extend_: extend_$5
|
827 | };
|
828 | }
|
829 | function make_$5(adm, key, descriptor, source) {
|
830 | var _this$options_3, _this$options_4;
|
831 |
|
832 | if (descriptor.get) {
|
833 | return computed.make_(adm, key, descriptor, source);
|
834 | }
|
835 |
|
836 | if (descriptor.set) {
|
837 |
|
838 | var set = createAction(key.toString(), descriptor.set);
|
839 | // own
|
840 | if (source === adm.target_) {
|
841 | return adm.defineProperty_(key, {
|
842 | configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
843 | set: set
|
844 | }) === null ? 0 /* Cancel */ : 2 /* Continue */;
|
845 | }
|
846 | // proto
|
847 | defineProperty(source, key, {
|
848 | configurable: true,
|
849 | set: set
|
850 | });
|
851 | return 2 /* Continue */;
|
852 | }
|
853 | // function on proto -> autoAction/flow
|
854 | if (source !== adm.target_ && typeof descriptor.value === "function") {
|
855 | var _this$options_2;
|
856 | if (isGenerator(descriptor.value)) {
|
857 | var _this$options_;
|
858 | var flowAnnotation = (_this$options_ = this.options_) != null && _this$options_.autoBind ? flow.bound : flow;
|
859 | return flowAnnotation.make_(adm, key, descriptor, source);
|
860 | }
|
861 | var actionAnnotation = (_this$options_2 = this.options_) != null && _this$options_2.autoBind ? autoAction.bound : autoAction;
|
862 | return actionAnnotation.make_(adm, key, descriptor, source);
|
863 | }
|
864 |
|
865 |
|
866 |
|
867 | var observableAnnotation = ((_this$options_3 = this.options_) == null ? void 0 : _this$options_3.deep) === false ? observable.ref : observable;
|
868 |
|
869 | if (typeof descriptor.value === "function" && (_this$options_4 = this.options_) != null && _this$options_4.autoBind) {
|
870 | var _adm$proxy_;
|
871 | descriptor.value = descriptor.value.bind((_adm$proxy_ = adm.proxy_) != null ? _adm$proxy_ : adm.target_);
|
872 | }
|
873 | return observableAnnotation.make_(adm, key, descriptor, source);
|
874 | }
|
875 | function extend_$5(adm, key, descriptor, proxyTrap) {
|
876 | var _this$options_5, _this$options_6;
|
877 |
|
878 | if (descriptor.get) {
|
879 | return computed.extend_(adm, key, descriptor, proxyTrap);
|
880 | }
|
881 |
|
882 | if (descriptor.set) {
|
883 |
|
884 | return adm.defineProperty_(key, {
|
885 | configurable: globalState.safeDescriptors ? adm.isPlainObject_ : true,
|
886 | set: createAction(key.toString(), descriptor.set)
|
887 | }, proxyTrap);
|
888 | }
|
889 | // other -> observable
|
890 | // if function respect autoBind option
|
891 | if (typeof descriptor.value === "function" && (_this$options_5 = this.options_) != null && _this$options_5.autoBind) {
|
892 | var _adm$proxy_2;
|
893 | descriptor.value = descriptor.value.bind((_adm$proxy_2 = adm.proxy_) != null ? _adm$proxy_2 : adm.target_);
|
894 | }
|
895 | var observableAnnotation = ((_this$options_6 = this.options_) == null ? void 0 : _this$options_6.deep) === false ? observable.ref : observable;
|
896 | return observableAnnotation.extend_(adm, key, descriptor, proxyTrap);
|
897 | }
|
898 |
|
899 | var OBSERVABLE = "observable";
|
900 | var OBSERVABLE_REF = "observable.ref";
|
901 | var OBSERVABLE_SHALLOW = "observable.shallow";
|
902 | var OBSERVABLE_STRUCT = "observable.struct";
|
903 |
|
904 |
|
905 | var defaultCreateObservableOptions = {
|
906 | deep: true,
|
907 | name: undefined,
|
908 | defaultDecorator: undefined,
|
909 | proxy: true
|
910 | };
|
911 | Object.freeze(defaultCreateObservableOptions);
|
912 | function asCreateObservableOptions(thing) {
|
913 | return thing || defaultCreateObservableOptions;
|
914 | }
|
915 | var observableAnnotation = createObservableAnnotation(OBSERVABLE);
|
916 | var observableRefAnnotation = createObservableAnnotation(OBSERVABLE_REF, {
|
917 | enhancer: referenceEnhancer
|
918 | });
|
919 | var observableShallowAnnotation = createObservableAnnotation(OBSERVABLE_SHALLOW, {
|
920 | enhancer: shallowEnhancer
|
921 | });
|
922 | var observableStructAnnotation = createObservableAnnotation(OBSERVABLE_STRUCT, {
|
923 | enhancer: refStructEnhancer
|
924 | });
|
925 | var observableDecoratorAnnotation = createDecoratorAnnotation(observableAnnotation);
|
926 | function getEnhancerFromOptions(options) {
|
927 | return options.deep === true ? deepEnhancer : options.deep === false ? referenceEnhancer : getEnhancerFromAnnotation(options.defaultDecorator);
|
928 | }
|
929 | function getAnnotationFromOptions(options) {
|
930 | var _options$defaultDecor;
|
931 | return options ? (_options$defaultDecor = options.defaultDecorator) != null ? _options$defaultDecor : createAutoAnnotation(options) : undefined;
|
932 | }
|
933 | function getEnhancerFromAnnotation(annotation) {
|
934 | var _annotation$options_$, _annotation$options_;
|
935 | return !annotation ? deepEnhancer : (_annotation$options_$ = (_annotation$options_ = annotation.options_) == null ? void 0 : _annotation$options_.enhancer) != null ? _annotation$options_$ : deepEnhancer;
|
936 | }
|
937 |
|
938 |
|
939 |
|
940 |
|
941 | function createObservable(v, arg2, arg3) {
|
942 |
|
943 | if (isStringish(arg2)) {
|
944 | storeAnnotation(v, arg2, observableAnnotation);
|
945 | return;
|
946 | }
|
947 |
|
948 | if (isObservable(v)) {
|
949 | return v;
|
950 | }
|
951 |
|
952 | if (isPlainObject(v)) {
|
953 | return observable.object(v, arg2, arg3);
|
954 | }
|
955 |
|
956 | if (Array.isArray(v)) {
|
957 | return observable.array(v, arg2);
|
958 | }
|
959 |
|
960 | if (isES6Map(v)) {
|
961 | return observable.map(v, arg2);
|
962 | }
|
963 |
|
964 | if (isES6Set(v)) {
|
965 | return observable.set(v, arg2);
|
966 | }
|
967 |
|
968 | if (typeof v === "object" && v !== null) {
|
969 | return v;
|
970 | }
|
971 |
|
972 | return observable.box(v, arg2);
|
973 | }
|
974 | assign(createObservable, observableDecoratorAnnotation);
|
975 | var observableFactories = {
|
976 | box: function box(value, options) {
|
977 | var o = asCreateObservableOptions(options);
|
978 | return new ObservableValue(value, getEnhancerFromOptions(o), o.name, true, o.equals);
|
979 | },
|
980 | array: function array(initialValues, options) {
|
981 | var o = asCreateObservableOptions(options);
|
982 | return (globalState.useProxies === false || o.proxy === false ? createLegacyArray : createObservableArray)(initialValues, getEnhancerFromOptions(o), o.name);
|
983 | },
|
984 | map: function map(initialValues, options) {
|
985 | var o = asCreateObservableOptions(options);
|
986 | return new ObservableMap(initialValues, getEnhancerFromOptions(o), o.name);
|
987 | },
|
988 | set: function set(initialValues, options) {
|
989 | var o = asCreateObservableOptions(options);
|
990 | return new ObservableSet(initialValues, getEnhancerFromOptions(o), o.name);
|
991 | },
|
992 | object: function object(props, decorators, options) {
|
993 | return extendObservable(globalState.useProxies === false || (options == null ? void 0 : options.proxy) === false ? asObservableObject({}, options) : asDynamicObservableObject({}, options), props, decorators);
|
994 | },
|
995 | ref: createDecoratorAnnotation(observableRefAnnotation),
|
996 | shallow: createDecoratorAnnotation(observableShallowAnnotation),
|
997 | deep: observableDecoratorAnnotation,
|
998 | struct: createDecoratorAnnotation(observableStructAnnotation)
|
999 | };
|
1000 |
|
1001 | var observable = assign(createObservable, observableFactories);
|
1002 |
|
1003 | var COMPUTED = "computed";
|
1004 | var COMPUTED_STRUCT = "computed.struct";
|
1005 | var computedAnnotation = createComputedAnnotation(COMPUTED);
|
1006 | var computedStructAnnotation = createComputedAnnotation(COMPUTED_STRUCT, {
|
1007 | equals: comparer.structural
|
1008 | });
|
1009 |
|
1010 |
|
1011 |
|
1012 |
|
1013 | var computed = function computed(arg1, arg2) {
|
1014 | if (isStringish(arg2)) {
|
1015 |
|
1016 | return storeAnnotation(arg1, arg2, computedAnnotation);
|
1017 | }
|
1018 | if (isPlainObject(arg1)) {
|
1019 |
|
1020 | return createDecoratorAnnotation(createComputedAnnotation(COMPUTED, arg1));
|
1021 | }
|
1022 |
|
1023 | if (process.env.NODE_ENV !== "production") {
|
1024 | if (!isFunction(arg1)) {
|
1025 | die("First argument to `computed` should be an expression.");
|
1026 | }
|
1027 | if (isFunction(arg2)) {
|
1028 | die("A setter as second argument is no longer supported, use `{ set: fn }` option instead");
|
1029 | }
|
1030 | }
|
1031 | var opts = isPlainObject(arg2) ? arg2 : {};
|
1032 | opts.get = arg1;
|
1033 | opts.name || (opts.name = arg1.name || "");
|
1034 | return new ComputedValue(opts);
|
1035 | };
|
1036 | Object.assign(computed, computedAnnotation);
|
1037 | computed.struct = createDecoratorAnnotation(computedStructAnnotation);
|
1038 |
|
1039 | var _getDescriptor$config, _getDescriptor;
|
1040 |
|
1041 |
|
1042 | var currentActionId = 0;
|
1043 | var nextActionId = 1;
|
1044 | var isFunctionNameConfigurable = (_getDescriptor$config = (_getDescriptor = getDescriptor(function () {}, "name")) == null ? void 0 : _getDescriptor.configurable) != null ? _getDescriptor$config : false;
|
1045 |
|
1046 | var tmpNameDescriptor = {
|
1047 | value: "action",
|
1048 | configurable: true,
|
1049 | writable: false,
|
1050 | enumerable: false
|
1051 | };
|
1052 | function createAction(actionName, fn, autoAction, ref) {
|
1053 | if (autoAction === void 0) {
|
1054 | autoAction = false;
|
1055 | }
|
1056 | if (process.env.NODE_ENV !== "production") {
|
1057 | if (!isFunction(fn)) {
|
1058 | die("`action` can only be invoked on functions");
|
1059 | }
|
1060 | if (typeof actionName !== "string" || !actionName) {
|
1061 | die("actions should have valid names, got: '" + actionName + "'");
|
1062 | }
|
1063 | }
|
1064 | function res() {
|
1065 | return executeAction(actionName, autoAction, fn, ref || this, arguments);
|
1066 | }
|
1067 | res.isMobxAction = true;
|
1068 | if (isFunctionNameConfigurable) {
|
1069 | tmpNameDescriptor.value = actionName;
|
1070 | defineProperty(res, "name", tmpNameDescriptor);
|
1071 | }
|
1072 | return res;
|
1073 | }
|
1074 | function executeAction(actionName, canRunAsDerivation, fn, scope, args) {
|
1075 | var runInfo = _startAction(actionName, canRunAsDerivation, scope, args);
|
1076 | try {
|
1077 | return fn.apply(scope, args);
|
1078 | } catch (err) {
|
1079 | runInfo.error_ = err;
|
1080 | throw err;
|
1081 | } finally {
|
1082 | _endAction(runInfo);
|
1083 | }
|
1084 | }
|
1085 | function _startAction(actionName, canRunAsDerivation,
|
1086 | // true for autoAction
|
1087 | scope, args) {
|
1088 | var notifySpy_ = process.env.NODE_ENV !== "production" && isSpyEnabled() && !!actionName;
|
1089 | var startTime_ = 0;
|
1090 | if (process.env.NODE_ENV !== "production" && notifySpy_) {
|
1091 | startTime_ = Date.now();
|
1092 | var flattenedArgs = args ? Array.from(args) : EMPTY_ARRAY;
|
1093 | spyReportStart({
|
1094 | type: ACTION,
|
1095 | name: actionName,
|
1096 | object: scope,
|
1097 | arguments: flattenedArgs
|
1098 | });
|
1099 | }
|
1100 | var prevDerivation_ = globalState.trackingDerivation;
|
1101 | var runAsAction = !canRunAsDerivation || !prevDerivation_;
|
1102 | startBatch();
|
1103 | var prevAllowStateChanges_ = globalState.allowStateChanges;
|
1104 | if (runAsAction) {
|
1105 | untrackedStart();
|
1106 | prevAllowStateChanges_ = allowStateChangesStart(true);
|
1107 | }
|
1108 | var prevAllowStateReads_ = allowStateReadsStart(true);
|
1109 | var runInfo = {
|
1110 | runAsAction_: runAsAction,
|
1111 | prevDerivation_: prevDerivation_,
|
1112 | prevAllowStateChanges_: prevAllowStateChanges_,
|
1113 | prevAllowStateReads_: prevAllowStateReads_,
|
1114 | notifySpy_: notifySpy_,
|
1115 | startTime_: startTime_,
|
1116 | actionId_: nextActionId++,
|
1117 | parentActionId_: currentActionId
|
1118 | };
|
1119 | currentActionId = runInfo.actionId_;
|
1120 | return runInfo;
|
1121 | }
|
1122 | function _endAction(runInfo) {
|
1123 | if (currentActionId !== runInfo.actionId_) {
|
1124 | die(30);
|
1125 | }
|
1126 | currentActionId = runInfo.parentActionId_;
|
1127 | if (runInfo.error_ !== undefined) {
|
1128 | globalState.suppressReactionErrors = true;
|
1129 | }
|
1130 | allowStateChangesEnd(runInfo.prevAllowStateChanges_);
|
1131 | allowStateReadsEnd(runInfo.prevAllowStateReads_);
|
1132 | endBatch();
|
1133 | if (runInfo.runAsAction_) {
|
1134 | untrackedEnd(runInfo.prevDerivation_);
|
1135 | }
|
1136 | if (process.env.NODE_ENV !== "production" && runInfo.notifySpy_) {
|
1137 | spyReportEnd({
|
1138 | time: Date.now() - runInfo.startTime_
|
1139 | });
|
1140 | }
|
1141 | globalState.suppressReactionErrors = false;
|
1142 | }
|
1143 | function allowStateChanges(allowStateChanges, func) {
|
1144 | var prev = allowStateChangesStart(allowStateChanges);
|
1145 | try {
|
1146 | return func();
|
1147 | } finally {
|
1148 | allowStateChangesEnd(prev);
|
1149 | }
|
1150 | }
|
1151 | function allowStateChangesStart(allowStateChanges) {
|
1152 | var prev = globalState.allowStateChanges;
|
1153 | globalState.allowStateChanges = allowStateChanges;
|
1154 | return prev;
|
1155 | }
|
1156 | function allowStateChangesEnd(prev) {
|
1157 | globalState.allowStateChanges = prev;
|
1158 | }
|
1159 |
|
1160 | var _Symbol$toPrimitive;
|
1161 | var CREATE = "create";
|
1162 | _Symbol$toPrimitive = Symbol.toPrimitive;
|
1163 | var ObservableValue = function (_Atom) {
|
1164 | _inheritsLoose(ObservableValue, _Atom);
|
1165 | function ObservableValue(value, enhancer, name_, notifySpy, equals) {
|
1166 | var _this;
|
1167 | if (name_ === void 0) {
|
1168 | name_ = process.env.NODE_ENV !== "production" ? "ObservableValue@" + getNextId() : "ObservableValue";
|
1169 | }
|
1170 | if (notifySpy === void 0) {
|
1171 | notifySpy = true;
|
1172 | }
|
1173 | if (equals === void 0) {
|
1174 | equals = comparer["default"];
|
1175 | }
|
1176 | _this = _Atom.call(this, name_) || this;
|
1177 | _this.enhancer = void 0;
|
1178 | _this.name_ = void 0;
|
1179 | _this.equals = void 0;
|
1180 | _this.hasUnreportedChange_ = false;
|
1181 | _this.interceptors_ = void 0;
|
1182 | _this.changeListeners_ = void 0;
|
1183 | _this.value_ = void 0;
|
1184 | _this.dehancer = void 0;
|
1185 | _this.enhancer = enhancer;
|
1186 | _this.name_ = name_;
|
1187 | _this.equals = equals;
|
1188 | _this.value_ = enhancer(value, undefined, name_);
|
1189 | if (process.env.NODE_ENV !== "production" && notifySpy && isSpyEnabled()) {
|
1190 |
|
1191 | spyReport({
|
1192 | type: CREATE,
|
1193 | object: _assertThisInitialized(_this),
|
1194 | observableKind: "value",
|
1195 | debugObjectName: _this.name_,
|
1196 | newValue: "" + _this.value_
|
1197 | });
|
1198 | }
|
1199 | return _this;
|
1200 | }
|
1201 | var _proto = ObservableValue.prototype;
|
1202 | _proto.dehanceValue = function dehanceValue(value) {
|
1203 | if (this.dehancer !== undefined) {
|
1204 | return this.dehancer(value);
|
1205 | }
|
1206 | return value;
|
1207 | };
|
1208 | _proto.set = function set(newValue) {
|
1209 | var oldValue = this.value_;
|
1210 | newValue = this.prepareNewValue_(newValue);
|
1211 | if (newValue !== globalState.UNCHANGED) {
|
1212 | var notifySpy = isSpyEnabled();
|
1213 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
1214 | spyReportStart({
|
1215 | type: UPDATE,
|
1216 | object: this,
|
1217 | observableKind: "value",
|
1218 | debugObjectName: this.name_,
|
1219 | newValue: newValue,
|
1220 | oldValue: oldValue
|
1221 | });
|
1222 | }
|
1223 | this.setNewValue_(newValue);
|
1224 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
1225 | spyReportEnd();
|
1226 | }
|
1227 | }
|
1228 | };
|
1229 | _proto.prepareNewValue_ = function prepareNewValue_(newValue) {
|
1230 | checkIfStateModificationsAreAllowed(this);
|
1231 | if (hasInterceptors(this)) {
|
1232 | var change = interceptChange(this, {
|
1233 | object: this,
|
1234 | type: UPDATE,
|
1235 | newValue: newValue
|
1236 | });
|
1237 | if (!change) {
|
1238 | return globalState.UNCHANGED;
|
1239 | }
|
1240 | newValue = change.newValue;
|
1241 | }
|
1242 |
|
1243 | newValue = this.enhancer(newValue, this.value_, this.name_);
|
1244 | return this.equals(this.value_, newValue) ? globalState.UNCHANGED : newValue;
|
1245 | };
|
1246 | _proto.setNewValue_ = function setNewValue_(newValue) {
|
1247 | var oldValue = this.value_;
|
1248 | this.value_ = newValue;
|
1249 | this.reportChanged();
|
1250 | if (hasListeners(this)) {
|
1251 | notifyListeners(this, {
|
1252 | type: UPDATE,
|
1253 | object: this,
|
1254 | newValue: newValue,
|
1255 | oldValue: oldValue
|
1256 | });
|
1257 | }
|
1258 | };
|
1259 | _proto.get = function get() {
|
1260 | this.reportObserved();
|
1261 | return this.dehanceValue(this.value_);
|
1262 | };
|
1263 | _proto.intercept_ = function intercept_(handler) {
|
1264 | return registerInterceptor(this, handler);
|
1265 | };
|
1266 | _proto.observe_ = function observe_(listener, fireImmediately) {
|
1267 | if (fireImmediately) {
|
1268 | listener({
|
1269 | observableKind: "value",
|
1270 | debugObjectName: this.name_,
|
1271 | object: this,
|
1272 | type: UPDATE,
|
1273 | newValue: this.value_,
|
1274 | oldValue: undefined
|
1275 | });
|
1276 | }
|
1277 | return registerListener(this, listener);
|
1278 | };
|
1279 | _proto.raw = function raw() {
|
1280 |
|
1281 | return this.value_;
|
1282 | };
|
1283 | _proto.toJSON = function toJSON() {
|
1284 | return this.get();
|
1285 | };
|
1286 | _proto.toString = function toString() {
|
1287 | return this.name_ + "[" + this.value_ + "]";
|
1288 | };
|
1289 | _proto.valueOf = function valueOf() {
|
1290 | return toPrimitive(this.get());
|
1291 | };
|
1292 | _proto[_Symbol$toPrimitive] = function () {
|
1293 | return this.valueOf();
|
1294 | };
|
1295 | return ObservableValue;
|
1296 | }(Atom);
|
1297 | var isObservableValue = createInstanceofPredicate("ObservableValue", ObservableValue);
|
1298 |
|
1299 | var _Symbol$toPrimitive$1;
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 | _Symbol$toPrimitive$1 = Symbol.toPrimitive;
|
1320 | var ComputedValue = function () {
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 | |
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 | function ComputedValue(options) {
|
1341 | this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
|
1342 | this.observing_ = [];
|
1343 | this.newObserving_ = null;
|
1344 | this.isBeingObserved_ = false;
|
1345 | this.isPendingUnobservation_ = false;
|
1346 | this.observers_ = new Set();
|
1347 | this.diffValue_ = 0;
|
1348 | this.runId_ = 0;
|
1349 | this.lastAccessedBy_ = 0;
|
1350 | this.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
1351 | this.unboundDepsCount_ = 0;
|
1352 | this.value_ = new CaughtException(null);
|
1353 | this.name_ = void 0;
|
1354 | this.triggeredBy_ = void 0;
|
1355 | this.isComputing_ = false;
|
1356 | this.isRunningSetter_ = false;
|
1357 | this.derivation = void 0;
|
1358 | this.setter_ = void 0;
|
1359 | this.isTracing_ = TraceMode.NONE;
|
1360 | this.scope_ = void 0;
|
1361 | this.equals_ = void 0;
|
1362 | this.requiresReaction_ = void 0;
|
1363 | this.keepAlive_ = void 0;
|
1364 | this.onBOL = void 0;
|
1365 | this.onBUOL = void 0;
|
1366 | if (!options.get) {
|
1367 | die(31);
|
1368 | }
|
1369 | this.derivation = options.get;
|
1370 | this.name_ = options.name || (process.env.NODE_ENV !== "production" ? "ComputedValue@" + getNextId() : "ComputedValue");
|
1371 | if (options.set) {
|
1372 | this.setter_ = createAction(process.env.NODE_ENV !== "production" ? this.name_ + "-setter" : "ComputedValue-setter", options.set);
|
1373 | }
|
1374 | this.equals_ = options.equals || (options.compareStructural || options.struct ? comparer.structural : comparer["default"]);
|
1375 | this.scope_ = options.context;
|
1376 | this.requiresReaction_ = options.requiresReaction;
|
1377 | this.keepAlive_ = !!options.keepAlive;
|
1378 | }
|
1379 | var _proto = ComputedValue.prototype;
|
1380 | _proto.onBecomeStale_ = function onBecomeStale_() {
|
1381 | propagateMaybeChanged(this);
|
1382 | };
|
1383 | _proto.onBO = function onBO() {
|
1384 | if (this.onBOL) {
|
1385 | this.onBOL.forEach(function (listener) {
|
1386 | return listener();
|
1387 | });
|
1388 | }
|
1389 | };
|
1390 | _proto.onBUO = function onBUO() {
|
1391 | if (this.onBUOL) {
|
1392 | this.onBUOL.forEach(function (listener) {
|
1393 | return listener();
|
1394 | });
|
1395 | }
|
1396 | }
|
1397 | |
1398 |
|
1399 |
|
1400 | ;
|
1401 | _proto.get = function get() {
|
1402 | if (this.isComputing_) {
|
1403 | die(32, this.name_, this.derivation);
|
1404 | }
|
1405 | if (globalState.inBatch === 0 &&
|
1406 |
|
1407 | this.observers_.size === 0 && !this.keepAlive_) {
|
1408 | if (shouldCompute(this)) {
|
1409 | this.warnAboutUntrackedRead_();
|
1410 | startBatch();
|
1411 | this.value_ = this.computeValue_(false);
|
1412 | endBatch();
|
1413 | }
|
1414 | } else {
|
1415 | reportObserved(this);
|
1416 | if (shouldCompute(this)) {
|
1417 | var prevTrackingContext = globalState.trackingContext;
|
1418 | if (this.keepAlive_ && !prevTrackingContext) {
|
1419 | globalState.trackingContext = this;
|
1420 | }
|
1421 | if (this.trackAndCompute()) {
|
1422 | propagateChangeConfirmed(this);
|
1423 | }
|
1424 | globalState.trackingContext = prevTrackingContext;
|
1425 | }
|
1426 | }
|
1427 | var result = this.value_;
|
1428 | if (isCaughtException(result)) {
|
1429 | throw result.cause;
|
1430 | }
|
1431 | return result;
|
1432 | };
|
1433 | _proto.set = function set(value) {
|
1434 | if (this.setter_) {
|
1435 | if (this.isRunningSetter_) {
|
1436 | die(33, this.name_);
|
1437 | }
|
1438 | this.isRunningSetter_ = true;
|
1439 | try {
|
1440 | this.setter_.call(this.scope_, value);
|
1441 | } finally {
|
1442 | this.isRunningSetter_ = false;
|
1443 | }
|
1444 | } else {
|
1445 | die(34, this.name_);
|
1446 | }
|
1447 | };
|
1448 | _proto.trackAndCompute = function trackAndCompute() {
|
1449 |
|
1450 | var oldValue = this.value_;
|
1451 | var wasSuspended = this.dependenciesState_ === IDerivationState_.NOT_TRACKING_;
|
1452 | var newValue = this.computeValue_(true);
|
1453 | var changed = wasSuspended || isCaughtException(oldValue) || isCaughtException(newValue) || !this.equals_(oldValue, newValue);
|
1454 | if (changed) {
|
1455 | this.value_ = newValue;
|
1456 | if (process.env.NODE_ENV !== "production" && isSpyEnabled()) {
|
1457 | spyReport({
|
1458 | observableKind: "computed",
|
1459 | debugObjectName: this.name_,
|
1460 | object: this.scope_,
|
1461 | type: "update",
|
1462 | oldValue: oldValue,
|
1463 | newValue: newValue
|
1464 | });
|
1465 | }
|
1466 | }
|
1467 | return changed;
|
1468 | };
|
1469 | _proto.computeValue_ = function computeValue_(track) {
|
1470 | this.isComputing_ = true;
|
1471 |
|
1472 | var prev = allowStateChangesStart(false);
|
1473 | var res;
|
1474 | if (track) {
|
1475 | res = trackDerivedFunction(this, this.derivation, this.scope_);
|
1476 | } else {
|
1477 | if (globalState.disableErrorBoundaries === true) {
|
1478 | res = this.derivation.call(this.scope_);
|
1479 | } else {
|
1480 | try {
|
1481 | res = this.derivation.call(this.scope_);
|
1482 | } catch (e) {
|
1483 | res = new CaughtException(e);
|
1484 | }
|
1485 | }
|
1486 | }
|
1487 | allowStateChangesEnd(prev);
|
1488 | this.isComputing_ = false;
|
1489 | return res;
|
1490 | };
|
1491 | _proto.suspend_ = function suspend_() {
|
1492 | if (!this.keepAlive_) {
|
1493 | clearObserving(this);
|
1494 | this.value_ = undefined;
|
1495 | if (process.env.NODE_ENV !== "production" && this.isTracing_ !== TraceMode.NONE) {
|
1496 | console.log("[mobx.trace] Computed value '" + this.name_ + "' was suspended and it will recompute on the next access.");
|
1497 | }
|
1498 | }
|
1499 | };
|
1500 | _proto.observe_ = function observe_(listener, fireImmediately) {
|
1501 | var _this = this;
|
1502 | var firstTime = true;
|
1503 | var prevValue = undefined;
|
1504 | return autorun(function () {
|
1505 |
|
1506 | var newValue = _this.get();
|
1507 | if (!firstTime || fireImmediately) {
|
1508 | var prevU = untrackedStart();
|
1509 | listener({
|
1510 | observableKind: "computed",
|
1511 | debugObjectName: _this.name_,
|
1512 | type: UPDATE,
|
1513 | object: _this,
|
1514 | newValue: newValue,
|
1515 | oldValue: prevValue
|
1516 | });
|
1517 | untrackedEnd(prevU);
|
1518 | }
|
1519 | firstTime = false;
|
1520 | prevValue = newValue;
|
1521 | });
|
1522 | };
|
1523 | _proto.warnAboutUntrackedRead_ = function warnAboutUntrackedRead_() {
|
1524 | if (!(process.env.NODE_ENV !== "production")) {
|
1525 | return;
|
1526 | }
|
1527 | if (this.isTracing_ !== TraceMode.NONE) {
|
1528 | console.log("[mobx.trace] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
1529 | }
|
1530 | if (typeof this.requiresReaction_ === "boolean" ? this.requiresReaction_ : globalState.computedRequiresReaction) {
|
1531 | console.warn("[mobx] Computed value '" + this.name_ + "' is being read outside a reactive context. Doing a full recompute.");
|
1532 | }
|
1533 | };
|
1534 | _proto.toString = function toString() {
|
1535 | return this.name_ + "[" + this.derivation.toString() + "]";
|
1536 | };
|
1537 | _proto.valueOf = function valueOf() {
|
1538 | return toPrimitive(this.get());
|
1539 | };
|
1540 | _proto[_Symbol$toPrimitive$1] = function () {
|
1541 | return this.valueOf();
|
1542 | };
|
1543 | return ComputedValue;
|
1544 | }();
|
1545 | var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue);
|
1546 |
|
1547 | var IDerivationState_;
|
1548 | (function (IDerivationState_) {
|
1549 |
|
1550 |
|
1551 | IDerivationState_[IDerivationState_["NOT_TRACKING_"] = -1] = "NOT_TRACKING_";
|
1552 |
|
1553 |
|
1554 |
|
1555 | IDerivationState_[IDerivationState_["UP_TO_DATE_"] = 0] = "UP_TO_DATE_";
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 | IDerivationState_[IDerivationState_["POSSIBLY_STALE_"] = 1] = "POSSIBLY_STALE_";
|
1563 |
|
1564 |
|
1565 | IDerivationState_[IDerivationState_["STALE_"] = 2] = "STALE_";
|
1566 | })(IDerivationState_ || (IDerivationState_ = {}));
|
1567 | var TraceMode;
|
1568 | (function (TraceMode) {
|
1569 | TraceMode[TraceMode["NONE"] = 0] = "NONE";
|
1570 | TraceMode[TraceMode["LOG"] = 1] = "LOG";
|
1571 | TraceMode[TraceMode["BREAK"] = 2] = "BREAK";
|
1572 | })(TraceMode || (TraceMode = {}));
|
1573 | var CaughtException = function CaughtException(cause) {
|
1574 | this.cause = void 0;
|
1575 | this.cause = cause;
|
1576 |
|
1577 | };
|
1578 |
|
1579 | function isCaughtException(e) {
|
1580 | return e instanceof CaughtException;
|
1581 | }
|
1582 |
|
1583 |
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 | function shouldCompute(derivation) {
|
1594 | switch (derivation.dependenciesState_) {
|
1595 | case IDerivationState_.UP_TO_DATE_:
|
1596 | return false;
|
1597 | case IDerivationState_.NOT_TRACKING_:
|
1598 | case IDerivationState_.STALE_:
|
1599 | return true;
|
1600 | case IDerivationState_.POSSIBLY_STALE_:
|
1601 | {
|
1602 |
|
1603 | var prevAllowStateReads = allowStateReadsStart(true);
|
1604 | var prevUntracked = untrackedStart();
|
1605 | var obs = derivation.observing_,
|
1606 | l = obs.length;
|
1607 | for (var i = 0; i < l; i++) {
|
1608 | var obj = obs[i];
|
1609 | if (isComputedValue(obj)) {
|
1610 | if (globalState.disableErrorBoundaries) {
|
1611 | obj.get();
|
1612 | } else {
|
1613 | try {
|
1614 | obj.get();
|
1615 | } catch (e) {
|
1616 |
|
1617 | untrackedEnd(prevUntracked);
|
1618 | allowStateReadsEnd(prevAllowStateReads);
|
1619 | return true;
|
1620 | }
|
1621 | }
|
1622 |
|
1623 |
|
1624 |
|
1625 | if (derivation.dependenciesState_ === IDerivationState_.STALE_) {
|
1626 | untrackedEnd(prevUntracked);
|
1627 | allowStateReadsEnd(prevAllowStateReads);
|
1628 | return true;
|
1629 | }
|
1630 | }
|
1631 | }
|
1632 | changeDependenciesStateTo0(derivation);
|
1633 | untrackedEnd(prevUntracked);
|
1634 | allowStateReadsEnd(prevAllowStateReads);
|
1635 | return false;
|
1636 | }
|
1637 | }
|
1638 | }
|
1639 | function isComputingDerivation() {
|
1640 | return globalState.trackingDerivation !== null;
|
1641 | }
|
1642 |
|
1643 | function checkIfStateModificationsAreAllowed(atom) {
|
1644 | if (!(process.env.NODE_ENV !== "production")) {
|
1645 | return;
|
1646 | }
|
1647 | var hasObservers = atom.observers_.size > 0;
|
1648 |
|
1649 | if (!globalState.allowStateChanges && (hasObservers || globalState.enforceActions === "always")) {
|
1650 | console.warn("[MobX] " + (globalState.enforceActions ? "Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed. Tried to modify: " : "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, a computed value or the render function of a React component? You can wrap side effects in 'runInAction' (or decorate functions with 'action') if needed. Tried to modify: ") + atom.name_);
|
1651 | }
|
1652 | }
|
1653 | function checkIfStateReadsAreAllowed(observable) {
|
1654 | if (process.env.NODE_ENV !== "production" && !globalState.allowStateReads && globalState.observableRequiresReaction) {
|
1655 | console.warn("[mobx] Observable '" + observable.name_ + "' being read outside a reactive context.");
|
1656 | }
|
1657 | }
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 | function trackDerivedFunction(derivation, f, context) {
|
1664 | var prevAllowStateReads = allowStateReadsStart(true);
|
1665 |
|
1666 |
|
1667 | changeDependenciesStateTo0(derivation);
|
1668 | derivation.newObserving_ = new Array(derivation.observing_.length + 100);
|
1669 | derivation.unboundDepsCount_ = 0;
|
1670 | derivation.runId_ = ++globalState.runId;
|
1671 | var prevTracking = globalState.trackingDerivation;
|
1672 | globalState.trackingDerivation = derivation;
|
1673 | globalState.inBatch++;
|
1674 | var result;
|
1675 | if (globalState.disableErrorBoundaries === true) {
|
1676 | result = f.call(context);
|
1677 | } else {
|
1678 | try {
|
1679 | result = f.call(context);
|
1680 | } catch (e) {
|
1681 | result = new CaughtException(e);
|
1682 | }
|
1683 | }
|
1684 | globalState.inBatch--;
|
1685 | globalState.trackingDerivation = prevTracking;
|
1686 | bindDependencies(derivation);
|
1687 | warnAboutDerivationWithoutDependencies(derivation);
|
1688 | allowStateReadsEnd(prevAllowStateReads);
|
1689 | return result;
|
1690 | }
|
1691 | function warnAboutDerivationWithoutDependencies(derivation) {
|
1692 | if (!(process.env.NODE_ENV !== "production")) {
|
1693 | return;
|
1694 | }
|
1695 | if (derivation.observing_.length !== 0) {
|
1696 | return;
|
1697 | }
|
1698 | if (typeof derivation.requiresObservable_ === "boolean" ? derivation.requiresObservable_ : globalState.reactionRequiresObservable) {
|
1699 | console.warn("[mobx] Derivation '" + derivation.name_ + "' is created/updated without reading any observable value.");
|
1700 | }
|
1701 | }
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 | function bindDependencies(derivation) {
|
1708 |
|
1709 | var prevObserving = derivation.observing_;
|
1710 | var observing = derivation.observing_ = derivation.newObserving_;
|
1711 | var lowestNewObservingDerivationState = IDerivationState_.UP_TO_DATE_;
|
1712 |
|
1713 |
|
1714 |
|
1715 | var i0 = 0,
|
1716 | l = derivation.unboundDepsCount_;
|
1717 | for (var i = 0; i < l; i++) {
|
1718 | var dep = observing[i];
|
1719 | if (dep.diffValue_ === 0) {
|
1720 | dep.diffValue_ = 1;
|
1721 | if (i0 !== i) {
|
1722 | observing[i0] = dep;
|
1723 | }
|
1724 | i0++;
|
1725 | }
|
1726 |
|
1727 |
|
1728 | if (dep.dependenciesState_ > lowestNewObservingDerivationState) {
|
1729 | lowestNewObservingDerivationState = dep.dependenciesState_;
|
1730 | }
|
1731 | }
|
1732 | observing.length = i0;
|
1733 | derivation.newObserving_ = null;
|
1734 |
|
1735 |
|
1736 |
|
1737 | l = prevObserving.length;
|
1738 | while (l--) {
|
1739 | var _dep = prevObserving[l];
|
1740 | if (_dep.diffValue_ === 0) {
|
1741 | removeObserver(_dep, derivation);
|
1742 | }
|
1743 | _dep.diffValue_ = 0;
|
1744 | }
|
1745 |
|
1746 |
|
1747 |
|
1748 | while (i0--) {
|
1749 | var _dep2 = observing[i0];
|
1750 | if (_dep2.diffValue_ === 1) {
|
1751 | _dep2.diffValue_ = 0;
|
1752 | addObserver(_dep2, derivation);
|
1753 | }
|
1754 | }
|
1755 |
|
1756 |
|
1757 | if (lowestNewObservingDerivationState !== IDerivationState_.UP_TO_DATE_) {
|
1758 | derivation.dependenciesState_ = lowestNewObservingDerivationState;
|
1759 | derivation.onBecomeStale_();
|
1760 | }
|
1761 | }
|
1762 | function clearObserving(derivation) {
|
1763 |
|
1764 | var obs = derivation.observing_;
|
1765 | derivation.observing_ = [];
|
1766 | var i = obs.length;
|
1767 | while (i--) {
|
1768 | removeObserver(obs[i], derivation);
|
1769 | }
|
1770 | derivation.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
|
1771 | }
|
1772 | function untracked(action) {
|
1773 | var prev = untrackedStart();
|
1774 | try {
|
1775 | return action();
|
1776 | } finally {
|
1777 | untrackedEnd(prev);
|
1778 | }
|
1779 | }
|
1780 | function untrackedStart() {
|
1781 | var prev = globalState.trackingDerivation;
|
1782 | globalState.trackingDerivation = null;
|
1783 | return prev;
|
1784 | }
|
1785 | function untrackedEnd(prev) {
|
1786 | globalState.trackingDerivation = prev;
|
1787 | }
|
1788 | function allowStateReadsStart(allowStateReads) {
|
1789 | var prev = globalState.allowStateReads;
|
1790 | globalState.allowStateReads = allowStateReads;
|
1791 | return prev;
|
1792 | }
|
1793 | function allowStateReadsEnd(prev) {
|
1794 | globalState.allowStateReads = prev;
|
1795 | }
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 | function changeDependenciesStateTo0(derivation) {
|
1801 | if (derivation.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
1802 | return;
|
1803 | }
|
1804 | derivation.dependenciesState_ = IDerivationState_.UP_TO_DATE_;
|
1805 | var obs = derivation.observing_;
|
1806 | var i = obs.length;
|
1807 | while (i--) {
|
1808 | obs[i].lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
1809 | }
|
1810 | }
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 | var persistentKeys = ["mobxGuid", "spyListeners", "enforceActions", "computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "allowStateReads", "disableErrorBoundaries", "runId", "UNCHANGED", "useProxies"];
|
1816 | var MobXGlobals = function MobXGlobals() {
|
1817 | this.version = 6;
|
1818 | this.UNCHANGED = {};
|
1819 | this.trackingDerivation = null;
|
1820 | this.trackingContext = null;
|
1821 | this.runId = 0;
|
1822 | this.mobxGuid = 0;
|
1823 | this.inBatch = 0;
|
1824 | this.pendingUnobservations = [];
|
1825 | this.pendingReactions = [];
|
1826 | this.isRunningReactions = false;
|
1827 | this.allowStateChanges = false;
|
1828 | this.allowStateReads = true;
|
1829 | this.enforceActions = true;
|
1830 | this.spyListeners = [];
|
1831 | this.globalReactionErrorHandlers = [];
|
1832 | this.computedRequiresReaction = false;
|
1833 | this.reactionRequiresObservable = false;
|
1834 | this.observableRequiresReaction = false;
|
1835 | this.disableErrorBoundaries = false;
|
1836 | this.suppressReactionErrors = false;
|
1837 | this.useProxies = true;
|
1838 | this.verifyProxies = false;
|
1839 | this.safeDescriptors = true;
|
1840 | this.stateVersion = Number.MIN_SAFE_INTEGER;
|
1841 | };
|
1842 | var canMergeGlobalState = true;
|
1843 | var isolateCalled = false;
|
1844 | var globalState = function () {
|
1845 | var global = getGlobal();
|
1846 | if (global.__mobxInstanceCount > 0 && !global.__mobxGlobals) {
|
1847 | canMergeGlobalState = false;
|
1848 | }
|
1849 | if (global.__mobxGlobals && global.__mobxGlobals.version !== new MobXGlobals().version) {
|
1850 | canMergeGlobalState = false;
|
1851 | }
|
1852 | if (!canMergeGlobalState) {
|
1853 |
|
1854 |
|
1855 | setTimeout(function () {
|
1856 | if (!isolateCalled) {
|
1857 | die(35);
|
1858 | }
|
1859 | }, 1);
|
1860 | return new MobXGlobals();
|
1861 | } else if (global.__mobxGlobals) {
|
1862 | global.__mobxInstanceCount += 1;
|
1863 | if (!global.__mobxGlobals.UNCHANGED) {
|
1864 | global.__mobxGlobals.UNCHANGED = {};
|
1865 | }
|
1866 | return global.__mobxGlobals;
|
1867 | } else {
|
1868 | global.__mobxInstanceCount = 1;
|
1869 | return global.__mobxGlobals = new MobXGlobals();
|
1870 | }
|
1871 | }();
|
1872 | function isolateGlobalState() {
|
1873 | if (globalState.pendingReactions.length || globalState.inBatch || globalState.isRunningReactions) {
|
1874 | die(36);
|
1875 | }
|
1876 | isolateCalled = true;
|
1877 | if (canMergeGlobalState) {
|
1878 | var global = getGlobal();
|
1879 | if (--global.__mobxInstanceCount === 0) {
|
1880 | global.__mobxGlobals = undefined;
|
1881 | }
|
1882 | globalState = new MobXGlobals();
|
1883 | }
|
1884 | }
|
1885 | function getGlobalState() {
|
1886 | return globalState;
|
1887 | }
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 | function resetGlobalState() {
|
1893 | var defaultGlobals = new MobXGlobals();
|
1894 | for (var key in defaultGlobals) {
|
1895 | if (persistentKeys.indexOf(key) === -1) {
|
1896 | globalState[key] = defaultGlobals[key];
|
1897 | }
|
1898 | }
|
1899 | globalState.allowStateChanges = !globalState.enforceActions;
|
1900 | }
|
1901 |
|
1902 | function hasObservers(observable) {
|
1903 | return observable.observers_ && observable.observers_.size > 0;
|
1904 | }
|
1905 | function getObservers(observable) {
|
1906 | return observable.observers_;
|
1907 | }
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 | function addObserver(observable, node) {
|
1926 |
|
1927 |
|
1928 |
|
1929 | observable.observers_.add(node);
|
1930 | if (observable.lowestObserverState_ > node.dependenciesState_) {
|
1931 | observable.lowestObserverState_ = node.dependenciesState_;
|
1932 | }
|
1933 |
|
1934 |
|
1935 | }
|
1936 |
|
1937 | function removeObserver(observable, node) {
|
1938 |
|
1939 |
|
1940 |
|
1941 | observable.observers_["delete"](node);
|
1942 | if (observable.observers_.size === 0) {
|
1943 |
|
1944 | queueForUnobservation(observable);
|
1945 | }
|
1946 |
|
1947 |
|
1948 | }
|
1949 |
|
1950 | function queueForUnobservation(observable) {
|
1951 | if (observable.isPendingUnobservation_ === false) {
|
1952 |
|
1953 | observable.isPendingUnobservation_ = true;
|
1954 | globalState.pendingUnobservations.push(observable);
|
1955 | }
|
1956 | }
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 | function startBatch() {
|
1963 | globalState.inBatch++;
|
1964 | }
|
1965 | function endBatch() {
|
1966 | if (--globalState.inBatch === 0) {
|
1967 | runReactions();
|
1968 |
|
1969 | var list = globalState.pendingUnobservations;
|
1970 | for (var i = 0; i < list.length; i++) {
|
1971 | var observable = list[i];
|
1972 | observable.isPendingUnobservation_ = false;
|
1973 | if (observable.observers_.size === 0) {
|
1974 | if (observable.isBeingObserved_) {
|
1975 |
|
1976 | observable.isBeingObserved_ = false;
|
1977 | observable.onBUO();
|
1978 | }
|
1979 | if (observable instanceof ComputedValue) {
|
1980 |
|
1981 |
|
1982 | observable.suspend_();
|
1983 | }
|
1984 | }
|
1985 | }
|
1986 | globalState.pendingUnobservations = [];
|
1987 | }
|
1988 | }
|
1989 | function reportObserved(observable) {
|
1990 | checkIfStateReadsAreAllowed(observable);
|
1991 | var derivation = globalState.trackingDerivation;
|
1992 | if (derivation !== null) {
|
1993 | |
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 | if (derivation.runId_ !== observable.lastAccessedBy_) {
|
1999 | observable.lastAccessedBy_ = derivation.runId_;
|
2000 |
|
2001 | derivation.newObserving_[derivation.unboundDepsCount_++] = observable;
|
2002 | if (!observable.isBeingObserved_ && globalState.trackingContext) {
|
2003 | observable.isBeingObserved_ = true;
|
2004 | observable.onBO();
|
2005 | }
|
2006 | }
|
2007 | return observable.isBeingObserved_;
|
2008 | } else if (observable.observers_.size === 0 && globalState.inBatch > 0) {
|
2009 | queueForUnobservation(observable);
|
2010 | }
|
2011 | return false;
|
2012 | }
|
2013 |
|
2014 |
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 |
|
2021 |
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 | function propagateChanged(observable) {
|
2035 |
|
2036 | if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
2037 | return;
|
2038 | }
|
2039 | observable.lowestObserverState_ = IDerivationState_.STALE_;
|
2040 |
|
2041 | observable.observers_.forEach(function (d) {
|
2042 | if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
2043 | if (process.env.NODE_ENV !== "production" && d.isTracing_ !== TraceMode.NONE) {
|
2044 | logTraceInfo(d, observable);
|
2045 | }
|
2046 | d.onBecomeStale_();
|
2047 | }
|
2048 | d.dependenciesState_ = IDerivationState_.STALE_;
|
2049 | });
|
2050 |
|
2051 | }
|
2052 |
|
2053 | function propagateChangeConfirmed(observable) {
|
2054 |
|
2055 | if (observable.lowestObserverState_ === IDerivationState_.STALE_) {
|
2056 | return;
|
2057 | }
|
2058 | observable.lowestObserverState_ = IDerivationState_.STALE_;
|
2059 | observable.observers_.forEach(function (d) {
|
2060 | if (d.dependenciesState_ === IDerivationState_.POSSIBLY_STALE_) {
|
2061 | d.dependenciesState_ = IDerivationState_.STALE_;
|
2062 | if (process.env.NODE_ENV !== "production" && d.isTracing_ !== TraceMode.NONE) {
|
2063 | logTraceInfo(d, observable);
|
2064 | }
|
2065 | } else if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_
|
2066 | ) {
|
2067 | observable.lowestObserverState_ = IDerivationState_.UP_TO_DATE_;
|
2068 | }
|
2069 | });
|
2070 |
|
2071 | }
|
2072 |
|
2073 | function propagateMaybeChanged(observable) {
|
2074 |
|
2075 | if (observable.lowestObserverState_ !== IDerivationState_.UP_TO_DATE_) {
|
2076 | return;
|
2077 | }
|
2078 | observable.lowestObserverState_ = IDerivationState_.POSSIBLY_STALE_;
|
2079 | observable.observers_.forEach(function (d) {
|
2080 | if (d.dependenciesState_ === IDerivationState_.UP_TO_DATE_) {
|
2081 | d.dependenciesState_ = IDerivationState_.POSSIBLY_STALE_;
|
2082 | d.onBecomeStale_();
|
2083 | }
|
2084 | });
|
2085 |
|
2086 | }
|
2087 |
|
2088 | function logTraceInfo(derivation, observable) {
|
2089 | console.log("[mobx.trace] '" + derivation.name_ + "' is invalidated due to a change in: '" + observable.name_ + "'");
|
2090 | if (derivation.isTracing_ === TraceMode.BREAK) {
|
2091 | var lines = [];
|
2092 | printDepTree(getDependencyTree(derivation), lines, 1);
|
2093 |
|
2094 | new Function("debugger;\n/*\nTracing '" + derivation.name_ + "'\n\nYou are entering this break point because derivation '" + derivation.name_ + "' is being traced and '" + observable.name_ + "' is now forcing it to update.\nJust follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update\nThe stackframe you are looking for is at least ~6-8 stack-frames up.\n\n" + (derivation instanceof ComputedValue ? derivation.derivation.toString().replace(/[*]\//g, "/") : "") + "\n\nThe dependencies for this derivation are:\n\n" + lines.join("\n") + "\n*/\n ")();
|
2095 | }
|
2096 | }
|
2097 | function printDepTree(tree, lines, depth) {
|
2098 | if (lines.length >= 1000) {
|
2099 | lines.push("(and many more)");
|
2100 | return;
|
2101 | }
|
2102 | lines.push("" + "\t".repeat(depth - 1) + tree.name);
|
2103 | if (tree.dependencies) {
|
2104 | tree.dependencies.forEach(function (child) {
|
2105 | return printDepTree(child, lines, depth + 1);
|
2106 | });
|
2107 | }
|
2108 | }
|
2109 |
|
2110 | var Reaction = function () {
|
2111 |
|
2112 |
|
2113 | function Reaction(name_, onInvalidate_, errorHandler_, requiresObservable_) {
|
2114 | if (name_ === void 0) {
|
2115 | name_ = process.env.NODE_ENV !== "production" ? "Reaction@" + getNextId() : "Reaction";
|
2116 | }
|
2117 | this.name_ = void 0;
|
2118 | this.onInvalidate_ = void 0;
|
2119 | this.errorHandler_ = void 0;
|
2120 | this.requiresObservable_ = void 0;
|
2121 | this.observing_ = [];
|
2122 | this.newObserving_ = [];
|
2123 | this.dependenciesState_ = IDerivationState_.NOT_TRACKING_;
|
2124 | this.diffValue_ = 0;
|
2125 | this.runId_ = 0;
|
2126 | this.unboundDepsCount_ = 0;
|
2127 | this.isDisposed_ = false;
|
2128 | this.isScheduled_ = false;
|
2129 | this.isTrackPending_ = false;
|
2130 | this.isRunning_ = false;
|
2131 | this.isTracing_ = TraceMode.NONE;
|
2132 | this.name_ = name_;
|
2133 | this.onInvalidate_ = onInvalidate_;
|
2134 | this.errorHandler_ = errorHandler_;
|
2135 | this.requiresObservable_ = requiresObservable_;
|
2136 | }
|
2137 | var _proto = Reaction.prototype;
|
2138 | _proto.onBecomeStale_ = function onBecomeStale_() {
|
2139 | this.schedule_();
|
2140 | };
|
2141 | _proto.schedule_ = function schedule_() {
|
2142 | if (!this.isScheduled_) {
|
2143 | this.isScheduled_ = true;
|
2144 | globalState.pendingReactions.push(this);
|
2145 | runReactions();
|
2146 | }
|
2147 | };
|
2148 | _proto.isScheduled = function isScheduled() {
|
2149 | return this.isScheduled_;
|
2150 | }
|
2151 | |
2152 |
|
2153 | ;
|
2154 | _proto.runReaction_ = function runReaction_() {
|
2155 | if (!this.isDisposed_) {
|
2156 | startBatch();
|
2157 | this.isScheduled_ = false;
|
2158 | var prev = globalState.trackingContext;
|
2159 | globalState.trackingContext = this;
|
2160 | if (shouldCompute(this)) {
|
2161 | this.isTrackPending_ = true;
|
2162 | try {
|
2163 | this.onInvalidate_();
|
2164 | if (process.env.NODE_ENV !== "production" && this.isTrackPending_ && isSpyEnabled()) {
|
2165 |
|
2166 | spyReport({
|
2167 | name: this.name_,
|
2168 | type: "scheduled-reaction"
|
2169 | });
|
2170 | }
|
2171 | } catch (e) {
|
2172 | this.reportExceptionInDerivation_(e);
|
2173 | }
|
2174 | }
|
2175 | globalState.trackingContext = prev;
|
2176 | endBatch();
|
2177 | }
|
2178 | };
|
2179 | _proto.track = function track(fn) {
|
2180 | if (this.isDisposed_) {
|
2181 | return;
|
2182 |
|
2183 | }
|
2184 |
|
2185 | startBatch();
|
2186 | var notify = isSpyEnabled();
|
2187 | var startTime;
|
2188 | if (process.env.NODE_ENV !== "production" && notify) {
|
2189 | startTime = Date.now();
|
2190 | spyReportStart({
|
2191 | name: this.name_,
|
2192 | type: "reaction"
|
2193 | });
|
2194 | }
|
2195 | this.isRunning_ = true;
|
2196 | var prevReaction = globalState.trackingContext;
|
2197 | globalState.trackingContext = this;
|
2198 | var result = trackDerivedFunction(this, fn, undefined);
|
2199 | globalState.trackingContext = prevReaction;
|
2200 | this.isRunning_ = false;
|
2201 | this.isTrackPending_ = false;
|
2202 | if (this.isDisposed_) {
|
2203 |
|
2204 | clearObserving(this);
|
2205 | }
|
2206 | if (isCaughtException(result)) {
|
2207 | this.reportExceptionInDerivation_(result.cause);
|
2208 | }
|
2209 | if (process.env.NODE_ENV !== "production" && notify) {
|
2210 | spyReportEnd({
|
2211 | time: Date.now() - startTime
|
2212 | });
|
2213 | }
|
2214 | endBatch();
|
2215 | };
|
2216 | _proto.reportExceptionInDerivation_ = function reportExceptionInDerivation_(error) {
|
2217 | var _this = this;
|
2218 | if (this.errorHandler_) {
|
2219 | this.errorHandler_(error, this);
|
2220 | return;
|
2221 | }
|
2222 | if (globalState.disableErrorBoundaries) {
|
2223 | throw error;
|
2224 | }
|
2225 | var message = process.env.NODE_ENV !== "production" ? "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this + "'" : "[mobx] uncaught error in '" + this + "'";
|
2226 | if (!globalState.suppressReactionErrors) {
|
2227 | console.error(message, error);
|
2228 |
|
2229 | } else if (process.env.NODE_ENV !== "production") {
|
2230 | console.warn("[mobx] (error in reaction '" + this.name_ + "' suppressed, fix error of causing action below)");
|
2231 | }
|
2232 | if (process.env.NODE_ENV !== "production" && isSpyEnabled()) {
|
2233 | spyReport({
|
2234 | type: "error",
|
2235 | name: this.name_,
|
2236 | message: message,
|
2237 | error: "" + error
|
2238 | });
|
2239 | }
|
2240 | globalState.globalReactionErrorHandlers.forEach(function (f) {
|
2241 | return f(error, _this);
|
2242 | });
|
2243 | };
|
2244 | _proto.dispose = function dispose() {
|
2245 | if (!this.isDisposed_) {
|
2246 | this.isDisposed_ = true;
|
2247 | if (!this.isRunning_) {
|
2248 |
|
2249 | startBatch();
|
2250 | clearObserving(this);
|
2251 | endBatch();
|
2252 | }
|
2253 | }
|
2254 | };
|
2255 | _proto.getDisposer_ = function getDisposer_(abortSignal) {
|
2256 | var _this2 = this;
|
2257 | var dispose = function dispose() {
|
2258 | _this2.dispose();
|
2259 | abortSignal == null ? void 0 : abortSignal.removeEventListener == null ? void 0 : abortSignal.removeEventListener("abort", dispose);
|
2260 | };
|
2261 | abortSignal == null ? void 0 : abortSignal.addEventListener == null ? void 0 : abortSignal.addEventListener("abort", dispose);
|
2262 | dispose[$mobx] = this;
|
2263 | return dispose;
|
2264 | };
|
2265 | _proto.toString = function toString() {
|
2266 | return "Reaction[" + this.name_ + "]";
|
2267 | };
|
2268 | _proto.trace = function trace$1(enterBreakPoint) {
|
2269 | if (enterBreakPoint === void 0) {
|
2270 | enterBreakPoint = false;
|
2271 | }
|
2272 | trace(this, enterBreakPoint);
|
2273 | };
|
2274 | return Reaction;
|
2275 | }();
|
2276 | function onReactionError(handler) {
|
2277 | globalState.globalReactionErrorHandlers.push(handler);
|
2278 | return function () {
|
2279 | var idx = globalState.globalReactionErrorHandlers.indexOf(handler);
|
2280 | if (idx >= 0) {
|
2281 | globalState.globalReactionErrorHandlers.splice(idx, 1);
|
2282 | }
|
2283 | };
|
2284 | }
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 | var MAX_REACTION_ITERATIONS = 100;
|
2291 | var reactionScheduler = function reactionScheduler(f) {
|
2292 | return f();
|
2293 | };
|
2294 | function runReactions() {
|
2295 |
|
2296 | if (globalState.inBatch > 0 || globalState.isRunningReactions) {
|
2297 | return;
|
2298 | }
|
2299 | reactionScheduler(runReactionsHelper);
|
2300 | }
|
2301 | function runReactionsHelper() {
|
2302 | globalState.isRunningReactions = true;
|
2303 | var allReactions = globalState.pendingReactions;
|
2304 | var iterations = 0;
|
2305 |
|
2306 |
|
2307 |
|
2308 | while (allReactions.length > 0) {
|
2309 | if (++iterations === MAX_REACTION_ITERATIONS) {
|
2310 | console.error(process.env.NODE_ENV !== "production" ? "Reaction doesn't converge to a stable state after " + MAX_REACTION_ITERATIONS + " iterations." + (" Probably there is a cycle in the reactive function: " + allReactions[0]) : "[mobx] cycle in reaction: " + allReactions[0]);
|
2311 | allReactions.splice(0);
|
2312 | }
|
2313 |
|
2314 | var remainingReactions = allReactions.splice(0);
|
2315 | for (var i = 0, l = remainingReactions.length; i < l; i++) {
|
2316 | remainingReactions[i].runReaction_();
|
2317 | }
|
2318 | }
|
2319 | globalState.isRunningReactions = false;
|
2320 | }
|
2321 | var isReaction = createInstanceofPredicate("Reaction", Reaction);
|
2322 | function setReactionScheduler(fn) {
|
2323 | var baseScheduler = reactionScheduler;
|
2324 | reactionScheduler = function reactionScheduler(f) {
|
2325 | return fn(function () {
|
2326 | return baseScheduler(f);
|
2327 | });
|
2328 | };
|
2329 | }
|
2330 |
|
2331 | function isSpyEnabled() {
|
2332 | return process.env.NODE_ENV !== "production" && !!globalState.spyListeners.length;
|
2333 | }
|
2334 | function spyReport(event) {
|
2335 | if (!(process.env.NODE_ENV !== "production")) {
|
2336 | return;
|
2337 | }
|
2338 | if (!globalState.spyListeners.length) {
|
2339 | return;
|
2340 | }
|
2341 | var listeners = globalState.spyListeners;
|
2342 | for (var i = 0, l = listeners.length; i < l; i++) {
|
2343 | listeners[i](event);
|
2344 | }
|
2345 | }
|
2346 | function spyReportStart(event) {
|
2347 | if (!(process.env.NODE_ENV !== "production")) {
|
2348 | return;
|
2349 | }
|
2350 | var change = _extends({}, event, {
|
2351 | spyReportStart: true
|
2352 | });
|
2353 | spyReport(change);
|
2354 | }
|
2355 | var END_EVENT = {
|
2356 | type: "report-end",
|
2357 | spyReportEnd: true
|
2358 | };
|
2359 | function spyReportEnd(change) {
|
2360 | if (!(process.env.NODE_ENV !== "production")) {
|
2361 | return;
|
2362 | }
|
2363 | if (change) {
|
2364 | spyReport(_extends({}, change, {
|
2365 | type: "report-end",
|
2366 | spyReportEnd: true
|
2367 | }));
|
2368 | } else {
|
2369 | spyReport(END_EVENT);
|
2370 | }
|
2371 | }
|
2372 | function spy(listener) {
|
2373 | if (!(process.env.NODE_ENV !== "production")) {
|
2374 | console.warn("[mobx.spy] Is a no-op in production builds");
|
2375 | return function () {};
|
2376 | } else {
|
2377 | globalState.spyListeners.push(listener);
|
2378 | return once(function () {
|
2379 | globalState.spyListeners = globalState.spyListeners.filter(function (l) {
|
2380 | return l !== listener;
|
2381 | });
|
2382 | });
|
2383 | }
|
2384 | }
|
2385 |
|
2386 | var ACTION = "action";
|
2387 | var ACTION_BOUND = "action.bound";
|
2388 | var AUTOACTION = "autoAction";
|
2389 | var AUTOACTION_BOUND = "autoAction.bound";
|
2390 | var DEFAULT_ACTION_NAME = "<unnamed action>";
|
2391 | var actionAnnotation = createActionAnnotation(ACTION);
|
2392 | var actionBoundAnnotation = createActionAnnotation(ACTION_BOUND, {
|
2393 | bound: true
|
2394 | });
|
2395 | var autoActionAnnotation = createActionAnnotation(AUTOACTION, {
|
2396 | autoAction: true
|
2397 | });
|
2398 | var autoActionBoundAnnotation = createActionAnnotation(AUTOACTION_BOUND, {
|
2399 | autoAction: true,
|
2400 | bound: true
|
2401 | });
|
2402 | function createActionFactory(autoAction) {
|
2403 | var res = function action(arg1, arg2) {
|
2404 |
|
2405 | if (isFunction(arg1)) {
|
2406 | return createAction(arg1.name || DEFAULT_ACTION_NAME, arg1, autoAction);
|
2407 | }
|
2408 |
|
2409 | if (isFunction(arg2)) {
|
2410 | return createAction(arg1, arg2, autoAction);
|
2411 | }
|
2412 |
|
2413 | if (isStringish(arg2)) {
|
2414 | return storeAnnotation(arg1, arg2, autoAction ? autoActionAnnotation : actionAnnotation);
|
2415 | }
|
2416 |
|
2417 | if (isStringish(arg1)) {
|
2418 | return createDecoratorAnnotation(createActionAnnotation(autoAction ? AUTOACTION : ACTION, {
|
2419 | name: arg1,
|
2420 | autoAction: autoAction
|
2421 | }));
|
2422 | }
|
2423 | if (process.env.NODE_ENV !== "production") {
|
2424 | die("Invalid arguments for `action`");
|
2425 | }
|
2426 | };
|
2427 | return res;
|
2428 | }
|
2429 | var action = createActionFactory(false);
|
2430 | Object.assign(action, actionAnnotation);
|
2431 | var autoAction = createActionFactory(true);
|
2432 | Object.assign(autoAction, autoActionAnnotation);
|
2433 | action.bound = createDecoratorAnnotation(actionBoundAnnotation);
|
2434 | autoAction.bound = createDecoratorAnnotation(autoActionBoundAnnotation);
|
2435 | function runInAction(fn) {
|
2436 | return executeAction(fn.name || DEFAULT_ACTION_NAME, false, fn, this, undefined);
|
2437 | }
|
2438 | function isAction(thing) {
|
2439 | return isFunction(thing) && thing.isMobxAction === true;
|
2440 | }
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 | function autorun(view, opts) {
|
2449 | var _opts$name, _opts, _opts2, _opts2$signal, _opts3;
|
2450 | if (opts === void 0) {
|
2451 | opts = EMPTY_OBJECT;
|
2452 | }
|
2453 | if (process.env.NODE_ENV !== "production") {
|
2454 | if (!isFunction(view)) {
|
2455 | die("Autorun expects a function as first argument");
|
2456 | }
|
2457 | if (isAction(view)) {
|
2458 | die("Autorun does not accept actions since actions are untrackable");
|
2459 | }
|
2460 | }
|
2461 | var name = (_opts$name = (_opts = opts) == null ? void 0 : _opts.name) != null ? _opts$name : process.env.NODE_ENV !== "production" ? view.name || "Autorun@" + getNextId() : "Autorun";
|
2462 | var runSync = !opts.scheduler && !opts.delay;
|
2463 | var reaction;
|
2464 | if (runSync) {
|
2465 |
|
2466 | reaction = new Reaction(name, function () {
|
2467 | this.track(reactionRunner);
|
2468 | }, opts.onError, opts.requiresObservable);
|
2469 | } else {
|
2470 | var scheduler = createSchedulerFromOptions(opts);
|
2471 |
|
2472 | var isScheduled = false;
|
2473 | reaction = new Reaction(name, function () {
|
2474 | if (!isScheduled) {
|
2475 | isScheduled = true;
|
2476 | scheduler(function () {
|
2477 | isScheduled = false;
|
2478 | if (!reaction.isDisposed_) {
|
2479 | reaction.track(reactionRunner);
|
2480 | }
|
2481 | });
|
2482 | }
|
2483 | }, opts.onError, opts.requiresObservable);
|
2484 | }
|
2485 | function reactionRunner() {
|
2486 | view(reaction);
|
2487 | }
|
2488 | if (!((_opts2 = opts) != null && (_opts2$signal = _opts2.signal) != null && _opts2$signal.aborted)) {
|
2489 | reaction.schedule_();
|
2490 | }
|
2491 | return reaction.getDisposer_((_opts3 = opts) == null ? void 0 : _opts3.signal);
|
2492 | }
|
2493 | var run = function run(f) {
|
2494 | return f();
|
2495 | };
|
2496 | function createSchedulerFromOptions(opts) {
|
2497 | return opts.scheduler ? opts.scheduler : opts.delay ? function (f) {
|
2498 | return setTimeout(f, opts.delay);
|
2499 | } : run;
|
2500 | }
|
2501 | function reaction(expression, effect, opts) {
|
2502 | var _opts$name2, _opts4, _opts4$signal, _opts5;
|
2503 | if (opts === void 0) {
|
2504 | opts = EMPTY_OBJECT;
|
2505 | }
|
2506 | if (process.env.NODE_ENV !== "production") {
|
2507 | if (!isFunction(expression) || !isFunction(effect)) {
|
2508 | die("First and second argument to reaction should be functions");
|
2509 | }
|
2510 | if (!isPlainObject(opts)) {
|
2511 | die("Third argument of reactions should be an object");
|
2512 | }
|
2513 | }
|
2514 | var name = (_opts$name2 = opts.name) != null ? _opts$name2 : process.env.NODE_ENV !== "production" ? "Reaction@" + getNextId() : "Reaction";
|
2515 | var effectAction = action(name, opts.onError ? wrapErrorHandler(opts.onError, effect) : effect);
|
2516 | var runSync = !opts.scheduler && !opts.delay;
|
2517 | var scheduler = createSchedulerFromOptions(opts);
|
2518 | var firstTime = true;
|
2519 | var isScheduled = false;
|
2520 | var value;
|
2521 | var oldValue;
|
2522 | var equals = opts.compareStructural ? comparer.structural : opts.equals || comparer["default"];
|
2523 | var r = new Reaction(name, function () {
|
2524 | if (firstTime || runSync) {
|
2525 | reactionRunner();
|
2526 | } else if (!isScheduled) {
|
2527 | isScheduled = true;
|
2528 | scheduler(reactionRunner);
|
2529 | }
|
2530 | }, opts.onError, opts.requiresObservable);
|
2531 | function reactionRunner() {
|
2532 | isScheduled = false;
|
2533 | if (r.isDisposed_) {
|
2534 | return;
|
2535 | }
|
2536 | var changed = false;
|
2537 | r.track(function () {
|
2538 | var nextValue = allowStateChanges(false, function () {
|
2539 | return expression(r);
|
2540 | });
|
2541 | changed = firstTime || !equals(value, nextValue);
|
2542 | oldValue = value;
|
2543 | value = nextValue;
|
2544 | });
|
2545 | if (firstTime && opts.fireImmediately) {
|
2546 | effectAction(value, oldValue, r);
|
2547 | } else if (!firstTime && changed) {
|
2548 | effectAction(value, oldValue, r);
|
2549 | }
|
2550 | firstTime = false;
|
2551 | }
|
2552 | if (!((_opts4 = opts) != null && (_opts4$signal = _opts4.signal) != null && _opts4$signal.aborted)) {
|
2553 | r.schedule_();
|
2554 | }
|
2555 | return r.getDisposer_((_opts5 = opts) == null ? void 0 : _opts5.signal);
|
2556 | }
|
2557 | function wrapErrorHandler(errorHandler, baseFn) {
|
2558 | return function () {
|
2559 | try {
|
2560 | return baseFn.apply(this, arguments);
|
2561 | } catch (e) {
|
2562 | errorHandler.call(this, e);
|
2563 | }
|
2564 | };
|
2565 | }
|
2566 |
|
2567 | var ON_BECOME_OBSERVED = "onBO";
|
2568 | var ON_BECOME_UNOBSERVED = "onBUO";
|
2569 | function onBecomeObserved(thing, arg2, arg3) {
|
2570 | return interceptHook(ON_BECOME_OBSERVED, thing, arg2, arg3);
|
2571 | }
|
2572 | function onBecomeUnobserved(thing, arg2, arg3) {
|
2573 | return interceptHook(ON_BECOME_UNOBSERVED, thing, arg2, arg3);
|
2574 | }
|
2575 | function interceptHook(hook, thing, arg2, arg3) {
|
2576 | var atom = typeof arg3 === "function" ? getAtom(thing, arg2) : getAtom(thing);
|
2577 | var cb = isFunction(arg3) ? arg3 : arg2;
|
2578 | var listenersKey = hook + "L";
|
2579 | if (atom[listenersKey]) {
|
2580 | atom[listenersKey].add(cb);
|
2581 | } else {
|
2582 | atom[listenersKey] = new Set([cb]);
|
2583 | }
|
2584 | return function () {
|
2585 | var hookListeners = atom[listenersKey];
|
2586 | if (hookListeners) {
|
2587 | hookListeners["delete"](cb);
|
2588 | if (hookListeners.size === 0) {
|
2589 | delete atom[listenersKey];
|
2590 | }
|
2591 | }
|
2592 | };
|
2593 | }
|
2594 |
|
2595 | var NEVER = "never";
|
2596 | var ALWAYS = "always";
|
2597 | var OBSERVED = "observed";
|
2598 |
|
2599 | function configure(options) {
|
2600 | if (options.isolateGlobalState === true) {
|
2601 | isolateGlobalState();
|
2602 | }
|
2603 | var useProxies = options.useProxies,
|
2604 | enforceActions = options.enforceActions;
|
2605 | if (useProxies !== undefined) {
|
2606 | globalState.useProxies = useProxies === ALWAYS ? true : useProxies === NEVER ? false : typeof Proxy !== "undefined";
|
2607 | }
|
2608 | if (useProxies === "ifavailable") {
|
2609 | globalState.verifyProxies = true;
|
2610 | }
|
2611 | if (enforceActions !== undefined) {
|
2612 | var ea = enforceActions === ALWAYS ? ALWAYS : enforceActions === OBSERVED;
|
2613 | globalState.enforceActions = ea;
|
2614 | globalState.allowStateChanges = ea === true || ea === ALWAYS ? false : true;
|
2615 | }
|
2616 | ["computedRequiresReaction", "reactionRequiresObservable", "observableRequiresReaction", "disableErrorBoundaries", "safeDescriptors"].forEach(function (key) {
|
2617 | if (key in options) {
|
2618 | globalState[key] = !!options[key];
|
2619 | }
|
2620 | });
|
2621 | globalState.allowStateReads = !globalState.observableRequiresReaction;
|
2622 | if (process.env.NODE_ENV !== "production" && globalState.disableErrorBoundaries === true) {
|
2623 | console.warn("WARNING: Debug feature only. MobX will NOT recover from errors when `disableErrorBoundaries` is enabled.");
|
2624 | }
|
2625 | if (options.reactionScheduler) {
|
2626 | setReactionScheduler(options.reactionScheduler);
|
2627 | }
|
2628 | }
|
2629 |
|
2630 | function extendObservable(target, properties, annotations, options) {
|
2631 | if (process.env.NODE_ENV !== "production") {
|
2632 | if (arguments.length > 4) {
|
2633 | die("'extendObservable' expected 2-4 arguments");
|
2634 | }
|
2635 | if (typeof target !== "object") {
|
2636 | die("'extendObservable' expects an object as first argument");
|
2637 | }
|
2638 | if (isObservableMap(target)) {
|
2639 | die("'extendObservable' should not be used on maps, use map.merge instead");
|
2640 | }
|
2641 | if (!isPlainObject(properties)) {
|
2642 | die("'extendObservable' only accepts plain objects as second argument");
|
2643 | }
|
2644 | if (isObservable(properties) || isObservable(annotations)) {
|
2645 | die("Extending an object with another observable (object) is not supported");
|
2646 | }
|
2647 | }
|
2648 |
|
2649 | var descriptors = getOwnPropertyDescriptors(properties);
|
2650 | var adm = asObservableObject(target, options)[$mobx];
|
2651 | startBatch();
|
2652 | try {
|
2653 | ownKeys(descriptors).forEach(function (key) {
|
2654 | adm.extend_(key, descriptors[key],
|
2655 |
|
2656 | !annotations ? true : key in annotations ? annotations[key] : true);
|
2657 | });
|
2658 | } finally {
|
2659 | endBatch();
|
2660 | }
|
2661 | return target;
|
2662 | }
|
2663 |
|
2664 | function getDependencyTree(thing, property) {
|
2665 | return nodeToDependencyTree(getAtom(thing, property));
|
2666 | }
|
2667 | function nodeToDependencyTree(node) {
|
2668 | var result = {
|
2669 | name: node.name_
|
2670 | };
|
2671 | if (node.observing_ && node.observing_.length > 0) {
|
2672 | result.dependencies = unique(node.observing_).map(nodeToDependencyTree);
|
2673 | }
|
2674 | return result;
|
2675 | }
|
2676 | function getObserverTree(thing, property) {
|
2677 | return nodeToObserverTree(getAtom(thing, property));
|
2678 | }
|
2679 | function nodeToObserverTree(node) {
|
2680 | var result = {
|
2681 | name: node.name_
|
2682 | };
|
2683 | if (hasObservers(node)) {
|
2684 | result.observers = Array.from(getObservers(node)).map(nodeToObserverTree);
|
2685 | }
|
2686 | return result;
|
2687 | }
|
2688 | function unique(list) {
|
2689 | return Array.from(new Set(list));
|
2690 | }
|
2691 |
|
2692 | var generatorId = 0;
|
2693 | function FlowCancellationError() {
|
2694 | this.message = "FLOW_CANCELLED";
|
2695 | }
|
2696 | FlowCancellationError.prototype = Object.create(Error.prototype);
|
2697 | function isFlowCancellationError(error) {
|
2698 | return error instanceof FlowCancellationError;
|
2699 | }
|
2700 | var flowAnnotation = createFlowAnnotation("flow");
|
2701 | var flowBoundAnnotation = createFlowAnnotation("flow.bound", {
|
2702 | bound: true
|
2703 | });
|
2704 | var flow = Object.assign(function flow(arg1, arg2) {
|
2705 |
|
2706 | if (isStringish(arg2)) {
|
2707 | return storeAnnotation(arg1, arg2, flowAnnotation);
|
2708 | }
|
2709 |
|
2710 | if (process.env.NODE_ENV !== "production" && arguments.length !== 1) {
|
2711 | die("Flow expects single argument with generator function");
|
2712 | }
|
2713 | var generator = arg1;
|
2714 | var name = generator.name || "<unnamed flow>";
|
2715 |
|
2716 | var res = function res() {
|
2717 | var ctx = this;
|
2718 | var args = arguments;
|
2719 | var runId = ++generatorId;
|
2720 | var gen = action(name + " - runid: " + runId + " - init", generator).apply(ctx, args);
|
2721 | var rejector;
|
2722 | var pendingPromise = undefined;
|
2723 | var promise = new Promise(function (resolve, reject) {
|
2724 | var stepId = 0;
|
2725 | rejector = reject;
|
2726 | function onFulfilled(res) {
|
2727 | pendingPromise = undefined;
|
2728 | var ret;
|
2729 | try {
|
2730 | ret = action(name + " - runid: " + runId + " - yield " + stepId++, gen.next).call(gen, res);
|
2731 | } catch (e) {
|
2732 | return reject(e);
|
2733 | }
|
2734 | next(ret);
|
2735 | }
|
2736 | function onRejected(err) {
|
2737 | pendingPromise = undefined;
|
2738 | var ret;
|
2739 | try {
|
2740 | ret = action(name + " - runid: " + runId + " - yield " + stepId++, gen["throw"]).call(gen, err);
|
2741 | } catch (e) {
|
2742 | return reject(e);
|
2743 | }
|
2744 | next(ret);
|
2745 | }
|
2746 | function next(ret) {
|
2747 | if (isFunction(ret == null ? void 0 : ret.then)) {
|
2748 |
|
2749 | ret.then(next, reject);
|
2750 | return;
|
2751 | }
|
2752 | if (ret.done) {
|
2753 | return resolve(ret.value);
|
2754 | }
|
2755 | pendingPromise = Promise.resolve(ret.value);
|
2756 | return pendingPromise.then(onFulfilled, onRejected);
|
2757 | }
|
2758 | onFulfilled(undefined);
|
2759 | });
|
2760 |
|
2761 | promise.cancel = action(name + " - runid: " + runId + " - cancel", function () {
|
2762 | try {
|
2763 | if (pendingPromise) {
|
2764 | cancelPromise(pendingPromise);
|
2765 | }
|
2766 |
|
2767 | var _res = gen["return"](undefined);
|
2768 |
|
2769 | var yieldedPromise = Promise.resolve(_res.value);
|
2770 | yieldedPromise.then(noop, noop);
|
2771 | cancelPromise(yieldedPromise);
|
2772 |
|
2773 | rejector(new FlowCancellationError());
|
2774 | } catch (e) {
|
2775 | rejector(e);
|
2776 | }
|
2777 | });
|
2778 |
|
2779 | return promise;
|
2780 | };
|
2781 | res.isMobXFlow = true;
|
2782 | return res;
|
2783 | }, flowAnnotation);
|
2784 | flow.bound = createDecoratorAnnotation(flowBoundAnnotation);
|
2785 | function cancelPromise(promise) {
|
2786 | if (isFunction(promise.cancel)) {
|
2787 | promise.cancel();
|
2788 | }
|
2789 | }
|
2790 | function flowResult(result) {
|
2791 | return result;
|
2792 | }
|
2793 |
|
2794 | function isFlow(fn) {
|
2795 | return (fn == null ? void 0 : fn.isMobXFlow) === true;
|
2796 | }
|
2797 |
|
2798 | function interceptReads(thing, propOrHandler, handler) {
|
2799 | var target;
|
2800 | if (isObservableMap(thing) || isObservableArray(thing) || isObservableValue(thing)) {
|
2801 | target = getAdministration(thing);
|
2802 | } else if (isObservableObject(thing)) {
|
2803 | if (process.env.NODE_ENV !== "production" && !isStringish(propOrHandler)) {
|
2804 | return die("InterceptReads can only be used with a specific property, not with an object in general");
|
2805 | }
|
2806 | target = getAdministration(thing, propOrHandler);
|
2807 | } else if (process.env.NODE_ENV !== "production") {
|
2808 | return die("Expected observable map, object or array as first array");
|
2809 | }
|
2810 | if (process.env.NODE_ENV !== "production" && target.dehancer !== undefined) {
|
2811 | return die("An intercept reader was already established");
|
2812 | }
|
2813 | target.dehancer = typeof propOrHandler === "function" ? propOrHandler : handler;
|
2814 | return function () {
|
2815 | target.dehancer = undefined;
|
2816 | };
|
2817 | }
|
2818 |
|
2819 | function intercept(thing, propOrHandler, handler) {
|
2820 | if (isFunction(handler)) {
|
2821 | return interceptProperty(thing, propOrHandler, handler);
|
2822 | } else {
|
2823 | return interceptInterceptable(thing, propOrHandler);
|
2824 | }
|
2825 | }
|
2826 | function interceptInterceptable(thing, handler) {
|
2827 | return getAdministration(thing).intercept_(handler);
|
2828 | }
|
2829 | function interceptProperty(thing, property, handler) {
|
2830 | return getAdministration(thing, property).intercept_(handler);
|
2831 | }
|
2832 |
|
2833 | function _isComputed(value, property) {
|
2834 | if (property === undefined) {
|
2835 | return isComputedValue(value);
|
2836 | }
|
2837 | if (isObservableObject(value) === false) {
|
2838 | return false;
|
2839 | }
|
2840 | if (!value[$mobx].values_.has(property)) {
|
2841 | return false;
|
2842 | }
|
2843 | var atom = getAtom(value, property);
|
2844 | return isComputedValue(atom);
|
2845 | }
|
2846 | function isComputed(value) {
|
2847 | if (process.env.NODE_ENV !== "production" && arguments.length > 1) {
|
2848 | return die("isComputed expects only 1 argument. Use isComputedProp to inspect the observability of a property");
|
2849 | }
|
2850 | return _isComputed(value);
|
2851 | }
|
2852 | function isComputedProp(value, propName) {
|
2853 | if (process.env.NODE_ENV !== "production" && !isStringish(propName)) {
|
2854 | return die("isComputed expected a property name as second argument");
|
2855 | }
|
2856 | return _isComputed(value, propName);
|
2857 | }
|
2858 |
|
2859 | function _isObservable(value, property) {
|
2860 | if (!value) {
|
2861 | return false;
|
2862 | }
|
2863 | if (property !== undefined) {
|
2864 | if (process.env.NODE_ENV !== "production" && (isObservableMap(value) || isObservableArray(value))) {
|
2865 | return die("isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.");
|
2866 | }
|
2867 | if (isObservableObject(value)) {
|
2868 | return value[$mobx].values_.has(property);
|
2869 | }
|
2870 | return false;
|
2871 | }
|
2872 |
|
2873 | return isObservableObject(value) || !!value[$mobx] || isAtom(value) || isReaction(value) || isComputedValue(value);
|
2874 | }
|
2875 | function isObservable(value) {
|
2876 | if (process.env.NODE_ENV !== "production" && arguments.length !== 1) {
|
2877 | die("isObservable expects only 1 argument. Use isObservableProp to inspect the observability of a property");
|
2878 | }
|
2879 | return _isObservable(value);
|
2880 | }
|
2881 | function isObservableProp(value, propName) {
|
2882 | if (process.env.NODE_ENV !== "production" && !isStringish(propName)) {
|
2883 | return die("expected a property name as second argument");
|
2884 | }
|
2885 | return _isObservable(value, propName);
|
2886 | }
|
2887 |
|
2888 | function keys(obj) {
|
2889 | if (isObservableObject(obj)) {
|
2890 | return obj[$mobx].keys_();
|
2891 | }
|
2892 | if (isObservableMap(obj) || isObservableSet(obj)) {
|
2893 | return Array.from(obj.keys());
|
2894 | }
|
2895 | if (isObservableArray(obj)) {
|
2896 | return obj.map(function (_, index) {
|
2897 | return index;
|
2898 | });
|
2899 | }
|
2900 | die(5);
|
2901 | }
|
2902 | function values(obj) {
|
2903 | if (isObservableObject(obj)) {
|
2904 | return keys(obj).map(function (key) {
|
2905 | return obj[key];
|
2906 | });
|
2907 | }
|
2908 | if (isObservableMap(obj)) {
|
2909 | return keys(obj).map(function (key) {
|
2910 | return obj.get(key);
|
2911 | });
|
2912 | }
|
2913 | if (isObservableSet(obj)) {
|
2914 | return Array.from(obj.values());
|
2915 | }
|
2916 | if (isObservableArray(obj)) {
|
2917 | return obj.slice();
|
2918 | }
|
2919 | die(6);
|
2920 | }
|
2921 | function entries(obj) {
|
2922 | if (isObservableObject(obj)) {
|
2923 | return keys(obj).map(function (key) {
|
2924 | return [key, obj[key]];
|
2925 | });
|
2926 | }
|
2927 | if (isObservableMap(obj)) {
|
2928 | return keys(obj).map(function (key) {
|
2929 | return [key, obj.get(key)];
|
2930 | });
|
2931 | }
|
2932 | if (isObservableSet(obj)) {
|
2933 | return Array.from(obj.entries());
|
2934 | }
|
2935 | if (isObservableArray(obj)) {
|
2936 | return obj.map(function (key, index) {
|
2937 | return [index, key];
|
2938 | });
|
2939 | }
|
2940 | die(7);
|
2941 | }
|
2942 | function set(obj, key, value) {
|
2943 | if (arguments.length === 2 && !isObservableSet(obj)) {
|
2944 | startBatch();
|
2945 | var _values = key;
|
2946 | try {
|
2947 | for (var _key in _values) {
|
2948 | set(obj, _key, _values[_key]);
|
2949 | }
|
2950 | } finally {
|
2951 | endBatch();
|
2952 | }
|
2953 | return;
|
2954 | }
|
2955 | if (isObservableObject(obj)) {
|
2956 | obj[$mobx].set_(key, value);
|
2957 | } else if (isObservableMap(obj)) {
|
2958 | obj.set(key, value);
|
2959 | } else if (isObservableSet(obj)) {
|
2960 | obj.add(key);
|
2961 | } else if (isObservableArray(obj)) {
|
2962 | if (typeof key !== "number") {
|
2963 | key = parseInt(key, 10);
|
2964 | }
|
2965 | if (key < 0) {
|
2966 | die("Invalid index: '" + key + "'");
|
2967 | }
|
2968 | startBatch();
|
2969 | if (key >= obj.length) {
|
2970 | obj.length = key + 1;
|
2971 | }
|
2972 | obj[key] = value;
|
2973 | endBatch();
|
2974 | } else {
|
2975 | die(8);
|
2976 | }
|
2977 | }
|
2978 | function remove(obj, key) {
|
2979 | if (isObservableObject(obj)) {
|
2980 | obj[$mobx].delete_(key);
|
2981 | } else if (isObservableMap(obj)) {
|
2982 | obj["delete"](key);
|
2983 | } else if (isObservableSet(obj)) {
|
2984 | obj["delete"](key);
|
2985 | } else if (isObservableArray(obj)) {
|
2986 | if (typeof key !== "number") {
|
2987 | key = parseInt(key, 10);
|
2988 | }
|
2989 | obj.splice(key, 1);
|
2990 | } else {
|
2991 | die(9);
|
2992 | }
|
2993 | }
|
2994 | function has(obj, key) {
|
2995 | if (isObservableObject(obj)) {
|
2996 | return obj[$mobx].has_(key);
|
2997 | } else if (isObservableMap(obj)) {
|
2998 | return obj.has(key);
|
2999 | } else if (isObservableSet(obj)) {
|
3000 | return obj.has(key);
|
3001 | } else if (isObservableArray(obj)) {
|
3002 | return key >= 0 && key < obj.length;
|
3003 | }
|
3004 | die(10);
|
3005 | }
|
3006 | function get(obj, key) {
|
3007 | if (!has(obj, key)) {
|
3008 | return undefined;
|
3009 | }
|
3010 | if (isObservableObject(obj)) {
|
3011 | return obj[$mobx].get_(key);
|
3012 | } else if (isObservableMap(obj)) {
|
3013 | return obj.get(key);
|
3014 | } else if (isObservableArray(obj)) {
|
3015 | return obj[key];
|
3016 | }
|
3017 | die(11);
|
3018 | }
|
3019 | function apiDefineProperty(obj, key, descriptor) {
|
3020 | if (isObservableObject(obj)) {
|
3021 | return obj[$mobx].defineProperty_(key, descriptor);
|
3022 | }
|
3023 | die(39);
|
3024 | }
|
3025 | function apiOwnKeys(obj) {
|
3026 | if (isObservableObject(obj)) {
|
3027 | return obj[$mobx].ownKeys_();
|
3028 | }
|
3029 | die(38);
|
3030 | }
|
3031 |
|
3032 | function observe(thing, propOrCb, cbOrFire, fireImmediately) {
|
3033 | if (isFunction(cbOrFire)) {
|
3034 | return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);
|
3035 | } else {
|
3036 | return observeObservable(thing, propOrCb, cbOrFire);
|
3037 | }
|
3038 | }
|
3039 | function observeObservable(thing, listener, fireImmediately) {
|
3040 | return getAdministration(thing).observe_(listener, fireImmediately);
|
3041 | }
|
3042 | function observeObservableProperty(thing, property, listener, fireImmediately) {
|
3043 | return getAdministration(thing, property).observe_(listener, fireImmediately);
|
3044 | }
|
3045 |
|
3046 | function cache(map, key, value) {
|
3047 | map.set(key, value);
|
3048 | return value;
|
3049 | }
|
3050 | function toJSHelper(source, __alreadySeen) {
|
3051 | if (source == null || typeof source !== "object" || source instanceof Date || !isObservable(source)) {
|
3052 | return source;
|
3053 | }
|
3054 | if (isObservableValue(source) || isComputedValue(source)) {
|
3055 | return toJSHelper(source.get(), __alreadySeen);
|
3056 | }
|
3057 | if (__alreadySeen.has(source)) {
|
3058 | return __alreadySeen.get(source);
|
3059 | }
|
3060 | if (isObservableArray(source)) {
|
3061 | var res = cache(__alreadySeen, source, new Array(source.length));
|
3062 | source.forEach(function (value, idx) {
|
3063 | res[idx] = toJSHelper(value, __alreadySeen);
|
3064 | });
|
3065 | return res;
|
3066 | }
|
3067 | if (isObservableSet(source)) {
|
3068 | var _res = cache(__alreadySeen, source, new Set());
|
3069 | source.forEach(function (value) {
|
3070 | _res.add(toJSHelper(value, __alreadySeen));
|
3071 | });
|
3072 | return _res;
|
3073 | }
|
3074 | if (isObservableMap(source)) {
|
3075 | var _res2 = cache(__alreadySeen, source, new Map());
|
3076 | source.forEach(function (value, key) {
|
3077 | _res2.set(key, toJSHelper(value, __alreadySeen));
|
3078 | });
|
3079 | return _res2;
|
3080 | } else {
|
3081 |
|
3082 | var _res3 = cache(__alreadySeen, source, {});
|
3083 | apiOwnKeys(source).forEach(function (key) {
|
3084 | if (objectPrototype.propertyIsEnumerable.call(source, key)) {
|
3085 | _res3[key] = toJSHelper(source[key], __alreadySeen);
|
3086 | }
|
3087 | });
|
3088 | return _res3;
|
3089 | }
|
3090 | }
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 | function toJS(source, options) {
|
3098 | if (process.env.NODE_ENV !== "production" && options) {
|
3099 | die("toJS no longer supports options");
|
3100 | }
|
3101 | return toJSHelper(source, new Map());
|
3102 | }
|
3103 |
|
3104 | function trace() {
|
3105 | if (!(process.env.NODE_ENV !== "production")) {
|
3106 | return;
|
3107 | }
|
3108 | var enterBreakPoint = false;
|
3109 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
3110 | args[_key] = arguments[_key];
|
3111 | }
|
3112 | if (typeof args[args.length - 1] === "boolean") {
|
3113 | enterBreakPoint = args.pop();
|
3114 | }
|
3115 | var derivation = getAtomFromArgs(args);
|
3116 | if (!derivation) {
|
3117 | return die("'trace(break?)' can only be used inside a tracked computed value or a Reaction. Consider passing in the computed value or reaction explicitly");
|
3118 | }
|
3119 | if (derivation.isTracing_ === TraceMode.NONE) {
|
3120 | console.log("[mobx.trace] '" + derivation.name_ + "' tracing enabled");
|
3121 | }
|
3122 | derivation.isTracing_ = enterBreakPoint ? TraceMode.BREAK : TraceMode.LOG;
|
3123 | }
|
3124 | function getAtomFromArgs(args) {
|
3125 | switch (args.length) {
|
3126 | case 0:
|
3127 | return globalState.trackingDerivation;
|
3128 | case 1:
|
3129 | return getAtom(args[0]);
|
3130 | case 2:
|
3131 | return getAtom(args[0], args[1]);
|
3132 | }
|
3133 | }
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 | function transaction(action, thisArg) {
|
3143 | if (thisArg === void 0) {
|
3144 | thisArg = undefined;
|
3145 | }
|
3146 | startBatch();
|
3147 | try {
|
3148 | return action.apply(thisArg);
|
3149 | } finally {
|
3150 | endBatch();
|
3151 | }
|
3152 | }
|
3153 |
|
3154 | function when(predicate, arg1, arg2) {
|
3155 | if (arguments.length === 1 || arg1 && typeof arg1 === "object") {
|
3156 | return whenPromise(predicate, arg1);
|
3157 | }
|
3158 | return _when(predicate, arg1, arg2 || {});
|
3159 | }
|
3160 | function _when(predicate, effect, opts) {
|
3161 | var timeoutHandle;
|
3162 | if (typeof opts.timeout === "number") {
|
3163 | var error = new Error("WHEN_TIMEOUT");
|
3164 | timeoutHandle = setTimeout(function () {
|
3165 | if (!disposer[$mobx].isDisposed_) {
|
3166 | disposer();
|
3167 | if (opts.onError) {
|
3168 | opts.onError(error);
|
3169 | } else {
|
3170 | throw error;
|
3171 | }
|
3172 | }
|
3173 | }, opts.timeout);
|
3174 | }
|
3175 | opts.name = process.env.NODE_ENV !== "production" ? opts.name || "When@" + getNextId() : "When";
|
3176 | var effectAction = createAction(process.env.NODE_ENV !== "production" ? opts.name + "-effect" : "When-effect", effect);
|
3177 |
|
3178 | var disposer = autorun(function (r) {
|
3179 |
|
3180 | var cond = allowStateChanges(false, predicate);
|
3181 | if (cond) {
|
3182 | r.dispose();
|
3183 | if (timeoutHandle) {
|
3184 | clearTimeout(timeoutHandle);
|
3185 | }
|
3186 | effectAction();
|
3187 | }
|
3188 | }, opts);
|
3189 | return disposer;
|
3190 | }
|
3191 | function whenPromise(predicate, opts) {
|
3192 | var _opts$signal;
|
3193 | if (process.env.NODE_ENV !== "production" && opts && opts.onError) {
|
3194 | return die("the options 'onError' and 'promise' cannot be combined");
|
3195 | }
|
3196 | if (opts != null && (_opts$signal = opts.signal) != null && _opts$signal.aborted) {
|
3197 | return Object.assign(Promise.reject(new Error("WHEN_ABORTED")), {
|
3198 | cancel: function cancel() {
|
3199 | return null;
|
3200 | }
|
3201 | });
|
3202 | }
|
3203 | var cancel;
|
3204 | var abort;
|
3205 | var res = new Promise(function (resolve, reject) {
|
3206 | var _opts$signal2;
|
3207 | var disposer = _when(predicate, resolve, _extends({}, opts, {
|
3208 | onError: reject
|
3209 | }));
|
3210 | cancel = function cancel() {
|
3211 | disposer();
|
3212 | reject(new Error("WHEN_CANCELLED"));
|
3213 | };
|
3214 | abort = function abort() {
|
3215 | disposer();
|
3216 | reject(new Error("WHEN_ABORTED"));
|
3217 | };
|
3218 | opts == null ? void 0 : (_opts$signal2 = opts.signal) == null ? void 0 : _opts$signal2.addEventListener == null ? void 0 : _opts$signal2.addEventListener("abort", abort);
|
3219 | })["finally"](function () {
|
3220 | var _opts$signal3;
|
3221 | return opts == null ? void 0 : (_opts$signal3 = opts.signal) == null ? void 0 : _opts$signal3.removeEventListener == null ? void 0 : _opts$signal3.removeEventListener("abort", abort);
|
3222 | });
|
3223 | res.cancel = cancel;
|
3224 | return res;
|
3225 | }
|
3226 |
|
3227 | function getAdm(target) {
|
3228 | return target[$mobx];
|
3229 | }
|
3230 |
|
3231 |
|
3232 | var objectProxyTraps = {
|
3233 | has: function has(target, name) {
|
3234 | if (process.env.NODE_ENV !== "production" && globalState.trackingDerivation) {
|
3235 | warnAboutProxyRequirement("detect new properties using the 'in' operator. Use 'has' from 'mobx' instead.");
|
3236 | }
|
3237 | return getAdm(target).has_(name);
|
3238 | },
|
3239 | get: function get(target, name) {
|
3240 | return getAdm(target).get_(name);
|
3241 | },
|
3242 | set: function set(target, name, value) {
|
3243 | var _getAdm$set_;
|
3244 | if (!isStringish(name)) {
|
3245 | return false;
|
3246 | }
|
3247 | if (process.env.NODE_ENV !== "production" && !getAdm(target).values_.has(name)) {
|
3248 | warnAboutProxyRequirement("add a new observable property through direct assignment. Use 'set' from 'mobx' instead.");
|
3249 | }
|
3250 |
|
3251 | return (_getAdm$set_ = getAdm(target).set_(name, value, true)) != null ? _getAdm$set_ : true;
|
3252 | },
|
3253 | deleteProperty: function deleteProperty(target, name) {
|
3254 | var _getAdm$delete_;
|
3255 | if (process.env.NODE_ENV !== "production") {
|
3256 | warnAboutProxyRequirement("delete properties from an observable object. Use 'remove' from 'mobx' instead.");
|
3257 | }
|
3258 | if (!isStringish(name)) {
|
3259 | return false;
|
3260 | }
|
3261 |
|
3262 | return (_getAdm$delete_ = getAdm(target).delete_(name, true)) != null ? _getAdm$delete_ : true;
|
3263 | },
|
3264 | defineProperty: function defineProperty(target, name, descriptor) {
|
3265 | var _getAdm$definePropert;
|
3266 | if (process.env.NODE_ENV !== "production") {
|
3267 | warnAboutProxyRequirement("define property on an observable object. Use 'defineProperty' from 'mobx' instead.");
|
3268 | }
|
3269 |
|
3270 | return (_getAdm$definePropert = getAdm(target).defineProperty_(name, descriptor)) != null ? _getAdm$definePropert : true;
|
3271 | },
|
3272 | ownKeys: function ownKeys(target) {
|
3273 | if (process.env.NODE_ENV !== "production" && globalState.trackingDerivation) {
|
3274 | warnAboutProxyRequirement("iterate keys to detect added / removed properties. Use 'keys' from 'mobx' instead.");
|
3275 | }
|
3276 | return getAdm(target).ownKeys_();
|
3277 | },
|
3278 | preventExtensions: function preventExtensions(target) {
|
3279 | die(13);
|
3280 | }
|
3281 | };
|
3282 | function asDynamicObservableObject(target, options) {
|
3283 | var _target$$mobx, _target$$mobx$proxy_;
|
3284 | assertProxies();
|
3285 | target = asObservableObject(target, options);
|
3286 | return (_target$$mobx$proxy_ = (_target$$mobx = target[$mobx]).proxy_) != null ? _target$$mobx$proxy_ : _target$$mobx.proxy_ = new Proxy(target, objectProxyTraps);
|
3287 | }
|
3288 |
|
3289 | function hasInterceptors(interceptable) {
|
3290 | return interceptable.interceptors_ !== undefined && interceptable.interceptors_.length > 0;
|
3291 | }
|
3292 | function registerInterceptor(interceptable, handler) {
|
3293 | var interceptors = interceptable.interceptors_ || (interceptable.interceptors_ = []);
|
3294 | interceptors.push(handler);
|
3295 | return once(function () {
|
3296 | var idx = interceptors.indexOf(handler);
|
3297 | if (idx !== -1) {
|
3298 | interceptors.splice(idx, 1);
|
3299 | }
|
3300 | });
|
3301 | }
|
3302 | function interceptChange(interceptable, change) {
|
3303 | var prevU = untrackedStart();
|
3304 | try {
|
3305 |
|
3306 | var interceptors = [].concat(interceptable.interceptors_ || []);
|
3307 | for (var i = 0, l = interceptors.length; i < l; i++) {
|
3308 | change = interceptors[i](change);
|
3309 | if (change && !change.type) {
|
3310 | die(14);
|
3311 | }
|
3312 | if (!change) {
|
3313 | break;
|
3314 | }
|
3315 | }
|
3316 | return change;
|
3317 | } finally {
|
3318 | untrackedEnd(prevU);
|
3319 | }
|
3320 | }
|
3321 |
|
3322 | function hasListeners(listenable) {
|
3323 | return listenable.changeListeners_ !== undefined && listenable.changeListeners_.length > 0;
|
3324 | }
|
3325 | function registerListener(listenable, handler) {
|
3326 | var listeners = listenable.changeListeners_ || (listenable.changeListeners_ = []);
|
3327 | listeners.push(handler);
|
3328 | return once(function () {
|
3329 | var idx = listeners.indexOf(handler);
|
3330 | if (idx !== -1) {
|
3331 | listeners.splice(idx, 1);
|
3332 | }
|
3333 | });
|
3334 | }
|
3335 | function notifyListeners(listenable, change) {
|
3336 | var prevU = untrackedStart();
|
3337 | var listeners = listenable.changeListeners_;
|
3338 | if (!listeners) {
|
3339 | return;
|
3340 | }
|
3341 | listeners = listeners.slice();
|
3342 | for (var i = 0, l = listeners.length; i < l; i++) {
|
3343 | listeners[i](change);
|
3344 | }
|
3345 | untrackedEnd(prevU);
|
3346 | }
|
3347 |
|
3348 | function makeObservable(target, annotations, options) {
|
3349 | var adm = asObservableObject(target, options)[$mobx];
|
3350 | startBatch();
|
3351 | try {
|
3352 | var _annotations;
|
3353 | if (process.env.NODE_ENV !== "production" && annotations && target[storedAnnotationsSymbol]) {
|
3354 | die("makeObservable second arg must be nullish when using decorators. Mixing @decorator syntax with annotations is not supported.");
|
3355 | }
|
3356 |
|
3357 | (_annotations = annotations) != null ? _annotations : annotations = collectStoredAnnotations(target);
|
3358 |
|
3359 | ownKeys(annotations).forEach(function (key) {
|
3360 | return adm.make_(key, annotations[key]);
|
3361 | });
|
3362 | } finally {
|
3363 | endBatch();
|
3364 | }
|
3365 | return target;
|
3366 | }
|
3367 |
|
3368 | var keysSymbol = Symbol("mobx-keys");
|
3369 | function makeAutoObservable(target, overrides, options) {
|
3370 | if (process.env.NODE_ENV !== "production") {
|
3371 | if (!isPlainObject(target) && !isPlainObject(Object.getPrototypeOf(target))) {
|
3372 | die("'makeAutoObservable' can only be used for classes that don't have a superclass");
|
3373 | }
|
3374 | if (isObservableObject(target)) {
|
3375 | die("makeAutoObservable can only be used on objects not already made observable");
|
3376 | }
|
3377 | }
|
3378 |
|
3379 |
|
3380 | if (isPlainObject(target)) {
|
3381 | return extendObservable(target, target, overrides, options);
|
3382 | }
|
3383 | var adm = asObservableObject(target, options)[$mobx];
|
3384 |
|
3385 |
|
3386 | if (!target[keysSymbol]) {
|
3387 | var proto = Object.getPrototypeOf(target);
|
3388 | var keys = new Set([].concat(ownKeys(target), ownKeys(proto)));
|
3389 | keys["delete"]("constructor");
|
3390 | keys["delete"]($mobx);
|
3391 | addHiddenProp(proto, keysSymbol, keys);
|
3392 | }
|
3393 | startBatch();
|
3394 | try {
|
3395 | target[keysSymbol].forEach(function (key) {
|
3396 | return adm.make_(key,
|
3397 |
|
3398 | !overrides ? true : key in overrides ? overrides[key] : true);
|
3399 | });
|
3400 | } finally {
|
3401 | endBatch();
|
3402 | }
|
3403 | return target;
|
3404 | }
|
3405 |
|
3406 | var SPLICE = "splice";
|
3407 | var UPDATE = "update";
|
3408 | var MAX_SPLICE_SIZE = 10000;
|
3409 | var arrayTraps = {
|
3410 | get: function get(target, name) {
|
3411 | var adm = target[$mobx];
|
3412 | if (name === $mobx) {
|
3413 | return adm;
|
3414 | }
|
3415 | if (name === "length") {
|
3416 | return adm.getArrayLength_();
|
3417 | }
|
3418 | if (typeof name === "string" && !isNaN(name)) {
|
3419 | return adm.get_(parseInt(name));
|
3420 | }
|
3421 | if (hasProp(arrayExtensions, name)) {
|
3422 | return arrayExtensions[name];
|
3423 | }
|
3424 | return target[name];
|
3425 | },
|
3426 | set: function set(target, name, value) {
|
3427 | var adm = target[$mobx];
|
3428 | if (name === "length") {
|
3429 | adm.setArrayLength_(value);
|
3430 | }
|
3431 | if (typeof name === "symbol" || isNaN(name)) {
|
3432 | target[name] = value;
|
3433 | } else {
|
3434 |
|
3435 | adm.set_(parseInt(name), value);
|
3436 | }
|
3437 | return true;
|
3438 | },
|
3439 | preventExtensions: function preventExtensions() {
|
3440 | die(15);
|
3441 | }
|
3442 | };
|
3443 | var ObservableArrayAdministration = function () {
|
3444 |
|
3445 |
|
3446 | function ObservableArrayAdministration(name, enhancer, owned_, legacyMode_) {
|
3447 | if (name === void 0) {
|
3448 | name = process.env.NODE_ENV !== "production" ? "ObservableArray@" + getNextId() : "ObservableArray";
|
3449 | }
|
3450 | this.owned_ = void 0;
|
3451 | this.legacyMode_ = void 0;
|
3452 | this.atom_ = void 0;
|
3453 | this.values_ = [];
|
3454 | this.interceptors_ = void 0;
|
3455 | this.changeListeners_ = void 0;
|
3456 | this.enhancer_ = void 0;
|
3457 | this.dehancer = void 0;
|
3458 | this.proxy_ = void 0;
|
3459 | this.lastKnownLength_ = 0;
|
3460 | this.owned_ = owned_;
|
3461 | this.legacyMode_ = legacyMode_;
|
3462 | this.atom_ = new Atom(name);
|
3463 | this.enhancer_ = function (newV, oldV) {
|
3464 | return enhancer(newV, oldV, process.env.NODE_ENV !== "production" ? name + "[..]" : "ObservableArray[..]");
|
3465 | };
|
3466 | }
|
3467 | var _proto = ObservableArrayAdministration.prototype;
|
3468 | _proto.dehanceValue_ = function dehanceValue_(value) {
|
3469 | if (this.dehancer !== undefined) {
|
3470 | return this.dehancer(value);
|
3471 | }
|
3472 | return value;
|
3473 | };
|
3474 | _proto.dehanceValues_ = function dehanceValues_(values) {
|
3475 | if (this.dehancer !== undefined && values.length > 0) {
|
3476 | return values.map(this.dehancer);
|
3477 | }
|
3478 | return values;
|
3479 | };
|
3480 | _proto.intercept_ = function intercept_(handler) {
|
3481 | return registerInterceptor(this, handler);
|
3482 | };
|
3483 | _proto.observe_ = function observe_(listener, fireImmediately) {
|
3484 | if (fireImmediately === void 0) {
|
3485 | fireImmediately = false;
|
3486 | }
|
3487 | if (fireImmediately) {
|
3488 | listener({
|
3489 | observableKind: "array",
|
3490 | object: this.proxy_,
|
3491 | debugObjectName: this.atom_.name_,
|
3492 | type: "splice",
|
3493 | index: 0,
|
3494 | added: this.values_.slice(),
|
3495 | addedCount: this.values_.length,
|
3496 | removed: [],
|
3497 | removedCount: 0
|
3498 | });
|
3499 | }
|
3500 | return registerListener(this, listener);
|
3501 | };
|
3502 | _proto.getArrayLength_ = function getArrayLength_() {
|
3503 | this.atom_.reportObserved();
|
3504 | return this.values_.length;
|
3505 | };
|
3506 | _proto.setArrayLength_ = function setArrayLength_(newLength) {
|
3507 | if (typeof newLength !== "number" || isNaN(newLength) || newLength < 0) {
|
3508 | die("Out of range: " + newLength);
|
3509 | }
|
3510 | var currentLength = this.values_.length;
|
3511 | if (newLength === currentLength) {
|
3512 | return;
|
3513 | } else if (newLength > currentLength) {
|
3514 | var newItems = new Array(newLength - currentLength);
|
3515 | for (var i = 0; i < newLength - currentLength; i++) {
|
3516 | newItems[i] = undefined;
|
3517 | }
|
3518 | this.spliceWithArray_(currentLength, 0, newItems);
|
3519 | } else {
|
3520 | this.spliceWithArray_(newLength, currentLength - newLength);
|
3521 | }
|
3522 | };
|
3523 | _proto.updateArrayLength_ = function updateArrayLength_(oldLength, delta) {
|
3524 | if (oldLength !== this.lastKnownLength_) {
|
3525 | die(16);
|
3526 | }
|
3527 | this.lastKnownLength_ += delta;
|
3528 | if (this.legacyMode_ && delta > 0) {
|
3529 | reserveArrayBuffer(oldLength + delta + 1);
|
3530 | }
|
3531 | };
|
3532 | _proto.spliceWithArray_ = function spliceWithArray_(index, deleteCount, newItems) {
|
3533 | var _this = this;
|
3534 | checkIfStateModificationsAreAllowed(this.atom_);
|
3535 | var length = this.values_.length;
|
3536 | if (index === undefined) {
|
3537 | index = 0;
|
3538 | } else if (index > length) {
|
3539 | index = length;
|
3540 | } else if (index < 0) {
|
3541 | index = Math.max(0, length + index);
|
3542 | }
|
3543 | if (arguments.length === 1) {
|
3544 | deleteCount = length - index;
|
3545 | } else if (deleteCount === undefined || deleteCount === null) {
|
3546 | deleteCount = 0;
|
3547 | } else {
|
3548 | deleteCount = Math.max(0, Math.min(deleteCount, length - index));
|
3549 | }
|
3550 | if (newItems === undefined) {
|
3551 | newItems = EMPTY_ARRAY;
|
3552 | }
|
3553 | if (hasInterceptors(this)) {
|
3554 | var change = interceptChange(this, {
|
3555 | object: this.proxy_,
|
3556 | type: SPLICE,
|
3557 | index: index,
|
3558 | removedCount: deleteCount,
|
3559 | added: newItems
|
3560 | });
|
3561 | if (!change) {
|
3562 | return EMPTY_ARRAY;
|
3563 | }
|
3564 | deleteCount = change.removedCount;
|
3565 | newItems = change.added;
|
3566 | }
|
3567 | newItems = newItems.length === 0 ? newItems : newItems.map(function (v) {
|
3568 | return _this.enhancer_(v, undefined);
|
3569 | });
|
3570 | if (this.legacyMode_ || process.env.NODE_ENV !== "production") {
|
3571 | var lengthDelta = newItems.length - deleteCount;
|
3572 | this.updateArrayLength_(length, lengthDelta);
|
3573 | }
|
3574 |
|
3575 | var res = this.spliceItemsIntoValues_(index, deleteCount, newItems);
|
3576 | if (deleteCount !== 0 || newItems.length !== 0) {
|
3577 | this.notifyArraySplice_(index, newItems, res);
|
3578 | }
|
3579 | return this.dehanceValues_(res);
|
3580 | };
|
3581 | _proto.spliceItemsIntoValues_ = function spliceItemsIntoValues_(index, deleteCount, newItems) {
|
3582 | if (newItems.length < MAX_SPLICE_SIZE) {
|
3583 | var _this$values_;
|
3584 | return (_this$values_ = this.values_).splice.apply(_this$values_, [index, deleteCount].concat(newItems));
|
3585 | } else {
|
3586 |
|
3587 | var res = this.values_.slice(index, index + deleteCount);
|
3588 |
|
3589 | var oldItems = this.values_.slice(index + deleteCount);
|
3590 |
|
3591 | this.values_.length += newItems.length - deleteCount;
|
3592 | for (var i = 0; i < newItems.length; i++) {
|
3593 | this.values_[index + i] = newItems[i];
|
3594 | }
|
3595 | for (var _i = 0; _i < oldItems.length; _i++) {
|
3596 | this.values_[index + newItems.length + _i] = oldItems[_i];
|
3597 | }
|
3598 | return res;
|
3599 | }
|
3600 | };
|
3601 | _proto.notifyArrayChildUpdate_ = function notifyArrayChildUpdate_(index, newValue, oldValue) {
|
3602 | var notifySpy = !this.owned_ && isSpyEnabled();
|
3603 | var notify = hasListeners(this);
|
3604 | var change = notify || notifySpy ? {
|
3605 | observableKind: "array",
|
3606 | object: this.proxy_,
|
3607 | type: UPDATE,
|
3608 | debugObjectName: this.atom_.name_,
|
3609 | index: index,
|
3610 | newValue: newValue,
|
3611 | oldValue: oldValue
|
3612 | } : null;
|
3613 |
|
3614 |
|
3615 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
3616 | spyReportStart(change);
|
3617 | }
|
3618 | this.atom_.reportChanged();
|
3619 | if (notify) {
|
3620 | notifyListeners(this, change);
|
3621 | }
|
3622 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
3623 | spyReportEnd();
|
3624 | }
|
3625 | };
|
3626 | _proto.notifyArraySplice_ = function notifyArraySplice_(index, added, removed) {
|
3627 | var notifySpy = !this.owned_ && isSpyEnabled();
|
3628 | var notify = hasListeners(this);
|
3629 | var change = notify || notifySpy ? {
|
3630 | observableKind: "array",
|
3631 | object: this.proxy_,
|
3632 | debugObjectName: this.atom_.name_,
|
3633 | type: SPLICE,
|
3634 | index: index,
|
3635 | removed: removed,
|
3636 | added: added,
|
3637 | removedCount: removed.length,
|
3638 | addedCount: added.length
|
3639 | } : null;
|
3640 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
3641 | spyReportStart(change);
|
3642 | }
|
3643 | this.atom_.reportChanged();
|
3644 |
|
3645 | if (notify) {
|
3646 | notifyListeners(this, change);
|
3647 | }
|
3648 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
3649 | spyReportEnd();
|
3650 | }
|
3651 | };
|
3652 | _proto.get_ = function get_(index) {
|
3653 | if (this.legacyMode_ && index >= this.values_.length) {
|
3654 | console.warn(process.env.NODE_ENV !== "production" ? "[mobx.array] Attempt to read an array index (" + index + ") that is out of bounds (" + this.values_.length + "). Please check length first. Out of bound indices will not be tracked by MobX" : "[mobx] Out of bounds read: " + index);
|
3655 | return undefined;
|
3656 | }
|
3657 | this.atom_.reportObserved();
|
3658 | return this.dehanceValue_(this.values_[index]);
|
3659 | };
|
3660 | _proto.set_ = function set_(index, newValue) {
|
3661 | var values = this.values_;
|
3662 | if (this.legacyMode_ && index > values.length) {
|
3663 |
|
3664 | die(17, index, values.length);
|
3665 | }
|
3666 | if (index < values.length) {
|
3667 |
|
3668 | checkIfStateModificationsAreAllowed(this.atom_);
|
3669 | var oldValue = values[index];
|
3670 | if (hasInterceptors(this)) {
|
3671 | var change = interceptChange(this, {
|
3672 | type: UPDATE,
|
3673 | object: this.proxy_,
|
3674 | index: index,
|
3675 | newValue: newValue
|
3676 | });
|
3677 | if (!change) {
|
3678 | return;
|
3679 | }
|
3680 | newValue = change.newValue;
|
3681 | }
|
3682 | newValue = this.enhancer_(newValue, oldValue);
|
3683 | var changed = newValue !== oldValue;
|
3684 | if (changed) {
|
3685 | values[index] = newValue;
|
3686 | this.notifyArrayChildUpdate_(index, newValue, oldValue);
|
3687 | }
|
3688 | } else {
|
3689 |
|
3690 |
|
3691 |
|
3692 | var newItems = new Array(index + 1 - values.length);
|
3693 | for (var i = 0; i < newItems.length - 1; i++) {
|
3694 | newItems[i] = undefined;
|
3695 | }
|
3696 | newItems[newItems.length - 1] = newValue;
|
3697 | this.spliceWithArray_(values.length, 0, newItems);
|
3698 | }
|
3699 | };
|
3700 | return ObservableArrayAdministration;
|
3701 | }();
|
3702 | function createObservableArray(initialValues, enhancer, name, owned) {
|
3703 | if (name === void 0) {
|
3704 | name = process.env.NODE_ENV !== "production" ? "ObservableArray@" + getNextId() : "ObservableArray";
|
3705 | }
|
3706 | if (owned === void 0) {
|
3707 | owned = false;
|
3708 | }
|
3709 | assertProxies();
|
3710 | var adm = new ObservableArrayAdministration(name, enhancer, owned, false);
|
3711 | addHiddenFinalProp(adm.values_, $mobx, adm);
|
3712 | var proxy = new Proxy(adm.values_, arrayTraps);
|
3713 | adm.proxy_ = proxy;
|
3714 | if (initialValues && initialValues.length) {
|
3715 | var prev = allowStateChangesStart(true);
|
3716 | adm.spliceWithArray_(0, 0, initialValues);
|
3717 | allowStateChangesEnd(prev);
|
3718 | }
|
3719 | return proxy;
|
3720 | }
|
3721 |
|
3722 | var arrayExtensions = {
|
3723 | clear: function clear() {
|
3724 | return this.splice(0);
|
3725 | },
|
3726 | replace: function replace(newItems) {
|
3727 | var adm = this[$mobx];
|
3728 | return adm.spliceWithArray_(0, adm.values_.length, newItems);
|
3729 | },
|
3730 |
|
3731 | toJSON: function toJSON() {
|
3732 | return this.slice();
|
3733 | },
|
3734 | |
3735 |
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 | splice: function splice(index, deleteCount) {
|
3741 | for (var _len = arguments.length, newItems = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
3742 | newItems[_key - 2] = arguments[_key];
|
3743 | }
|
3744 | var adm = this[$mobx];
|
3745 | switch (arguments.length) {
|
3746 | case 0:
|
3747 | return [];
|
3748 | case 1:
|
3749 | return adm.spliceWithArray_(index);
|
3750 | case 2:
|
3751 | return adm.spliceWithArray_(index, deleteCount);
|
3752 | }
|
3753 | return adm.spliceWithArray_(index, deleteCount, newItems);
|
3754 | },
|
3755 | spliceWithArray: function spliceWithArray(index, deleteCount, newItems) {
|
3756 | return this[$mobx].spliceWithArray_(index, deleteCount, newItems);
|
3757 | },
|
3758 | push: function push() {
|
3759 | var adm = this[$mobx];
|
3760 | for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
3761 | items[_key2] = arguments[_key2];
|
3762 | }
|
3763 | adm.spliceWithArray_(adm.values_.length, 0, items);
|
3764 | return adm.values_.length;
|
3765 | },
|
3766 | pop: function pop() {
|
3767 | return this.splice(Math.max(this[$mobx].values_.length - 1, 0), 1)[0];
|
3768 | },
|
3769 | shift: function shift() {
|
3770 | return this.splice(0, 1)[0];
|
3771 | },
|
3772 | unshift: function unshift() {
|
3773 | var adm = this[$mobx];
|
3774 | for (var _len3 = arguments.length, items = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
3775 | items[_key3] = arguments[_key3];
|
3776 | }
|
3777 | adm.spliceWithArray_(0, 0, items);
|
3778 | return adm.values_.length;
|
3779 | },
|
3780 | reverse: function reverse() {
|
3781 |
|
3782 |
|
3783 | if (globalState.trackingDerivation) {
|
3784 | die(37, "reverse");
|
3785 | }
|
3786 | this.replace(this.slice().reverse());
|
3787 | return this;
|
3788 | },
|
3789 | sort: function sort() {
|
3790 |
|
3791 |
|
3792 | if (globalState.trackingDerivation) {
|
3793 | die(37, "sort");
|
3794 | }
|
3795 | var copy = this.slice();
|
3796 | copy.sort.apply(copy, arguments);
|
3797 | this.replace(copy);
|
3798 | return this;
|
3799 | },
|
3800 | remove: function remove(value) {
|
3801 | var adm = this[$mobx];
|
3802 | var idx = adm.dehanceValues_(adm.values_).indexOf(value);
|
3803 | if (idx > -1) {
|
3804 | this.splice(idx, 1);
|
3805 | return true;
|
3806 | }
|
3807 | return false;
|
3808 | }
|
3809 | };
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 | addArrayExtension("concat", simpleFunc);
|
3816 | addArrayExtension("flat", simpleFunc);
|
3817 | addArrayExtension("includes", simpleFunc);
|
3818 | addArrayExtension("indexOf", simpleFunc);
|
3819 | addArrayExtension("join", simpleFunc);
|
3820 | addArrayExtension("lastIndexOf", simpleFunc);
|
3821 | addArrayExtension("slice", simpleFunc);
|
3822 | addArrayExtension("toString", simpleFunc);
|
3823 | addArrayExtension("toLocaleString", simpleFunc);
|
3824 |
|
3825 | addArrayExtension("every", mapLikeFunc);
|
3826 | addArrayExtension("filter", mapLikeFunc);
|
3827 | addArrayExtension("find", mapLikeFunc);
|
3828 | addArrayExtension("findIndex", mapLikeFunc);
|
3829 | addArrayExtension("flatMap", mapLikeFunc);
|
3830 | addArrayExtension("forEach", mapLikeFunc);
|
3831 | addArrayExtension("map", mapLikeFunc);
|
3832 | addArrayExtension("some", mapLikeFunc);
|
3833 |
|
3834 | addArrayExtension("reduce", reduceLikeFunc);
|
3835 | addArrayExtension("reduceRight", reduceLikeFunc);
|
3836 | function addArrayExtension(funcName, funcFactory) {
|
3837 | if (typeof Array.prototype[funcName] === "function") {
|
3838 | arrayExtensions[funcName] = funcFactory(funcName);
|
3839 | }
|
3840 | }
|
3841 |
|
3842 | function simpleFunc(funcName) {
|
3843 | return function () {
|
3844 | var adm = this[$mobx];
|
3845 | adm.atom_.reportObserved();
|
3846 | var dehancedValues = adm.dehanceValues_(adm.values_);
|
3847 | return dehancedValues[funcName].apply(dehancedValues, arguments);
|
3848 | };
|
3849 | }
|
3850 |
|
3851 | function mapLikeFunc(funcName) {
|
3852 | return function (callback, thisArg) {
|
3853 | var _this2 = this;
|
3854 | var adm = this[$mobx];
|
3855 | adm.atom_.reportObserved();
|
3856 | var dehancedValues = adm.dehanceValues_(adm.values_);
|
3857 | return dehancedValues[funcName](function (element, index) {
|
3858 | return callback.call(thisArg, element, index, _this2);
|
3859 | });
|
3860 | };
|
3861 | }
|
3862 |
|
3863 | function reduceLikeFunc(funcName) {
|
3864 | return function () {
|
3865 | var _this3 = this;
|
3866 | var adm = this[$mobx];
|
3867 | adm.atom_.reportObserved();
|
3868 | var dehancedValues = adm.dehanceValues_(adm.values_);
|
3869 |
|
3870 | var callback = arguments[0];
|
3871 | arguments[0] = function (accumulator, currentValue, index) {
|
3872 | return callback(accumulator, currentValue, index, _this3);
|
3873 | };
|
3874 | return dehancedValues[funcName].apply(dehancedValues, arguments);
|
3875 | };
|
3876 | }
|
3877 | var isObservableArrayAdministration = createInstanceofPredicate("ObservableArrayAdministration", ObservableArrayAdministration);
|
3878 | function isObservableArray(thing) {
|
3879 | return isObject(thing) && isObservableArrayAdministration(thing[$mobx]);
|
3880 | }
|
3881 |
|
3882 | var _Symbol$iterator, _Symbol$toStringTag;
|
3883 | var ObservableMapMarker = {};
|
3884 | var ADD = "add";
|
3885 | var DELETE = "delete";
|
3886 |
|
3887 |
|
3888 | _Symbol$iterator = Symbol.iterator;
|
3889 | _Symbol$toStringTag = Symbol.toStringTag;
|
3890 | var ObservableMap = function () {
|
3891 |
|
3892 |
|
3893 | function ObservableMap(initialData, enhancer_, name_) {
|
3894 | var _this = this;
|
3895 | if (enhancer_ === void 0) {
|
3896 | enhancer_ = deepEnhancer;
|
3897 | }
|
3898 | if (name_ === void 0) {
|
3899 | name_ = process.env.NODE_ENV !== "production" ? "ObservableMap@" + getNextId() : "ObservableMap";
|
3900 | }
|
3901 | this.enhancer_ = void 0;
|
3902 | this.name_ = void 0;
|
3903 | this[$mobx] = ObservableMapMarker;
|
3904 | this.data_ = void 0;
|
3905 | this.hasMap_ = void 0;
|
3906 | this.keysAtom_ = void 0;
|
3907 | this.interceptors_ = void 0;
|
3908 | this.changeListeners_ = void 0;
|
3909 | this.dehancer = void 0;
|
3910 | this.enhancer_ = enhancer_;
|
3911 | this.name_ = name_;
|
3912 | if (!isFunction(Map)) {
|
3913 | die(18);
|
3914 | }
|
3915 | this.keysAtom_ = createAtom(process.env.NODE_ENV !== "production" ? this.name_ + ".keys()" : "ObservableMap.keys()");
|
3916 | this.data_ = new Map();
|
3917 | this.hasMap_ = new Map();
|
3918 | allowStateChanges(true, function () {
|
3919 | _this.merge(initialData);
|
3920 | });
|
3921 | }
|
3922 | var _proto = ObservableMap.prototype;
|
3923 | _proto.has_ = function has_(key) {
|
3924 | return this.data_.has(key);
|
3925 | };
|
3926 | _proto.has = function has(key) {
|
3927 | var _this2 = this;
|
3928 | if (!globalState.trackingDerivation) {
|
3929 | return this.has_(key);
|
3930 | }
|
3931 | var entry = this.hasMap_.get(key);
|
3932 | if (!entry) {
|
3933 | var newEntry = entry = new ObservableValue(this.has_(key), referenceEnhancer, process.env.NODE_ENV !== "production" ? this.name_ + "." + stringifyKey(key) + "?" : "ObservableMap.key?", false);
|
3934 | this.hasMap_.set(key, newEntry);
|
3935 | onBecomeUnobserved(newEntry, function () {
|
3936 | return _this2.hasMap_["delete"](key);
|
3937 | });
|
3938 | }
|
3939 | return entry.get();
|
3940 | };
|
3941 | _proto.set = function set(key, value) {
|
3942 | var hasKey = this.has_(key);
|
3943 | if (hasInterceptors(this)) {
|
3944 | var change = interceptChange(this, {
|
3945 | type: hasKey ? UPDATE : ADD,
|
3946 | object: this,
|
3947 | newValue: value,
|
3948 | name: key
|
3949 | });
|
3950 | if (!change) {
|
3951 | return this;
|
3952 | }
|
3953 | value = change.newValue;
|
3954 | }
|
3955 | if (hasKey) {
|
3956 | this.updateValue_(key, value);
|
3957 | } else {
|
3958 | this.addValue_(key, value);
|
3959 | }
|
3960 | return this;
|
3961 | };
|
3962 | _proto["delete"] = function _delete(key) {
|
3963 | var _this3 = this;
|
3964 | checkIfStateModificationsAreAllowed(this.keysAtom_);
|
3965 | if (hasInterceptors(this)) {
|
3966 | var change = interceptChange(this, {
|
3967 | type: DELETE,
|
3968 | object: this,
|
3969 | name: key
|
3970 | });
|
3971 | if (!change) {
|
3972 | return false;
|
3973 | }
|
3974 | }
|
3975 | if (this.has_(key)) {
|
3976 | var notifySpy = isSpyEnabled();
|
3977 | var notify = hasListeners(this);
|
3978 | var _change = notify || notifySpy ? {
|
3979 | observableKind: "map",
|
3980 | debugObjectName: this.name_,
|
3981 | type: DELETE,
|
3982 | object: this,
|
3983 | oldValue: this.data_.get(key).value_,
|
3984 | name: key
|
3985 | } : null;
|
3986 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
3987 | spyReportStart(_change);
|
3988 | }
|
3989 | transaction(function () {
|
3990 | var _this3$hasMap_$get;
|
3991 | _this3.keysAtom_.reportChanged();
|
3992 | (_this3$hasMap_$get = _this3.hasMap_.get(key)) == null ? void 0 : _this3$hasMap_$get.setNewValue_(false);
|
3993 | var observable = _this3.data_.get(key);
|
3994 | observable.setNewValue_(undefined);
|
3995 | _this3.data_["delete"](key);
|
3996 | });
|
3997 | if (notify) {
|
3998 | notifyListeners(this, _change);
|
3999 | }
|
4000 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4001 | spyReportEnd();
|
4002 | }
|
4003 | return true;
|
4004 | }
|
4005 | return false;
|
4006 | };
|
4007 | _proto.updateValue_ = function updateValue_(key, newValue) {
|
4008 | var observable = this.data_.get(key);
|
4009 | newValue = observable.prepareNewValue_(newValue);
|
4010 | if (newValue !== globalState.UNCHANGED) {
|
4011 | var notifySpy = isSpyEnabled();
|
4012 | var notify = hasListeners(this);
|
4013 | var change = notify || notifySpy ? {
|
4014 | observableKind: "map",
|
4015 | debugObjectName: this.name_,
|
4016 | type: UPDATE,
|
4017 | object: this,
|
4018 | oldValue: observable.value_,
|
4019 | name: key,
|
4020 | newValue: newValue
|
4021 | } : null;
|
4022 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4023 | spyReportStart(change);
|
4024 | }
|
4025 | observable.setNewValue_(newValue);
|
4026 | if (notify) {
|
4027 | notifyListeners(this, change);
|
4028 | }
|
4029 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4030 | spyReportEnd();
|
4031 | }
|
4032 | }
|
4033 | };
|
4034 | _proto.addValue_ = function addValue_(key, newValue) {
|
4035 | var _this4 = this;
|
4036 | checkIfStateModificationsAreAllowed(this.keysAtom_);
|
4037 | transaction(function () {
|
4038 | var _this4$hasMap_$get;
|
4039 | var observable = new ObservableValue(newValue, _this4.enhancer_, process.env.NODE_ENV !== "production" ? _this4.name_ + "." + stringifyKey(key) : "ObservableMap.key", false);
|
4040 | _this4.data_.set(key, observable);
|
4041 | newValue = observable.value_; // value might have been changed
|
4042 | (_this4$hasMap_$get = _this4.hasMap_.get(key)) == null ? void 0 : _this4$hasMap_$get.setNewValue_(true);
|
4043 | _this4.keysAtom_.reportChanged();
|
4044 | });
|
4045 | var notifySpy = isSpyEnabled();
|
4046 | var notify = hasListeners(this);
|
4047 | var change = notify || notifySpy ? {
|
4048 | observableKind: "map",
|
4049 | debugObjectName: this.name_,
|
4050 | type: ADD,
|
4051 | object: this,
|
4052 | name: key,
|
4053 | newValue: newValue
|
4054 | } : null;
|
4055 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4056 | spyReportStart(change);
|
4057 | }
|
4058 | if (notify) {
|
4059 | notifyListeners(this, change);
|
4060 | }
|
4061 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4062 | spyReportEnd();
|
4063 | }
|
4064 | };
|
4065 | _proto.get = function get(key) {
|
4066 | if (this.has(key)) {
|
4067 | return this.dehanceValue_(this.data_.get(key).get());
|
4068 | }
|
4069 | return this.dehanceValue_(undefined);
|
4070 | };
|
4071 | _proto.dehanceValue_ = function dehanceValue_(value) {
|
4072 | if (this.dehancer !== undefined) {
|
4073 | return this.dehancer(value);
|
4074 | }
|
4075 | return value;
|
4076 | };
|
4077 | _proto.keys = function keys() {
|
4078 | this.keysAtom_.reportObserved();
|
4079 | return this.data_.keys();
|
4080 | };
|
4081 | _proto.values = function values() {
|
4082 | var self = this;
|
4083 | var keys = this.keys();
|
4084 | return makeIterable({
|
4085 | next: function next() {
|
4086 | var _keys$next = keys.next(),
|
4087 | done = _keys$next.done,
|
4088 | value = _keys$next.value;
|
4089 | return {
|
4090 | done: done,
|
4091 | value: done ? undefined : self.get(value)
|
4092 | };
|
4093 | }
|
4094 | });
|
4095 | };
|
4096 | _proto.entries = function entries() {
|
4097 | var self = this;
|
4098 | var keys = this.keys();
|
4099 | return makeIterable({
|
4100 | next: function next() {
|
4101 | var _keys$next2 = keys.next(),
|
4102 | done = _keys$next2.done,
|
4103 | value = _keys$next2.value;
|
4104 | return {
|
4105 | done: done,
|
4106 | value: done ? undefined : [value, self.get(value)]
|
4107 | };
|
4108 | }
|
4109 | });
|
4110 | };
|
4111 | _proto[_Symbol$iterator] = function () {
|
4112 | return this.entries();
|
4113 | };
|
4114 | _proto.forEach = function forEach(callback, thisArg) {
|
4115 | for (var _iterator = _createForOfIteratorHelperLoose(this), _step; !(_step = _iterator()).done;) {
|
4116 | var _step$value = _step.value,
|
4117 | key = _step$value[0],
|
4118 | value = _step$value[1];
|
4119 | callback.call(thisArg, value, key, this);
|
4120 | }
|
4121 | }
|
4122 | ;
|
4123 | _proto.merge = function merge(other) {
|
4124 | var _this5 = this;
|
4125 | if (isObservableMap(other)) {
|
4126 | other = new Map(other);
|
4127 | }
|
4128 | transaction(function () {
|
4129 | if (isPlainObject(other)) {
|
4130 | getPlainObjectKeys(other).forEach(function (key) {
|
4131 | return _this5.set(key, other[key]);
|
4132 | });
|
4133 | } else if (Array.isArray(other)) {
|
4134 | other.forEach(function (_ref) {
|
4135 | var key = _ref[0],
|
4136 | value = _ref[1];
|
4137 | return _this5.set(key, value);
|
4138 | });
|
4139 | } else if (isES6Map(other)) {
|
4140 | if (other.constructor !== Map) {
|
4141 | die(19, other);
|
4142 | }
|
4143 | other.forEach(function (value, key) {
|
4144 | return _this5.set(key, value);
|
4145 | });
|
4146 | } else if (other !== null && other !== undefined) {
|
4147 | die(20, other);
|
4148 | }
|
4149 | });
|
4150 | return this;
|
4151 | };
|
4152 | _proto.clear = function clear() {
|
4153 | var _this6 = this;
|
4154 | transaction(function () {
|
4155 | untracked(function () {
|
4156 | for (var _iterator2 = _createForOfIteratorHelperLoose(_this6.keys()), _step2; !(_step2 = _iterator2()).done;) {
|
4157 | var key = _step2.value;
|
4158 | _this6["delete"](key);
|
4159 | }
|
4160 | });
|
4161 | });
|
4162 | };
|
4163 | _proto.replace = function replace(values) {
|
4164 | var _this7 = this;
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 | transaction(function () {
|
4172 |
|
4173 | var replacementMap = convertToMap(values);
|
4174 | var orderedData = new Map();
|
4175 |
|
4176 | var keysReportChangedCalled = false;
|
4177 |
|
4178 |
|
4179 |
|
4180 | for (var _iterator3 = _createForOfIteratorHelperLoose(_this7.data_.keys()), _step3; !(_step3 = _iterator3()).done;) {
|
4181 | var key = _step3.value;
|
4182 |
|
4183 |
|
4184 | if (!replacementMap.has(key)) {
|
4185 | var deleted = _this7["delete"](key);
|
4186 |
|
4187 | if (deleted) {
|
4188 |
|
4189 | keysReportChangedCalled = true;
|
4190 | } else {
|
4191 |
|
4192 | var value = _this7.data_.get(key);
|
4193 | orderedData.set(key, value);
|
4194 | }
|
4195 | }
|
4196 | }
|
4197 |
|
4198 | for (var _iterator4 = _createForOfIteratorHelperLoose(replacementMap.entries()), _step4; !(_step4 = _iterator4()).done;) {
|
4199 | var _step4$value = _step4.value,
|
4200 | _key = _step4$value[0],
|
4201 | _value = _step4$value[1];
|
4202 |
|
4203 | var keyExisted = _this7.data_.has(_key);
|
4204 |
|
4205 | _this7.set(_key, _value);
|
4206 |
|
4207 | if (_this7.data_.has(_key)) {
|
4208 |
|
4209 |
|
4210 |
|
4211 | var _value2 = _this7.data_.get(_key);
|
4212 | orderedData.set(_key, _value2);
|
4213 |
|
4214 | if (!keyExisted) {
|
4215 |
|
4216 | keysReportChangedCalled = true;
|
4217 | }
|
4218 | }
|
4219 | }
|
4220 |
|
4221 | if (!keysReportChangedCalled) {
|
4222 | if (_this7.data_.size !== orderedData.size) {
|
4223 |
|
4224 | _this7.keysAtom_.reportChanged();
|
4225 | } else {
|
4226 | var iter1 = _this7.data_.keys();
|
4227 | var iter2 = orderedData.keys();
|
4228 | var next1 = iter1.next();
|
4229 | var next2 = iter2.next();
|
4230 | while (!next1.done) {
|
4231 | if (next1.value !== next2.value) {
|
4232 | _this7.keysAtom_.reportChanged();
|
4233 | break;
|
4234 | }
|
4235 | next1 = iter1.next();
|
4236 | next2 = iter2.next();
|
4237 | }
|
4238 | }
|
4239 | }
|
4240 |
|
4241 | _this7.data_ = orderedData;
|
4242 | });
|
4243 | return this;
|
4244 | };
|
4245 | _proto.toString = function toString() {
|
4246 | return "[object ObservableMap]";
|
4247 | };
|
4248 | _proto.toJSON = function toJSON() {
|
4249 | return Array.from(this);
|
4250 | };
|
4251 | |
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 | _proto.observe_ = function observe_(listener, fireImmediately) {
|
4257 | if (process.env.NODE_ENV !== "production" && fireImmediately === true) {
|
4258 | die("`observe` doesn't support fireImmediately=true in combination with maps.");
|
4259 | }
|
4260 | return registerListener(this, listener);
|
4261 | };
|
4262 | _proto.intercept_ = function intercept_(handler) {
|
4263 | return registerInterceptor(this, handler);
|
4264 | };
|
4265 | _createClass(ObservableMap, [{
|
4266 | key: "size",
|
4267 | get: function get() {
|
4268 | this.keysAtom_.reportObserved();
|
4269 | return this.data_.size;
|
4270 | }
|
4271 | }, {
|
4272 | key: _Symbol$toStringTag,
|
4273 | get: function get() {
|
4274 | return "Map";
|
4275 | }
|
4276 | }]);
|
4277 | return ObservableMap;
|
4278 | }();
|
4279 |
|
4280 | var isObservableMap = createInstanceofPredicate("ObservableMap", ObservableMap);
|
4281 | function convertToMap(dataStructure) {
|
4282 | if (isES6Map(dataStructure) || isObservableMap(dataStructure)) {
|
4283 | return dataStructure;
|
4284 | } else if (Array.isArray(dataStructure)) {
|
4285 | return new Map(dataStructure);
|
4286 | } else if (isPlainObject(dataStructure)) {
|
4287 | var map = new Map();
|
4288 | for (var key in dataStructure) {
|
4289 | map.set(key, dataStructure[key]);
|
4290 | }
|
4291 | return map;
|
4292 | } else {
|
4293 | return die(21, dataStructure);
|
4294 | }
|
4295 | }
|
4296 |
|
4297 | var _Symbol$iterator$1, _Symbol$toStringTag$1;
|
4298 | var ObservableSetMarker = {};
|
4299 | _Symbol$iterator$1 = Symbol.iterator;
|
4300 | _Symbol$toStringTag$1 = Symbol.toStringTag;
|
4301 | var ObservableSet = function () {
|
4302 | function ObservableSet(initialData, enhancer, name_) {
|
4303 | if (enhancer === void 0) {
|
4304 | enhancer = deepEnhancer;
|
4305 | }
|
4306 | if (name_ === void 0) {
|
4307 | name_ = process.env.NODE_ENV !== "production" ? "ObservableSet@" + getNextId() : "ObservableSet";
|
4308 | }
|
4309 | this.name_ = void 0;
|
4310 | this[$mobx] = ObservableSetMarker;
|
4311 | this.data_ = new Set();
|
4312 | this.atom_ = void 0;
|
4313 | this.changeListeners_ = void 0;
|
4314 | this.interceptors_ = void 0;
|
4315 | this.dehancer = void 0;
|
4316 | this.enhancer_ = void 0;
|
4317 | this.name_ = name_;
|
4318 | if (!isFunction(Set)) {
|
4319 | die(22);
|
4320 | }
|
4321 | this.atom_ = createAtom(this.name_);
|
4322 | this.enhancer_ = function (newV, oldV) {
|
4323 | return enhancer(newV, oldV, name_);
|
4324 | };
|
4325 | if (initialData) {
|
4326 | this.replace(initialData);
|
4327 | }
|
4328 | }
|
4329 | var _proto = ObservableSet.prototype;
|
4330 | _proto.dehanceValue_ = function dehanceValue_(value) {
|
4331 | if (this.dehancer !== undefined) {
|
4332 | return this.dehancer(value);
|
4333 | }
|
4334 | return value;
|
4335 | };
|
4336 | _proto.clear = function clear() {
|
4337 | var _this = this;
|
4338 | transaction(function () {
|
4339 | untracked(function () {
|
4340 | for (var _iterator = _createForOfIteratorHelperLoose(_this.data_.values()), _step; !(_step = _iterator()).done;) {
|
4341 | var value = _step.value;
|
4342 | _this["delete"](value);
|
4343 | }
|
4344 | });
|
4345 | });
|
4346 | };
|
4347 | _proto.forEach = function forEach(callbackFn, thisArg) {
|
4348 | for (var _iterator2 = _createForOfIteratorHelperLoose(this), _step2; !(_step2 = _iterator2()).done;) {
|
4349 | var value = _step2.value;
|
4350 | callbackFn.call(thisArg, value, value, this);
|
4351 | }
|
4352 | };
|
4353 | _proto.add = function add(value) {
|
4354 | var _this2 = this;
|
4355 | checkIfStateModificationsAreAllowed(this.atom_);
|
4356 | if (hasInterceptors(this)) {
|
4357 | var change = interceptChange(this, {
|
4358 | type: ADD,
|
4359 | object: this,
|
4360 | newValue: value
|
4361 | });
|
4362 | if (!change) {
|
4363 | return this;
|
4364 | }
|
4365 |
|
4366 |
|
4367 | }
|
4368 |
|
4369 | if (!this.has(value)) {
|
4370 | transaction(function () {
|
4371 | _this2.data_.add(_this2.enhancer_(value, undefined));
|
4372 | _this2.atom_.reportChanged();
|
4373 | });
|
4374 | var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
4375 | var notify = hasListeners(this);
|
4376 | var _change = notify || notifySpy ? {
|
4377 | observableKind: "set",
|
4378 | debugObjectName: this.name_,
|
4379 | type: ADD,
|
4380 | object: this,
|
4381 | newValue: value
|
4382 | } : null;
|
4383 | if (notifySpy && process.env.NODE_ENV !== "production") {
|
4384 | spyReportStart(_change);
|
4385 | }
|
4386 | if (notify) {
|
4387 | notifyListeners(this, _change);
|
4388 | }
|
4389 | if (notifySpy && process.env.NODE_ENV !== "production") {
|
4390 | spyReportEnd();
|
4391 | }
|
4392 | }
|
4393 | return this;
|
4394 | };
|
4395 | _proto["delete"] = function _delete(value) {
|
4396 | var _this3 = this;
|
4397 | if (hasInterceptors(this)) {
|
4398 | var change = interceptChange(this, {
|
4399 | type: DELETE,
|
4400 | object: this,
|
4401 | oldValue: value
|
4402 | });
|
4403 | if (!change) {
|
4404 | return false;
|
4405 | }
|
4406 | }
|
4407 | if (this.has(value)) {
|
4408 | var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
4409 | var notify = hasListeners(this);
|
4410 | var _change2 = notify || notifySpy ? {
|
4411 | observableKind: "set",
|
4412 | debugObjectName: this.name_,
|
4413 | type: DELETE,
|
4414 | object: this,
|
4415 | oldValue: value
|
4416 | } : null;
|
4417 | if (notifySpy && process.env.NODE_ENV !== "production") {
|
4418 | spyReportStart(_change2);
|
4419 | }
|
4420 | transaction(function () {
|
4421 | _this3.atom_.reportChanged();
|
4422 | _this3.data_["delete"](value);
|
4423 | });
|
4424 | if (notify) {
|
4425 | notifyListeners(this, _change2);
|
4426 | }
|
4427 | if (notifySpy && process.env.NODE_ENV !== "production") {
|
4428 | spyReportEnd();
|
4429 | }
|
4430 | return true;
|
4431 | }
|
4432 | return false;
|
4433 | };
|
4434 | _proto.has = function has(value) {
|
4435 | this.atom_.reportObserved();
|
4436 | return this.data_.has(this.dehanceValue_(value));
|
4437 | };
|
4438 | _proto.entries = function entries() {
|
4439 | var nextIndex = 0;
|
4440 | var keys = Array.from(this.keys());
|
4441 | var values = Array.from(this.values());
|
4442 | return makeIterable({
|
4443 | next: function next() {
|
4444 | var index = nextIndex;
|
4445 | nextIndex += 1;
|
4446 | return index < values.length ? {
|
4447 | value: [keys[index], values[index]],
|
4448 | done: false
|
4449 | } : {
|
4450 | done: true
|
4451 | };
|
4452 | }
|
4453 | });
|
4454 | };
|
4455 | _proto.keys = function keys() {
|
4456 | return this.values();
|
4457 | };
|
4458 | _proto.values = function values() {
|
4459 | this.atom_.reportObserved();
|
4460 | var self = this;
|
4461 | var nextIndex = 0;
|
4462 | var observableValues = Array.from(this.data_.values());
|
4463 | return makeIterable({
|
4464 | next: function next() {
|
4465 | return nextIndex < observableValues.length ? {
|
4466 | value: self.dehanceValue_(observableValues[nextIndex++]),
|
4467 | done: false
|
4468 | } : {
|
4469 | done: true
|
4470 | };
|
4471 | }
|
4472 | });
|
4473 | };
|
4474 | _proto.replace = function replace(other) {
|
4475 | var _this4 = this;
|
4476 | if (isObservableSet(other)) {
|
4477 | other = new Set(other);
|
4478 | }
|
4479 | transaction(function () {
|
4480 | if (Array.isArray(other)) {
|
4481 | _this4.clear();
|
4482 | other.forEach(function (value) {
|
4483 | return _this4.add(value);
|
4484 | });
|
4485 | } else if (isES6Set(other)) {
|
4486 | _this4.clear();
|
4487 | other.forEach(function (value) {
|
4488 | return _this4.add(value);
|
4489 | });
|
4490 | } else if (other !== null && other !== undefined) {
|
4491 | die("Cannot initialize set from " + other);
|
4492 | }
|
4493 | });
|
4494 | return this;
|
4495 | };
|
4496 | _proto.observe_ = function observe_(listener, fireImmediately) {
|
4497 |
|
4498 | if (process.env.NODE_ENV !== "production" && fireImmediately === true) {
|
4499 | die("`observe` doesn't support fireImmediately=true in combination with sets.");
|
4500 | }
|
4501 | return registerListener(this, listener);
|
4502 | };
|
4503 | _proto.intercept_ = function intercept_(handler) {
|
4504 | return registerInterceptor(this, handler);
|
4505 | };
|
4506 | _proto.toJSON = function toJSON() {
|
4507 | return Array.from(this);
|
4508 | };
|
4509 | _proto.toString = function toString() {
|
4510 | return "[object ObservableSet]";
|
4511 | };
|
4512 | _proto[_Symbol$iterator$1] = function () {
|
4513 | return this.values();
|
4514 | };
|
4515 | _createClass(ObservableSet, [{
|
4516 | key: "size",
|
4517 | get: function get() {
|
4518 | this.atom_.reportObserved();
|
4519 | return this.data_.size;
|
4520 | }
|
4521 | }, {
|
4522 | key: _Symbol$toStringTag$1,
|
4523 | get: function get() {
|
4524 | return "Set";
|
4525 | }
|
4526 | }]);
|
4527 | return ObservableSet;
|
4528 | }();
|
4529 |
|
4530 | var isObservableSet = createInstanceofPredicate("ObservableSet", ObservableSet);
|
4531 |
|
4532 | var descriptorCache = Object.create(null);
|
4533 | var REMOVE = "remove";
|
4534 | var ObservableObjectAdministration = function () {
|
4535 | function ObservableObjectAdministration(target_, values_, name_,
|
4536 | // Used anytime annotation is not explicitely provided
|
4537 | defaultAnnotation_) {
|
4538 | if (values_ === void 0) {
|
4539 | values_ = new Map();
|
4540 | }
|
4541 | if (defaultAnnotation_ === void 0) {
|
4542 | defaultAnnotation_ = autoAnnotation;
|
4543 | }
|
4544 | this.target_ = void 0;
|
4545 | this.values_ = void 0;
|
4546 | this.name_ = void 0;
|
4547 | this.defaultAnnotation_ = void 0;
|
4548 | this.keysAtom_ = void 0;
|
4549 | this.changeListeners_ = void 0;
|
4550 | this.interceptors_ = void 0;
|
4551 | this.proxy_ = void 0;
|
4552 | this.isPlainObject_ = void 0;
|
4553 | this.appliedAnnotations_ = void 0;
|
4554 | this.pendingKeys_ = void 0;
|
4555 | this.target_ = target_;
|
4556 | this.values_ = values_;
|
4557 | this.name_ = name_;
|
4558 | this.defaultAnnotation_ = defaultAnnotation_;
|
4559 | this.keysAtom_ = new Atom(process.env.NODE_ENV !== "production" ? this.name_ + ".keys" : "ObservableObject.keys");
|
4560 |
|
4561 | this.isPlainObject_ = isPlainObject(this.target_);
|
4562 | if (process.env.NODE_ENV !== "production" && !isAnnotation(this.defaultAnnotation_)) {
|
4563 | die("defaultAnnotation must be valid annotation");
|
4564 | }
|
4565 | if (process.env.NODE_ENV !== "production") {
|
4566 |
|
4567 | this.appliedAnnotations_ = {};
|
4568 | }
|
4569 | }
|
4570 | var _proto = ObservableObjectAdministration.prototype;
|
4571 | _proto.getObservablePropValue_ = function getObservablePropValue_(key) {
|
4572 | return this.values_.get(key).get();
|
4573 | };
|
4574 | _proto.setObservablePropValue_ = function setObservablePropValue_(key, newValue) {
|
4575 | var observable = this.values_.get(key);
|
4576 | if (observable instanceof ComputedValue) {
|
4577 | observable.set(newValue);
|
4578 | return true;
|
4579 | }
|
4580 |
|
4581 | if (hasInterceptors(this)) {
|
4582 | var change = interceptChange(this, {
|
4583 | type: UPDATE,
|
4584 | object: this.proxy_ || this.target_,
|
4585 | name: key,
|
4586 | newValue: newValue
|
4587 | });
|
4588 | if (!change) {
|
4589 | return null;
|
4590 | }
|
4591 | newValue = change.newValue;
|
4592 | }
|
4593 | newValue = observable.prepareNewValue_(newValue);
|
4594 |
|
4595 | if (newValue !== globalState.UNCHANGED) {
|
4596 | var notify = hasListeners(this);
|
4597 | var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
4598 | var _change = notify || notifySpy ? {
|
4599 | type: UPDATE,
|
4600 | observableKind: "object",
|
4601 | debugObjectName: this.name_,
|
4602 | object: this.proxy_ || this.target_,
|
4603 | oldValue: observable.value_,
|
4604 | name: key,
|
4605 | newValue: newValue
|
4606 | } : null;
|
4607 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4608 | spyReportStart(_change);
|
4609 | }
|
4610 | observable.setNewValue_(newValue);
|
4611 | if (notify) {
|
4612 | notifyListeners(this, _change);
|
4613 | }
|
4614 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4615 | spyReportEnd();
|
4616 | }
|
4617 | }
|
4618 | return true;
|
4619 | };
|
4620 | _proto.get_ = function get_(key) {
|
4621 | if (globalState.trackingDerivation && !hasProp(this.target_, key)) {
|
4622 |
|
4623 | this.has_(key);
|
4624 | }
|
4625 | return this.target_[key];
|
4626 | }
|
4627 | |
4628 |
|
4629 |
|
4630 |
|
4631 |
|
4632 |
|
4633 | ;
|
4634 | _proto.set_ = function set_(key, value, proxyTrap) {
|
4635 | if (proxyTrap === void 0) {
|
4636 | proxyTrap = false;
|
4637 | }
|
4638 |
|
4639 | if (hasProp(this.target_, key)) {
|
4640 |
|
4641 | if (this.values_.has(key)) {
|
4642 |
|
4643 | return this.setObservablePropValue_(key, value);
|
4644 | } else if (proxyTrap) {
|
4645 |
|
4646 | return Reflect.set(this.target_, key, value);
|
4647 | } else {
|
4648 |
|
4649 | this.target_[key] = value;
|
4650 | return true;
|
4651 | }
|
4652 | } else {
|
4653 |
|
4654 | return this.extend_(key, {
|
4655 | value: value,
|
4656 | enumerable: true,
|
4657 | writable: true,
|
4658 | configurable: true
|
4659 | }, this.defaultAnnotation_, proxyTrap);
|
4660 | }
|
4661 | }
|
4662 |
|
4663 | ;
|
4664 | _proto.has_ = function has_(key) {
|
4665 | if (!globalState.trackingDerivation) {
|
4666 |
|
4667 | return key in this.target_;
|
4668 | }
|
4669 | this.pendingKeys_ || (this.pendingKeys_ = new Map());
|
4670 | var entry = this.pendingKeys_.get(key);
|
4671 | if (!entry) {
|
4672 | entry = new ObservableValue(key in this.target_, referenceEnhancer, process.env.NODE_ENV !== "production" ? this.name_ + "." + stringifyKey(key) + "?" : "ObservableObject.key?", false);
|
4673 | this.pendingKeys_.set(key, entry);
|
4674 | }
|
4675 | return entry.get();
|
4676 | }
|
4677 | |
4678 |
|
4679 |
|
4680 | ;
|
4681 | _proto.make_ = function make_(key, annotation) {
|
4682 | if (annotation === true) {
|
4683 | annotation = this.defaultAnnotation_;
|
4684 | }
|
4685 | if (annotation === false) {
|
4686 | return;
|
4687 | }
|
4688 | assertAnnotable(this, annotation, key);
|
4689 | if (!(key in this.target_)) {
|
4690 | var _this$target_$storedA;
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 | if ((_this$target_$storedA = this.target_[storedAnnotationsSymbol]) != null && _this$target_$storedA[key]) {
|
4697 | return;
|
4698 | } else {
|
4699 | die(1, annotation.annotationType_, this.name_ + "." + key.toString());
|
4700 | }
|
4701 | }
|
4702 | var source = this.target_;
|
4703 | while (source && source !== objectPrototype) {
|
4704 | var descriptor = getDescriptor(source, key);
|
4705 | if (descriptor) {
|
4706 | var outcome = annotation.make_(this, key, descriptor, source);
|
4707 | if (outcome === 0 ) {
|
4708 | return;
|
4709 | }
|
4710 | if (outcome === 1 ) {
|
4711 | break;
|
4712 | }
|
4713 | }
|
4714 | source = Object.getPrototypeOf(source);
|
4715 | }
|
4716 | recordAnnotationApplied(this, annotation, key);
|
4717 | }
|
4718 | |
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 | ;
|
4725 | _proto.extend_ = function extend_(key, descriptor, annotation, proxyTrap) {
|
4726 | if (proxyTrap === void 0) {
|
4727 | proxyTrap = false;
|
4728 | }
|
4729 | if (annotation === true) {
|
4730 | annotation = this.defaultAnnotation_;
|
4731 | }
|
4732 | if (annotation === false) {
|
4733 | return this.defineProperty_(key, descriptor, proxyTrap);
|
4734 | }
|
4735 | assertAnnotable(this, annotation, key);
|
4736 | var outcome = annotation.extend_(this, key, descriptor, proxyTrap);
|
4737 | if (outcome) {
|
4738 | recordAnnotationApplied(this, annotation, key);
|
4739 | }
|
4740 | return outcome;
|
4741 | }
|
4742 | |
4743 |
|
4744 |
|
4745 |
|
4746 |
|
4747 | ;
|
4748 | _proto.defineProperty_ = function defineProperty_(key, descriptor, proxyTrap) {
|
4749 | if (proxyTrap === void 0) {
|
4750 | proxyTrap = false;
|
4751 | }
|
4752 | try {
|
4753 | startBatch();
|
4754 |
|
4755 | var deleteOutcome = this.delete_(key);
|
4756 | if (!deleteOutcome) {
|
4757 |
|
4758 | return deleteOutcome;
|
4759 | }
|
4760 |
|
4761 | if (hasInterceptors(this)) {
|
4762 | var change = interceptChange(this, {
|
4763 | object: this.proxy_ || this.target_,
|
4764 | name: key,
|
4765 | type: ADD,
|
4766 | newValue: descriptor.value
|
4767 | });
|
4768 | if (!change) {
|
4769 | return null;
|
4770 | }
|
4771 | var newValue = change.newValue;
|
4772 | if (descriptor.value !== newValue) {
|
4773 | descriptor = _extends({}, descriptor, {
|
4774 | value: newValue
|
4775 | });
|
4776 | }
|
4777 | }
|
4778 |
|
4779 | if (proxyTrap) {
|
4780 | if (!Reflect.defineProperty(this.target_, key, descriptor)) {
|
4781 | return false;
|
4782 | }
|
4783 | } else {
|
4784 | defineProperty(this.target_, key, descriptor);
|
4785 | }
|
4786 |
|
4787 | this.notifyPropertyAddition_(key, descriptor.value);
|
4788 | } finally {
|
4789 | endBatch();
|
4790 | }
|
4791 | return true;
|
4792 | }
|
4793 |
|
4794 | ;
|
4795 | _proto.defineObservableProperty_ = function defineObservableProperty_(key, value, enhancer, proxyTrap) {
|
4796 | if (proxyTrap === void 0) {
|
4797 | proxyTrap = false;
|
4798 | }
|
4799 | try {
|
4800 | startBatch();
|
4801 |
|
4802 | var deleteOutcome = this.delete_(key);
|
4803 | if (!deleteOutcome) {
|
4804 |
|
4805 | return deleteOutcome;
|
4806 | }
|
4807 |
|
4808 | if (hasInterceptors(this)) {
|
4809 | var change = interceptChange(this, {
|
4810 | object: this.proxy_ || this.target_,
|
4811 | name: key,
|
4812 | type: ADD,
|
4813 | newValue: value
|
4814 | });
|
4815 | if (!change) {
|
4816 | return null;
|
4817 | }
|
4818 | value = change.newValue;
|
4819 | }
|
4820 | var cachedDescriptor = getCachedObservablePropDescriptor(key);
|
4821 | var descriptor = {
|
4822 | configurable: globalState.safeDescriptors ? this.isPlainObject_ : true,
|
4823 | enumerable: true,
|
4824 | get: cachedDescriptor.get,
|
4825 | set: cachedDescriptor.set
|
4826 | };
|
4827 | // Define
|
4828 | if (proxyTrap) {
|
4829 | if (!Reflect.defineProperty(this.target_, key, descriptor)) {
|
4830 | return false;
|
4831 | }
|
4832 | } else {
|
4833 | defineProperty(this.target_, key, descriptor);
|
4834 | }
|
4835 | var observable = new ObservableValue(value, enhancer, process.env.NODE_ENV !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key", false);
|
4836 | this.values_.set(key, observable);
|
4837 |
|
4838 | this.notifyPropertyAddition_(key, observable.value_);
|
4839 | } finally {
|
4840 | endBatch();
|
4841 | }
|
4842 | return true;
|
4843 | }
|
4844 |
|
4845 | ;
|
4846 | _proto.defineComputedProperty_ = function defineComputedProperty_(key, options, proxyTrap) {
|
4847 | if (proxyTrap === void 0) {
|
4848 | proxyTrap = false;
|
4849 | }
|
4850 | try {
|
4851 | startBatch();
|
4852 |
|
4853 | var deleteOutcome = this.delete_(key);
|
4854 | if (!deleteOutcome) {
|
4855 |
|
4856 | return deleteOutcome;
|
4857 | }
|
4858 |
|
4859 | if (hasInterceptors(this)) {
|
4860 | var change = interceptChange(this, {
|
4861 | object: this.proxy_ || this.target_,
|
4862 | name: key,
|
4863 | type: ADD,
|
4864 | newValue: undefined
|
4865 | });
|
4866 | if (!change) {
|
4867 | return null;
|
4868 | }
|
4869 | }
|
4870 | options.name || (options.name = process.env.NODE_ENV !== "production" ? this.name_ + "." + key.toString() : "ObservableObject.key");
|
4871 | options.context = this.proxy_ || this.target_;
|
4872 | var cachedDescriptor = getCachedObservablePropDescriptor(key);
|
4873 | var descriptor = {
|
4874 | configurable: globalState.safeDescriptors ? this.isPlainObject_ : true,
|
4875 | enumerable: false,
|
4876 | get: cachedDescriptor.get,
|
4877 | set: cachedDescriptor.set
|
4878 | };
|
4879 | // Define
|
4880 | if (proxyTrap) {
|
4881 | if (!Reflect.defineProperty(this.target_, key, descriptor)) {
|
4882 | return false;
|
4883 | }
|
4884 | } else {
|
4885 | defineProperty(this.target_, key, descriptor);
|
4886 | }
|
4887 | this.values_.set(key, new ComputedValue(options));
|
4888 |
|
4889 | this.notifyPropertyAddition_(key, undefined);
|
4890 | } finally {
|
4891 | endBatch();
|
4892 | }
|
4893 | return true;
|
4894 | }
|
4895 | |
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 | ;
|
4901 | _proto.delete_ = function delete_(key, proxyTrap) {
|
4902 | if (proxyTrap === void 0) {
|
4903 | proxyTrap = false;
|
4904 | }
|
4905 |
|
4906 | if (!hasProp(this.target_, key)) {
|
4907 | return true;
|
4908 | }
|
4909 |
|
4910 | if (hasInterceptors(this)) {
|
4911 | var change = interceptChange(this, {
|
4912 | object: this.proxy_ || this.target_,
|
4913 | name: key,
|
4914 | type: REMOVE
|
4915 | });
|
4916 |
|
4917 | if (!change) {
|
4918 | return null;
|
4919 | }
|
4920 | }
|
4921 |
|
4922 | try {
|
4923 | var _this$pendingKeys_, _this$pendingKeys_$ge;
|
4924 | startBatch();
|
4925 | var notify = hasListeners(this);
|
4926 | var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
4927 | var observable = this.values_.get(key);
|
4928 |
|
4929 | var value = undefined;
|
4930 |
|
4931 | if (!observable && (notify || notifySpy)) {
|
4932 | var _getDescriptor;
|
4933 | value = (_getDescriptor = getDescriptor(this.target_, key)) == null ? void 0 : _getDescriptor.value;
|
4934 | }
|
4935 |
|
4936 | if (proxyTrap) {
|
4937 | if (!Reflect.deleteProperty(this.target_, key)) {
|
4938 | return false;
|
4939 | }
|
4940 | } else {
|
4941 | delete this.target_[key];
|
4942 | }
|
4943 |
|
4944 | if (process.env.NODE_ENV !== "production") {
|
4945 | delete this.appliedAnnotations_[key];
|
4946 | }
|
4947 |
|
4948 | if (observable) {
|
4949 | this.values_["delete"](key);
|
4950 |
|
4951 | if (observable instanceof ObservableValue) {
|
4952 | value = observable.value_;
|
4953 | }
|
4954 |
|
4955 | propagateChanged(observable);
|
4956 | }
|
4957 |
|
4958 | this.keysAtom_.reportChanged();
|
4959 |
|
4960 |
|
4961 | (_this$pendingKeys_ = this.pendingKeys_) == null ? void 0 : (_this$pendingKeys_$ge = _this$pendingKeys_.get(key)) == null ? void 0 : _this$pendingKeys_$ge.set(key in this.target_);
|
4962 |
|
4963 | if (notify || notifySpy) {
|
4964 | var _change2 = {
|
4965 | type: REMOVE,
|
4966 | observableKind: "object",
|
4967 | object: this.proxy_ || this.target_,
|
4968 | debugObjectName: this.name_,
|
4969 | oldValue: value,
|
4970 | name: key
|
4971 | };
|
4972 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4973 | spyReportStart(_change2);
|
4974 | }
|
4975 | if (notify) {
|
4976 | notifyListeners(this, _change2);
|
4977 | }
|
4978 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
4979 | spyReportEnd();
|
4980 | }
|
4981 | }
|
4982 | } finally {
|
4983 | endBatch();
|
4984 | }
|
4985 | return true;
|
4986 | }
|
4987 | |
4988 |
|
4989 |
|
4990 |
|
4991 | ;
|
4992 | _proto.observe_ = function observe_(callback, fireImmediately) {
|
4993 | if (process.env.NODE_ENV !== "production" && fireImmediately === true) {
|
4994 | die("`observe` doesn't support the fire immediately property for observable objects.");
|
4995 | }
|
4996 | return registerListener(this, callback);
|
4997 | };
|
4998 | _proto.intercept_ = function intercept_(handler) {
|
4999 | return registerInterceptor(this, handler);
|
5000 | };
|
5001 | _proto.notifyPropertyAddition_ = function notifyPropertyAddition_(key, value) {
|
5002 | var _this$pendingKeys_2, _this$pendingKeys_2$g;
|
5003 | var notify = hasListeners(this);
|
5004 | var notifySpy = process.env.NODE_ENV !== "production" && isSpyEnabled();
|
5005 | if (notify || notifySpy) {
|
5006 | var change = notify || notifySpy ? {
|
5007 | type: ADD,
|
5008 | observableKind: "object",
|
5009 | debugObjectName: this.name_,
|
5010 | object: this.proxy_ || this.target_,
|
5011 | name: key,
|
5012 | newValue: value
|
5013 | } : null;
|
5014 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
5015 | spyReportStart(change);
|
5016 | }
|
5017 | if (notify) {
|
5018 | notifyListeners(this, change);
|
5019 | }
|
5020 | if (process.env.NODE_ENV !== "production" && notifySpy) {
|
5021 | spyReportEnd();
|
5022 | }
|
5023 | }
|
5024 | (_this$pendingKeys_2 = this.pendingKeys_) == null ? void 0 : (_this$pendingKeys_2$g = _this$pendingKeys_2.get(key)) == null ? void 0 : _this$pendingKeys_2$g.set(true);
|
5025 |
|
5026 | this.keysAtom_.reportChanged();
|
5027 | };
|
5028 | _proto.ownKeys_ = function ownKeys_() {
|
5029 | this.keysAtom_.reportObserved();
|
5030 | return ownKeys(this.target_);
|
5031 | };
|
5032 | _proto.keys_ = function keys_() {
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 | this.keysAtom_.reportObserved();
|
5040 | return Object.keys(this.target_);
|
5041 | };
|
5042 | return ObservableObjectAdministration;
|
5043 | }();
|
5044 | function asObservableObject(target, options) {
|
5045 | var _options$name;
|
5046 | if (process.env.NODE_ENV !== "production" && options && isObservableObject(target)) {
|
5047 | die("Options can't be provided for already observable objects.");
|
5048 | }
|
5049 | if (hasProp(target, $mobx)) {
|
5050 | if (process.env.NODE_ENV !== "production" && !(getAdministration(target) instanceof ObservableObjectAdministration)) {
|
5051 | die("Cannot convert '" + getDebugName(target) + "' into observable object:" + "\nThe target is already observable of different type." + "\nExtending builtins is not supported.");
|
5052 | }
|
5053 | return target;
|
5054 | }
|
5055 | if (process.env.NODE_ENV !== "production" && !Object.isExtensible(target)) {
|
5056 | die("Cannot make the designated object observable; it is not extensible");
|
5057 | }
|
5058 | var name = (_options$name = options == null ? void 0 : options.name) != null ? _options$name : process.env.NODE_ENV !== "production" ? (isPlainObject(target) ? "ObservableObject" : target.constructor.name) + "@" + getNextId() : "ObservableObject";
|
5059 | var adm = new ObservableObjectAdministration(target, new Map(), String(name), getAnnotationFromOptions(options));
|
5060 | addHiddenProp(target, $mobx, adm);
|
5061 | return target;
|
5062 | }
|
5063 | var isObservableObjectAdministration = createInstanceofPredicate("ObservableObjectAdministration", ObservableObjectAdministration);
|
5064 | function getCachedObservablePropDescriptor(key) {
|
5065 | return descriptorCache[key] || (descriptorCache[key] = {
|
5066 | get: function get() {
|
5067 | return this[$mobx].getObservablePropValue_(key);
|
5068 | },
|
5069 | set: function set(value) {
|
5070 | return this[$mobx].setObservablePropValue_(key, value);
|
5071 | }
|
5072 | });
|
5073 | }
|
5074 | function isObservableObject(thing) {
|
5075 | if (isObject(thing)) {
|
5076 | return isObservableObjectAdministration(thing[$mobx]);
|
5077 | }
|
5078 | return false;
|
5079 | }
|
5080 | function recordAnnotationApplied(adm, annotation, key) {
|
5081 | var _adm$target_$storedAn;
|
5082 | if (process.env.NODE_ENV !== "production") {
|
5083 | adm.appliedAnnotations_[key] = annotation;
|
5084 | }
|
5085 |
|
5086 | (_adm$target_$storedAn = adm.target_[storedAnnotationsSymbol]) == null ? true : delete _adm$target_$storedAn[key];
|
5087 | }
|
5088 | function assertAnnotable(adm, annotation, key) {
|
5089 |
|
5090 | if (process.env.NODE_ENV !== "production" && !isAnnotation(annotation)) {
|
5091 | die("Cannot annotate '" + adm.name_ + "." + key.toString() + "': Invalid annotation.");
|
5092 | }
|
5093 | |
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 | if (process.env.NODE_ENV !== "production" && !isOverride(annotation) && hasProp(adm.appliedAnnotations_, key)) {
|
5125 | var fieldName = adm.name_ + "." + key.toString();
|
5126 | var currentAnnotationType = adm.appliedAnnotations_[key].annotationType_;
|
5127 | var requestedAnnotationType = annotation.annotationType_;
|
5128 | die("Cannot apply '" + requestedAnnotationType + "' to '" + fieldName + "':" + ("\nThe field is already annotated with '" + currentAnnotationType + "'.") + "\nRe-annotating fields is not allowed." + "\nUse 'override' annotation for methods overridden by subclass.");
|
5129 | }
|
5130 | }
|
5131 |
|
5132 |
|
5133 | var ENTRY_0 = createArrayEntryDescriptor(0);
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 | var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
|
5140 |
|
5141 | var StubArray = function StubArray() {};
|
5142 | function inherit(ctor, proto) {
|
5143 | if (Object.setPrototypeOf) {
|
5144 | Object.setPrototypeOf(ctor.prototype, proto);
|
5145 | } else if (ctor.prototype.__proto__ !== undefined) {
|
5146 | ctor.prototype.__proto__ = proto;
|
5147 | } else {
|
5148 | ctor.prototype = proto;
|
5149 | }
|
5150 | }
|
5151 | inherit(StubArray, Array.prototype);
|
5152 |
|
5153 |
|
5154 |
|
5155 | var LegacyObservableArray = function (_StubArray, _Symbol$toStringTag, _Symbol$iterator) {
|
5156 | _inheritsLoose(LegacyObservableArray, _StubArray);
|
5157 | function LegacyObservableArray(initialValues, enhancer, name, owned) {
|
5158 | var _this;
|
5159 | if (name === void 0) {
|
5160 | name = process.env.NODE_ENV !== "production" ? "ObservableArray@" + getNextId() : "ObservableArray";
|
5161 | }
|
5162 | if (owned === void 0) {
|
5163 | owned = false;
|
5164 | }
|
5165 | _this = _StubArray.call(this) || this;
|
5166 | var adm = new ObservableArrayAdministration(name, enhancer, owned, true);
|
5167 | adm.proxy_ = _assertThisInitialized(_this);
|
5168 | addHiddenFinalProp(_assertThisInitialized(_this), $mobx, adm);
|
5169 | if (initialValues && initialValues.length) {
|
5170 | var prev = allowStateChangesStart(true);
|
5171 |
|
5172 | _this.spliceWithArray(0, 0, initialValues);
|
5173 | allowStateChangesEnd(prev);
|
5174 | }
|
5175 | {
|
5176 |
|
5177 |
|
5178 | Object.defineProperty(_assertThisInitialized(_this), "0", ENTRY_0);
|
5179 | }
|
5180 | return _this;
|
5181 | }
|
5182 | var _proto = LegacyObservableArray.prototype;
|
5183 | _proto.concat = function concat() {
|
5184 | this[$mobx].atom_.reportObserved();
|
5185 | for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
|
5186 | arrays[_key] = arguments[_key];
|
5187 | }
|
5188 | return Array.prototype.concat.apply(this.slice(),
|
5189 |
|
5190 | arrays.map(function (a) {
|
5191 | return isObservableArray(a) ? a.slice() : a;
|
5192 | }));
|
5193 | };
|
5194 | _proto[_Symbol$iterator] = function () {
|
5195 | var self = this;
|
5196 | var nextIndex = 0;
|
5197 | return makeIterable({
|
5198 | next: function next() {
|
5199 | return nextIndex < self.length ? {
|
5200 | value: self[nextIndex++],
|
5201 | done: false
|
5202 | } : {
|
5203 | done: true,
|
5204 | value: undefined
|
5205 | };
|
5206 | }
|
5207 | });
|
5208 | };
|
5209 | _createClass(LegacyObservableArray, [{
|
5210 | key: "length",
|
5211 | get: function get() {
|
5212 | return this[$mobx].getArrayLength_();
|
5213 | },
|
5214 | set: function set(newLength) {
|
5215 | this[$mobx].setArrayLength_(newLength);
|
5216 | }
|
5217 | }, {
|
5218 | key: _Symbol$toStringTag,
|
5219 | get: function get() {
|
5220 | return "Array";
|
5221 | }
|
5222 | }]);
|
5223 | return LegacyObservableArray;
|
5224 | }(StubArray, Symbol.toStringTag, Symbol.iterator);
|
5225 | Object.entries(arrayExtensions).forEach(function (_ref) {
|
5226 | var prop = _ref[0],
|
5227 | fn = _ref[1];
|
5228 | if (prop !== "concat") {
|
5229 | addHiddenProp(LegacyObservableArray.prototype, prop, fn);
|
5230 | }
|
5231 | });
|
5232 | function createArrayEntryDescriptor(index) {
|
5233 | return {
|
5234 | enumerable: false,
|
5235 | configurable: true,
|
5236 | get: function get() {
|
5237 | return this[$mobx].get_(index);
|
5238 | },
|
5239 | set: function set(value) {
|
5240 | this[$mobx].set_(index, value);
|
5241 | }
|
5242 | };
|
5243 | }
|
5244 | function createArrayBufferItem(index) {
|
5245 | defineProperty(LegacyObservableArray.prototype, "" + index, createArrayEntryDescriptor(index));
|
5246 | }
|
5247 | function reserveArrayBuffer(max) {
|
5248 | if (max > OBSERVABLE_ARRAY_BUFFER_SIZE) {
|
5249 | for (var index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max + 100; index++) {
|
5250 | createArrayBufferItem(index);
|
5251 | }
|
5252 | OBSERVABLE_ARRAY_BUFFER_SIZE = max;
|
5253 | }
|
5254 | }
|
5255 | reserveArrayBuffer(1000);
|
5256 | function createLegacyArray(initialValues, enhancer, name) {
|
5257 | return new LegacyObservableArray(initialValues, enhancer, name);
|
5258 | }
|
5259 |
|
5260 | function getAtom(thing, property) {
|
5261 | if (typeof thing === "object" && thing !== null) {
|
5262 | if (isObservableArray(thing)) {
|
5263 | if (property !== undefined) {
|
5264 | die(23);
|
5265 | }
|
5266 | return thing[$mobx].atom_;
|
5267 | }
|
5268 | if (isObservableSet(thing)) {
|
5269 | return thing.atom_;
|
5270 | }
|
5271 | if (isObservableMap(thing)) {
|
5272 | if (property === undefined) {
|
5273 | return thing.keysAtom_;
|
5274 | }
|
5275 | var observable = thing.data_.get(property) || thing.hasMap_.get(property);
|
5276 | if (!observable) {
|
5277 | die(25, property, getDebugName(thing));
|
5278 | }
|
5279 | return observable;
|
5280 | }
|
5281 | if (isObservableObject(thing)) {
|
5282 | if (!property) {
|
5283 | return die(26);
|
5284 | }
|
5285 | var _observable = thing[$mobx].values_.get(property);
|
5286 | if (!_observable) {
|
5287 | die(27, property, getDebugName(thing));
|
5288 | }
|
5289 | return _observable;
|
5290 | }
|
5291 | if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
5292 | return thing;
|
5293 | }
|
5294 | } else if (isFunction(thing)) {
|
5295 | if (isReaction(thing[$mobx])) {
|
5296 |
|
5297 | return thing[$mobx];
|
5298 | }
|
5299 | }
|
5300 | die(28);
|
5301 | }
|
5302 | function getAdministration(thing, property) {
|
5303 | if (!thing) {
|
5304 | die(29);
|
5305 | }
|
5306 | if (property !== undefined) {
|
5307 | return getAdministration(getAtom(thing, property));
|
5308 | }
|
5309 | if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) {
|
5310 | return thing;
|
5311 | }
|
5312 | if (isObservableMap(thing) || isObservableSet(thing)) {
|
5313 | return thing;
|
5314 | }
|
5315 | if (thing[$mobx]) {
|
5316 | return thing[$mobx];
|
5317 | }
|
5318 | die(24, thing);
|
5319 | }
|
5320 | function getDebugName(thing, property) {
|
5321 | var named;
|
5322 | if (property !== undefined) {
|
5323 | named = getAtom(thing, property);
|
5324 | } else if (isAction(thing)) {
|
5325 | return thing.name;
|
5326 | } else if (isObservableObject(thing) || isObservableMap(thing) || isObservableSet(thing)) {
|
5327 | named = getAdministration(thing);
|
5328 | } else {
|
5329 |
|
5330 | named = getAtom(thing);
|
5331 | }
|
5332 | return named.name_;
|
5333 | }
|
5334 |
|
5335 | var toString = objectPrototype.toString;
|
5336 | function deepEqual(a, b, depth) {
|
5337 | if (depth === void 0) {
|
5338 | depth = -1;
|
5339 | }
|
5340 | return eq(a, b, depth);
|
5341 | }
|
5342 |
|
5343 |
|
5344 | function eq(a, b, depth, aStack, bStack) {
|
5345 |
|
5346 |
|
5347 | if (a === b) {
|
5348 | return a !== 0 || 1 / a === 1 / b;
|
5349 | }
|
5350 |
|
5351 | if (a == null || b == null) {
|
5352 | return false;
|
5353 | }
|
5354 |
|
5355 | if (a !== a) {
|
5356 | return b !== b;
|
5357 | }
|
5358 |
|
5359 | var type = typeof a;
|
5360 | if (type !== "function" && type !== "object" && typeof b != "object") {
|
5361 | return false;
|
5362 | }
|
5363 |
|
5364 | var className = toString.call(a);
|
5365 | if (className !== toString.call(b)) {
|
5366 | return false;
|
5367 | }
|
5368 | switch (className) {
|
5369 |
|
5370 | case "[object RegExp]":
|
5371 |
|
5372 | case "[object String]":
|
5373 |
|
5374 |
|
5375 | return "" + a === "" + b;
|
5376 | case "[object Number]":
|
5377 |
|
5378 |
|
5379 | if (+a !== +a) {
|
5380 | return +b !== +b;
|
5381 | }
|
5382 |
|
5383 | return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
5384 | case "[object Date]":
|
5385 | case "[object Boolean]":
|
5386 |
|
5387 |
|
5388 |
|
5389 | return +a === +b;
|
5390 | case "[object Symbol]":
|
5391 | return typeof Symbol !== "undefined" && Symbol.valueOf.call(a) === Symbol.valueOf.call(b);
|
5392 | case "[object Map]":
|
5393 | case "[object Set]":
|
5394 |
|
5395 |
|
5396 | if (depth >= 0) {
|
5397 | depth++;
|
5398 | }
|
5399 | break;
|
5400 | }
|
5401 |
|
5402 | a = unwrap(a);
|
5403 | b = unwrap(b);
|
5404 | var areArrays = className === "[object Array]";
|
5405 | if (!areArrays) {
|
5406 | if (typeof a != "object" || typeof b != "object") {
|
5407 | return false;
|
5408 | }
|
5409 |
|
5410 |
|
5411 | var aCtor = a.constructor,
|
5412 | bCtor = b.constructor;
|
5413 | if (aCtor !== bCtor && !(isFunction(aCtor) && aCtor instanceof aCtor && isFunction(bCtor) && bCtor instanceof bCtor) && "constructor" in a && "constructor" in b) {
|
5414 | return false;
|
5415 | }
|
5416 | }
|
5417 | if (depth === 0) {
|
5418 | return false;
|
5419 | } else if (depth < 0) {
|
5420 | depth = -1;
|
5421 | }
|
5422 |
|
5423 |
|
5424 |
|
5425 |
|
5426 | aStack = aStack || [];
|
5427 | bStack = bStack || [];
|
5428 | var length = aStack.length;
|
5429 | while (length--) {
|
5430 |
|
5431 |
|
5432 | if (aStack[length] === a) {
|
5433 | return bStack[length] === b;
|
5434 | }
|
5435 | }
|
5436 |
|
5437 | aStack.push(a);
|
5438 | bStack.push(b);
|
5439 |
|
5440 | if (areArrays) {
|
5441 |
|
5442 | length = a.length;
|
5443 | if (length !== b.length) {
|
5444 | return false;
|
5445 | }
|
5446 |
|
5447 | while (length--) {
|
5448 | if (!eq(a[length], b[length], depth - 1, aStack, bStack)) {
|
5449 | return false;
|
5450 | }
|
5451 | }
|
5452 | } else {
|
5453 |
|
5454 | var keys = Object.keys(a);
|
5455 | var key;
|
5456 | length = keys.length;
|
5457 |
|
5458 | if (Object.keys(b).length !== length) {
|
5459 | return false;
|
5460 | }
|
5461 | while (length--) {
|
5462 |
|
5463 | key = keys[length];
|
5464 | if (!(hasProp(b, key) && eq(a[key], b[key], depth - 1, aStack, bStack))) {
|
5465 | return false;
|
5466 | }
|
5467 | }
|
5468 | }
|
5469 |
|
5470 | aStack.pop();
|
5471 | bStack.pop();
|
5472 | return true;
|
5473 | }
|
5474 | function unwrap(a) {
|
5475 | if (isObservableArray(a)) {
|
5476 | return a.slice();
|
5477 | }
|
5478 | if (isES6Map(a) || isObservableMap(a)) {
|
5479 | return Array.from(a.entries());
|
5480 | }
|
5481 | if (isES6Set(a) || isObservableSet(a)) {
|
5482 | return Array.from(a.entries());
|
5483 | }
|
5484 | return a;
|
5485 | }
|
5486 |
|
5487 | function makeIterable(iterator) {
|
5488 | iterator[Symbol.iterator] = getSelf;
|
5489 | return iterator;
|
5490 | }
|
5491 | function getSelf() {
|
5492 | return this;
|
5493 | }
|
5494 |
|
5495 | function isAnnotation(thing) {
|
5496 | return (
|
5497 |
|
5498 | thing instanceof Object && typeof thing.annotationType_ === "string" && isFunction(thing.make_) && isFunction(thing.extend_)
|
5499 | );
|
5500 | }
|
5501 |
|
5502 |
|
5503 |
|
5504 |
|
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 |
|
5515 |
|
5516 |
|
5517 |
|
5518 |
|
5519 | ["Symbol", "Map", "Set"].forEach(function (m) {
|
5520 | var g = getGlobal();
|
5521 | if (typeof g[m] === "undefined") {
|
5522 | die("MobX requires global '" + m + "' to be available or polyfilled");
|
5523 | }
|
5524 | });
|
5525 | if (typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "object") {
|
5526 |
|
5527 | __MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx({
|
5528 | spy: spy,
|
5529 | extras: {
|
5530 | getDebugName: getDebugName
|
5531 | },
|
5532 | $mobx: $mobx
|
5533 | });
|
5534 | }
|
5535 |
|
5536 | export { $mobx, FlowCancellationError, ObservableMap, ObservableSet, Reaction, allowStateChanges as _allowStateChanges, runInAction as _allowStateChangesInsideComputed, allowStateReadsEnd as _allowStateReadsEnd, allowStateReadsStart as _allowStateReadsStart, autoAction as _autoAction, _endAction, getAdministration as _getAdministration, getGlobalState as _getGlobalState, interceptReads as _interceptReads, isComputingDerivation as _isComputingDerivation, resetGlobalState as _resetGlobalState, _startAction, action, autorun, comparer, computed, configure, createAtom, apiDefineProperty as defineProperty, entries, extendObservable, flow, flowResult, get, getAtom, getDebugName, getDependencyTree, getObserverTree, has, intercept, isAction, isObservableValue as isBoxedObservable, isComputed, isComputedProp, isFlow, isFlowCancellationError, isObservable, isObservableArray, isObservableMap, isObservableObject, isObservableProp, isObservableSet, keys, makeAutoObservable, makeObservable, observable, observe, onBecomeObserved, onBecomeUnobserved, onReactionError, override, apiOwnKeys as ownKeys, reaction, remove, runInAction, set, spy, toJS, trace, transaction, untracked, values, when };
|
5537 | //# sourceMappingURL=mobx.esm.js.map
|