UNPKG

hexo-theme-kratos-rebirth

Version:

A transplanted theme for Hexo, with many new features built with love.

1,302 lines (1,294 loc) 149 kB
var Gitment = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 5); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var LS_ACCESS_TOKEN_KEY = exports.LS_ACCESS_TOKEN_KEY = 'gitment-comments-token'; var LS_USER_KEY = exports.LS_USER_KEY = 'gitment-user-info'; var NOT_INITIALIZED_ERROR = exports.NOT_INITIALIZED_ERROR = new Error('Comments Not Initialized'); /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) { var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var __extends = undefined && undefined.__extends || function () { var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; } || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) d[p] = b[p]; } }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); Object.defineProperty(exports, "__esModule", { value: true }); registerGlobals(); exports.extras = { allowStateChanges: allowStateChanges, deepEqual: deepEqual, getAtom: getAtom, getDebugName: getDebugName, getDependencyTree: getDependencyTree, getAdministration: getAdministration, getGlobalState: getGlobalState, getObserverTree: getObserverTree, isComputingDerivation: isComputingDerivation, isSpyEnabled: isSpyEnabled, onReactionError: onReactionError, resetGlobalState: resetGlobalState, shareGlobalState: shareGlobalState, spyReport: spyReport, spyReportEnd: spyReportEnd, spyReportStart: spyReportStart, setReactionScheduler: setReactionScheduler }; if ((typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "undefined" ? "undefined" : _typeof(__MOBX_DEVTOOLS_GLOBAL_HOOK__)) === "object") { __MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx(module.exports); } module.exports.default = module.exports; var actionFieldDecorator = createClassPropertyDecorator(function (target, key, value, args, originalDescriptor) { var actionName = args && args.length === 1 ? args[0] : value.name || key || "<unnamed action>"; var wrappedAction = action(actionName, value); addHiddenProp(target, key, wrappedAction); }, function (key) { return this[key]; }, function () { invariant(false, getMessage("m001")); }, false, true); var boundActionDecorator = createClassPropertyDecorator(function (target, key, value) { defineBoundAction(target, key, value); }, function (key) { return this[key]; }, function () { invariant(false, getMessage("m001")); }, false, false); var action = function action(arg1, arg2, arg3, arg4) { if (arguments.length === 1 && typeof arg1 === "function") return createAction(arg1.name || "<unnamed action>", arg1); if (arguments.length === 2 && typeof arg2 === "function") return createAction(arg1, arg2); if (arguments.length === 1 && typeof arg1 === "string") return namedActionDecorator(arg1); return namedActionDecorator(arg2).apply(null, arguments); }; exports.action = action; action.bound = function boundAction(arg1, arg2, arg3) { if (typeof arg1 === "function") { var action_1 = createAction("<not yet bound action>", arg1); action_1.autoBind = true; return action_1; } return boundActionDecorator.apply(null, arguments); }; function namedActionDecorator(name) { return function (target, prop, descriptor) { if (descriptor && typeof descriptor.value === "function") { descriptor.value = createAction(name, descriptor.value); descriptor.enumerable = false; descriptor.configurable = true; return descriptor; } return actionFieldDecorator(name).apply(this, arguments); }; } function runInAction(arg1, arg2, arg3) { var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>"; var fn = typeof arg1 === "function" ? arg1 : arg2; var scope = typeof arg1 === "function" ? arg2 : arg3; invariant(typeof fn === "function", getMessage("m002")); invariant(fn.length === 0, getMessage("m003")); invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'"); return executeAction(actionName, fn, scope, undefined); } exports.runInAction = runInAction; function isAction(thing) { return typeof thing === "function" && thing.isMobxAction === true; } exports.isAction = isAction; function defineBoundAction(target, propertyName, fn) { var res = function res() { return executeAction(propertyName, fn, target, arguments); }; res.isMobxAction = true; addHiddenProp(target, propertyName, res); } function autorun(arg1, arg2, arg3) { var name, view, scope; if (typeof arg1 === "string") { name = arg1; view = arg2; scope = arg3; } else { name = arg1.name || "Autorun@" + getNextId(); view = arg1; scope = arg2; } invariant(typeof view === "function", getMessage("m004")); invariant(isAction(view) === false, getMessage("m005")); if (scope) view = view.bind(scope); var reaction = new Reaction(name, function () { this.track(reactionRunner); }); function reactionRunner() { view(reaction); } reaction.schedule(); return reaction.getDisposer(); } exports.autorun = autorun; function when(arg1, arg2, arg3, arg4) { var name, predicate, effect, scope; if (typeof arg1 === "string") { name = arg1; predicate = arg2; effect = arg3; scope = arg4; } else { name = "When@" + getNextId(); predicate = arg1; effect = arg2; scope = arg3; } var disposer = autorun(name, function (r) { if (predicate.call(scope)) { r.dispose(); var prevUntracked = untrackedStart(); effect.call(scope); untrackedEnd(prevUntracked); } }); return disposer; } exports.when = when; function autorunAsync(arg1, arg2, arg3, arg4) { var name, func, delay, scope; if (typeof arg1 === "string") { name = arg1; func = arg2; delay = arg3; scope = arg4; } else { name = arg1.name || "AutorunAsync@" + getNextId(); func = arg1; delay = arg2; scope = arg3; } invariant(isAction(func) === false, getMessage("m006")); if (delay === void 0) delay = 1; if (scope) func = func.bind(scope); var isScheduled = false; var r = new Reaction(name, function () { if (!isScheduled) { isScheduled = true; setTimeout(function () { isScheduled = false; if (!r.isDisposed) r.track(reactionRunner); }, delay); } }); function reactionRunner() { func(r); } r.schedule(); return r.getDisposer(); } exports.autorunAsync = autorunAsync; function reaction(expression, effect, arg3) { if (arguments.length > 3) { fail(getMessage("m007")); } if (isModifierDescriptor(expression)) { fail(getMessage("m008")); } var opts; if ((typeof arg3 === "undefined" ? "undefined" : _typeof(arg3)) === "object") { opts = arg3; } else { opts = {}; } opts.name = opts.name || expression.name || effect.name || "Reaction@" + getNextId(); opts.fireImmediately = arg3 === true || opts.fireImmediately === true; opts.delay = opts.delay || 0; opts.compareStructural = opts.compareStructural || opts.struct || false; effect = action(opts.name, opts.context ? effect.bind(opts.context) : effect); if (opts.context) { expression = expression.bind(opts.context); } var firstTime = true; var isScheduled = false; var nextValue; var r = new Reaction(opts.name, function () { if (firstTime || opts.delay < 1) { reactionRunner(); } else if (!isScheduled) { isScheduled = true; setTimeout(function () { isScheduled = false; reactionRunner(); }, opts.delay); } }); function reactionRunner() { if (r.isDisposed) return; var changed = false; r.track(function () { var v = expression(r); changed = valueDidChange(opts.compareStructural, nextValue, v); nextValue = v; }); if (firstTime && opts.fireImmediately) effect(nextValue, r); if (!firstTime && changed === true) effect(nextValue, r); if (firstTime) firstTime = false; } r.schedule(); return r.getDisposer(); } exports.reaction = reaction; function createComputedDecorator(compareStructural) { return createClassPropertyDecorator(function (target, name, _, __, originalDescriptor) { invariant(typeof originalDescriptor !== "undefined", getMessage("m009")); invariant(typeof originalDescriptor.get === "function", getMessage("m010")); var adm = asObservableObject(target, ""); defineComputedProperty(adm, name, originalDescriptor.get, originalDescriptor.set, compareStructural, false); }, function (name) { var observable = this.$mobx.values[name]; if (observable === undefined) return undefined; return observable.get(); }, function (name, value) { this.$mobx.values[name].set(value); }, false, false); } var computedDecorator = createComputedDecorator(false); var computedStructDecorator = createComputedDecorator(true); var computed = function computed(arg1, arg2, arg3) { if (typeof arg2 === "string") { return computedDecorator.apply(null, arguments); } invariant(typeof arg1 === "function", getMessage("m011")); invariant(arguments.length < 3, getMessage("m012")); var opts = (typeof arg2 === "undefined" ? "undefined" : _typeof(arg2)) === "object" ? arg2 : {}; opts.setter = typeof arg2 === "function" ? arg2 : opts.setter; return new ComputedValue(arg1, opts.context, opts.compareStructural || opts.struct || false, opts.name || arg1.name || "", opts.setter); }; exports.computed = computed; computed.struct = computedStructDecorator; function createTransformer(transformer, onCleanup) { invariant(typeof transformer === "function" && transformer.length < 2, "createTransformer expects a function that accepts one argument"); var objectCache = {}; var resetId = globalState.resetId; var Transformer = function (_super) { __extends(Transformer, _super); function Transformer(sourceIdentifier, sourceObject) { var _this = _super.call(this, function () { return transformer(sourceObject); }, undefined, false, "Transformer-" + transformer.name + "-" + sourceIdentifier, undefined) || this; _this.sourceIdentifier = sourceIdentifier; _this.sourceObject = sourceObject; return _this; } Transformer.prototype.onBecomeUnobserved = function () { var lastValue = this.value; _super.prototype.onBecomeUnobserved.call(this); delete objectCache[this.sourceIdentifier]; if (onCleanup) onCleanup(lastValue, this.sourceObject); }; return Transformer; }(ComputedValue); return function (object) { if (resetId !== globalState.resetId) { objectCache = {}; resetId = globalState.resetId; } var identifier = getMemoizationId(object); var reactiveTransformer = objectCache[identifier]; if (reactiveTransformer) return reactiveTransformer.get(); reactiveTransformer = objectCache[identifier] = new Transformer(identifier, object); return reactiveTransformer.get(); }; } exports.createTransformer = createTransformer; function getMemoizationId(object) { if (object === null || (typeof object === "undefined" ? "undefined" : _typeof(object)) !== "object") throw new Error("[mobx] transform expected some kind of object, got: " + object); var tid = object.$transformId; if (tid === undefined) { tid = getNextId(); addHiddenProp(object, "$transformId", tid); } return tid; } function expr(expr, scope) { if (!isComputingDerivation()) console.warn(getMessage("m013")); return computed(expr, { context: scope }).get(); } exports.expr = expr; function extendObservable(target) { var properties = []; for (var _i = 1; _i < arguments.length; _i++) { properties[_i - 1] = arguments[_i]; } return extendObservableHelper(target, deepEnhancer, properties); } exports.extendObservable = extendObservable; function extendShallowObservable(target) { var properties = []; for (var _i = 1; _i < arguments.length; _i++) { properties[_i - 1] = arguments[_i]; } return extendObservableHelper(target, referenceEnhancer, properties); } exports.extendShallowObservable = extendShallowObservable; function extendObservableHelper(target, defaultEnhancer, properties) { invariant(arguments.length >= 2, getMessage("m014")); invariant((typeof target === "undefined" ? "undefined" : _typeof(target)) === "object", getMessage("m015")); invariant(!isObservableMap(target), getMessage("m016")); properties.forEach(function (propSet) { invariant((typeof propSet === "undefined" ? "undefined" : _typeof(propSet)) === "object", getMessage("m017")); invariant(!isObservable(propSet), getMessage("m018")); }); var adm = asObservableObject(target); var definedProps = {}; for (var i = properties.length - 1; i >= 0; i--) { var propSet = properties[i]; for (var key in propSet) { if (definedProps[key] !== true && hasOwnProperty(propSet, key)) { definedProps[key] = true; if (target === propSet && !isPropertyConfigurable(target, key)) continue; var descriptor = Object.getOwnPropertyDescriptor(propSet, key); defineObservablePropertyFromDescriptor(adm, key, descriptor, defaultEnhancer); } } } return target; } function getDependencyTree(thing, property) { return nodeToDependencyTree(getAtom(thing, property)); } function nodeToDependencyTree(node) { var result = { name: node.name }; if (node.observing && node.observing.length > 0) result.dependencies = unique(node.observing).map(nodeToDependencyTree); return result; } function getObserverTree(thing, property) { return nodeToObserverTree(getAtom(thing, property)); } function nodeToObserverTree(node) { var result = { name: node.name }; if (hasObservers(node)) result.observers = getObservers(node).map(nodeToObserverTree); return result; } function intercept(thing, propOrHandler, handler) { if (typeof handler === "function") return interceptProperty(thing, propOrHandler, handler);else return interceptInterceptable(thing, propOrHandler); } exports.intercept = intercept; function interceptInterceptable(thing, handler) { return getAdministration(thing).intercept(handler); } function interceptProperty(thing, property, handler) { return getAdministration(thing, property).intercept(handler); } function isComputed(value, property) { if (value === null || value === undefined) return false; if (property !== undefined) { if (isObservableObject(value) === false) return false; var atom = getAtom(value, property); return isComputedValue(atom); } return isComputedValue(value); } exports.isComputed = isComputed; function isObservable(value, property) { if (value === null || value === undefined) return false; if (property !== undefined) { if (isObservableArray(value) || isObservableMap(value)) throw new Error(getMessage("m019"));else if (isObservableObject(value)) { var o = value.$mobx; return o.values && !!o.values[property]; } return false; } return isObservableObject(value) || !!value.$mobx || isAtom(value) || isReaction(value) || isComputedValue(value); } exports.isObservable = isObservable; var deepDecorator = createDecoratorForEnhancer(deepEnhancer); var shallowDecorator = createDecoratorForEnhancer(shallowEnhancer); var refDecorator = createDecoratorForEnhancer(referenceEnhancer); var deepStructDecorator = createDecoratorForEnhancer(deepStructEnhancer); var refStructDecorator = createDecoratorForEnhancer(refStructEnhancer); function createObservable(v) { if (v === void 0) { v = undefined; } if (typeof arguments[1] === "string") return deepDecorator.apply(null, arguments); invariant(arguments.length <= 1, getMessage("m021")); invariant(!isModifierDescriptor(v), getMessage("m020")); if (isObservable(v)) return v; var res = deepEnhancer(v, undefined, undefined); if (res !== v) return res; return observable.box(v); } var IObservableFactories = function () { function IObservableFactories() {} IObservableFactories.prototype.box = function (value, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("box"); return new ObservableValue(value, deepEnhancer, name); }; IObservableFactories.prototype.shallowBox = function (value, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowBox"); return new ObservableValue(value, referenceEnhancer, name); }; IObservableFactories.prototype.array = function (initialValues, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("array"); return new ObservableArray(initialValues, deepEnhancer, name); }; IObservableFactories.prototype.shallowArray = function (initialValues, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowArray"); return new ObservableArray(initialValues, referenceEnhancer, name); }; IObservableFactories.prototype.map = function (initialValues, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("map"); return new ObservableMap(initialValues, deepEnhancer, name); }; IObservableFactories.prototype.shallowMap = function (initialValues, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowMap"); return new ObservableMap(initialValues, referenceEnhancer, name); }; IObservableFactories.prototype.object = function (props, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("object"); var res = {}; asObservableObject(res, name); extendObservable(res, props); return res; }; IObservableFactories.prototype.shallowObject = function (props, name) { if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowObject"); var res = {}; asObservableObject(res, name); extendShallowObservable(res, props); return res; }; IObservableFactories.prototype.ref = function () { if (arguments.length < 2) { return createModifierDescriptor(referenceEnhancer, arguments[0]); } else { return refDecorator.apply(null, arguments); } }; IObservableFactories.prototype.shallow = function () { if (arguments.length < 2) { return createModifierDescriptor(shallowEnhancer, arguments[0]); } else { return shallowDecorator.apply(null, arguments); } }; IObservableFactories.prototype.deep = function () { if (arguments.length < 2) { return createModifierDescriptor(deepEnhancer, arguments[0]); } else { return deepDecorator.apply(null, arguments); } }; IObservableFactories.prototype.struct = function () { if (arguments.length < 2) { return createModifierDescriptor(deepStructEnhancer, arguments[0]); } else { return deepStructDecorator.apply(null, arguments); } }; return IObservableFactories; }(); exports.IObservableFactories = IObservableFactories; var observable = createObservable; exports.observable = observable; Object.keys(IObservableFactories.prototype).forEach(function (key) { return observable[key] = IObservableFactories.prototype[key]; }); observable.deep.struct = observable.struct; observable.ref.struct = function () { if (arguments.length < 2) { return createModifierDescriptor(refStructEnhancer, arguments[0]); } else { return refStructDecorator.apply(null, arguments); } }; function incorrectlyUsedAsDecorator(methodName) { fail("Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?"); } function createDecoratorForEnhancer(enhancer) { invariant(!!enhancer, ":("); return createClassPropertyDecorator(function (target, name, baseValue, _, baseDescriptor) { assertPropertyConfigurable(target, name); invariant(!baseDescriptor || !baseDescriptor.get, getMessage("m022")); var adm = asObservableObject(target, undefined); defineObservableProperty(adm, name, baseValue, enhancer); }, function (name) { var observable = this.$mobx.values[name]; if (observable === undefined) return undefined; return observable.get(); }, function (name, value) { setPropertyValue(this, name, value); }, true, false); } function observe(thing, propOrCb, cbOrFire, fireImmediately) { if (typeof cbOrFire === "function") return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire); } exports.observe = observe; function observeObservable(thing, listener, fireImmediately) { return getAdministration(thing).observe(listener, fireImmediately); } function observeObservableProperty(thing, property, listener, fireImmediately) { return getAdministration(thing, property).observe(listener, fireImmediately); } function toJS(source, detectCycles, __alreadySeen) { if (detectCycles === void 0) { detectCycles = true; } if (__alreadySeen === void 0) { __alreadySeen = []; } function cache(value) { if (detectCycles) __alreadySeen.push([source, value]); return value; } if (isObservable(source)) { if (detectCycles && __alreadySeen === null) __alreadySeen = []; if (detectCycles && source !== null && (typeof source === "undefined" ? "undefined" : _typeof(source)) === "object") { for (var i = 0, l = __alreadySeen.length; i < l; i++) { if (__alreadySeen[i][0] === source) return __alreadySeen[i][1]; } } if (isObservableArray(source)) { var res = cache([]); var toAdd = source.map(function (value) { return toJS(value, detectCycles, __alreadySeen); }); res.length = toAdd.length; for (var i = 0, l = toAdd.length; i < l; i++) { res[i] = toAdd[i]; }return res; } if (isObservableObject(source)) { var res = cache({}); for (var key in source) { res[key] = toJS(source[key], detectCycles, __alreadySeen); }return res; } if (isObservableMap(source)) { var res_1 = cache({}); source.forEach(function (value, key) { return res_1[key] = toJS(value, detectCycles, __alreadySeen); }); return res_1; } if (isObservableValue(source)) return toJS(source.get(), detectCycles, __alreadySeen); } return source; } exports.toJS = toJS; function transaction(action, thisArg) { if (thisArg === void 0) { thisArg = undefined; } deprecated(getMessage("m023")); return runInTransaction.apply(undefined, arguments); } exports.transaction = transaction; function runInTransaction(action, thisArg) { if (thisArg === void 0) { thisArg = undefined; } return executeAction("", action); } function log(msg) { console.log(msg); return msg; } function whyRun(thing, prop) { switch (arguments.length) { case 0: thing = globalState.trackingDerivation; if (!thing) return log(getMessage("m024")); break; case 2: thing = getAtom(thing, prop); break; } thing = getAtom(thing); if (isComputedValue(thing)) return log(thing.whyRun());else if (isReaction(thing)) return log(thing.whyRun()); return fail(getMessage("m025")); } exports.whyRun = whyRun; function createAction(actionName, fn) { invariant(typeof fn === "function", getMessage("m026")); invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'"); var res = function res() { return executeAction(actionName, fn, this, arguments); }; res.originalFn = fn; res.isMobxAction = true; return res; } function executeAction(actionName, fn, scope, args) { var runInfo = startAction(actionName, fn, scope, args); try { return fn.apply(scope, args); } finally { endAction(runInfo); } } function startAction(actionName, fn, scope, args) { var notifySpy = isSpyEnabled() && !!actionName; var startTime = 0; if (notifySpy) { startTime = Date.now(); var l = args && args.length || 0; var flattendArgs = new Array(l); if (l > 0) for (var i = 0; i < l; i++) { flattendArgs[i] = args[i]; }spyReportStart({ type: "action", name: actionName, fn: fn, object: scope, arguments: flattendArgs }); } var prevDerivation = untrackedStart(); startBatch(); var prevAllowStateChanges = allowStateChangesStart(true); return { prevDerivation: prevDerivation, prevAllowStateChanges: prevAllowStateChanges, notifySpy: notifySpy, startTime: startTime }; } function endAction(runInfo) { allowStateChangesEnd(runInfo.prevAllowStateChanges); endBatch(); untrackedEnd(runInfo.prevDerivation); if (runInfo.notifySpy) spyReportEnd({ time: Date.now() - runInfo.startTime }); } function useStrict(strict) { invariant(globalState.trackingDerivation === null, getMessage("m028")); globalState.strictMode = strict; globalState.allowStateChanges = !strict; } exports.useStrict = useStrict; function isStrictModeEnabled() { return globalState.strictMode; } exports.isStrictModeEnabled = isStrictModeEnabled; function allowStateChanges(allowStateChanges, func) { var prev = allowStateChangesStart(allowStateChanges); var res; try { res = func(); } finally { allowStateChangesEnd(prev); } return res; } function allowStateChangesStart(allowStateChanges) { var prev = globalState.allowStateChanges; globalState.allowStateChanges = allowStateChanges; return prev; } function allowStateChangesEnd(prev) { globalState.allowStateChanges = prev; } var BaseAtom = function () { function BaseAtom(name) { if (name === void 0) { name = "Atom@" + getNextId(); } this.name = name; this.isPendingUnobservation = true; this.observers = []; this.observersIndexes = {}; this.diffValue = 0; this.lastAccessedBy = 0; this.lowestObserverState = IDerivationState.NOT_TRACKING; } BaseAtom.prototype.onBecomeUnobserved = function () {}; BaseAtom.prototype.reportObserved = function () { reportObserved(this); }; BaseAtom.prototype.reportChanged = function () { startBatch(); propagateChanged(this); endBatch(); }; BaseAtom.prototype.toString = function () { return this.name; }; return BaseAtom; }(); exports.BaseAtom = BaseAtom; var Atom = function (_super) { __extends(Atom, _super); function Atom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) { if (name === void 0) { name = "Atom@" + getNextId(); } if (onBecomeObservedHandler === void 0) { onBecomeObservedHandler = noop; } if (onBecomeUnobservedHandler === void 0) { onBecomeUnobservedHandler = noop; } var _this = _super.call(this, name) || this; _this.name = name; _this.onBecomeObservedHandler = onBecomeObservedHandler; _this.onBecomeUnobservedHandler = onBecomeUnobservedHandler; _this.isPendingUnobservation = false; _this.isBeingTracked = false; return _this; } Atom.prototype.reportObserved = function () { startBatch(); _super.prototype.reportObserved.call(this); if (!this.isBeingTracked) { this.isBeingTracked = true; this.onBecomeObservedHandler(); } endBatch(); return !!globalState.trackingDerivation; }; Atom.prototype.onBecomeUnobserved = function () { this.isBeingTracked = false; this.onBecomeUnobservedHandler(); }; return Atom; }(BaseAtom); exports.Atom = Atom; var isAtom = createInstanceofPredicate("Atom", BaseAtom); var ComputedValue = function () { function ComputedValue(derivation, scope, compareStructural, name, setter) { this.derivation = derivation; this.scope = scope; this.compareStructural = compareStructural; this.dependenciesState = IDerivationState.NOT_TRACKING; this.observing = []; this.newObserving = null; this.isPendingUnobservation = false; this.observers = []; this.observersIndexes = {}; this.diffValue = 0; this.runId = 0; this.lastAccessedBy = 0; this.lowestObserverState = IDerivationState.UP_TO_DATE; this.unboundDepsCount = 0; this.__mapid = "#" + getNextId(); this.value = undefined; this.isComputing = false; this.isRunningSetter = false; this.name = name || "ComputedValue@" + getNextId(); if (setter) this.setter = createAction(name + "-setter", setter); } ComputedValue.prototype.onBecomeStale = function () { propagateMaybeChanged(this); }; ComputedValue.prototype.onBecomeUnobserved = function () { invariant(this.dependenciesState !== IDerivationState.NOT_TRACKING, getMessage("m029")); clearObserving(this); this.value = undefined; }; ComputedValue.prototype.get = function () { invariant(!this.isComputing, "Cycle detected in computation " + this.name, this.derivation); if (globalState.inBatch === 0) { startBatch(); if (shouldCompute(this)) this.value = this.computeValue(false); endBatch(); } else { reportObserved(this); if (shouldCompute(this)) if (this.trackAndCompute()) propagateChangeConfirmed(this); } var result = this.value; if (isCaughtException(result)) throw result.cause; return result; }; ComputedValue.prototype.peek = function () { var res = this.computeValue(false); if (isCaughtException(res)) throw res.cause; return res; }; ComputedValue.prototype.set = function (value) { if (this.setter) { invariant(!this.isRunningSetter, "The setter of computed value '" + this.name + "' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?"); this.isRunningSetter = true; try { this.setter.call(this.scope, value); } finally { this.isRunningSetter = false; } } else invariant(false, "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value."); }; ComputedValue.prototype.trackAndCompute = function () { if (isSpyEnabled()) { spyReport({ object: this.scope, type: "compute", fn: this.derivation }); } var oldValue = this.value; var newValue = this.value = this.computeValue(true); return isCaughtException(newValue) || valueDidChange(this.compareStructural, newValue, oldValue); }; ComputedValue.prototype.computeValue = function (track) { this.isComputing = true; globalState.computationDepth++; var res; if (track) { res = trackDerivedFunction(this, this.derivation, this.scope); } else { try { res = this.derivation.call(this.scope); } catch (e) { res = new CaughtException(e); } } globalState.computationDepth--; this.isComputing = false; return res; }; ; ComputedValue.prototype.observe = function (listener, fireImmediately) { var _this = this; var firstTime = true; var prevValue = undefined; return autorun(function () { var newValue = _this.get(); if (!firstTime || fireImmediately) { var prevU = untrackedStart(); listener({ type: "update", object: _this, newValue: newValue, oldValue: prevValue }); untrackedEnd(prevU); } firstTime = false; prevValue = newValue; }); }; ComputedValue.prototype.toJSON = function () { return this.get(); }; ComputedValue.prototype.toString = function () { return this.name + "[" + this.derivation.toString() + "]"; }; ComputedValue.prototype.valueOf = function () { return toPrimitive(this.get()); }; ; ComputedValue.prototype.whyRun = function () { var isTracking = Boolean(globalState.trackingDerivation); var observing = unique(this.isComputing ? this.newObserving : this.observing).map(function (dep) { return dep.name; }); var observers = unique(getObservers(this).map(function (dep) { return dep.name; })); return "\nWhyRun? computation '" + this.name + "':\n * Running because: " + (isTracking ? "[active] the value of this computation is needed by a reaction" : this.isComputing ? "[get] The value of this computed was requested outside a reaction" : "[idle] not running at the moment") + "\n" + (this.dependenciesState === IDerivationState.NOT_TRACKING ? getMessage("m032") : " * This computation will re-run if any of the following observables changes:\n " + joinStrings(observing) + "\n " + (this.isComputing && isTracking ? " (... or any observable accessed during the remainder of the current run)" : "") + "\n\t" + getMessage("m038") + "\n\n * If the outcome of this computation changes, the following observers will be re-run:\n " + joinStrings(observers) + "\n"); }; return ComputedValue; }(); ComputedValue.prototype[primitiveSymbol()] = ComputedValue.prototype.valueOf; var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue); var IDerivationState; (function (IDerivationState) { IDerivationState[IDerivationState["NOT_TRACKING"] = -1] = "NOT_TRACKING"; IDerivationState[IDerivationState["UP_TO_DATE"] = 0] = "UP_TO_DATE"; IDerivationState[IDerivationState["POSSIBLY_STALE"] = 1] = "POSSIBLY_STALE"; IDerivationState[IDerivationState["STALE"] = 2] = "STALE"; })(IDerivationState || (IDerivationState = {})); exports.IDerivationState = IDerivationState; var CaughtException = function () { function CaughtException(cause) { this.cause = cause; } return CaughtException; }(); function isCaughtException(e) { return e instanceof CaughtException; } function shouldCompute(derivation) { switch (derivation.dependenciesState) { case IDerivationState.UP_TO_DATE: return false; case IDerivationState.NOT_TRACKING: case IDerivationState.STALE: return true; case IDerivationState.POSSIBLY_STALE: { var prevUntracked = untrackedStart(); var obs = derivation.observing, l = obs.length; for (var i = 0; i < l; i++) { var obj = obs[i]; if (isComputedValue(obj)) { try { obj.get(); } catch (e) { untrackedEnd(prevUntracked); return true; } if (derivation.dependenciesState === IDerivationState.STALE) { untrackedEnd(prevUntracked); return true; } } } changeDependenciesStateTo0(derivation); untrackedEnd(prevUntracked); return false; } } } function isComputingDerivation() { return globalState.trackingDerivation !== null; } function checkIfStateModificationsAreAllowed(atom) { var hasObservers = atom.observers.length > 0; if (globalState.computationDepth > 0 && hasObservers) fail(getMessage("m031") + atom.name); if (!globalState.allowStateChanges && hasObservers) fail(getMessage(globalState.strictMode ? "m030a" : "m030b") + atom.name); } function trackDerivedFunction(derivation, f, context) { changeDependenciesStateTo0(derivation); derivation.newObserving = new Array(derivation.observing.length + 100); derivation.unboundDepsCount = 0; derivation.runId = ++globalState.runId; var prevTracking = globalState.trackingDerivation; globalState.trackingDerivation = derivation; var result; try { result = f.call(context); } catch (e) { result = new CaughtException(e); } globalState.trackingDerivation = prevTracking; bindDependencies(derivation); return result; } function bindDependencies(derivation) { var prevObserving = derivation.observing; var observing = derivation.observing = derivation.newObserving; derivation.newObserving = null; var i0 = 0, l = derivation.unboundDepsCount; for (var i = 0; i < l; i++) { var dep = observing[i]; if (dep.diffValue === 0) { dep.diffValue = 1; if (i0 !== i) observing[i0] = dep; i0++; } } observing.length = i0; l = prevObserving.length; while (l--) { var dep = prevObserving[l]; if (dep.diffValue === 0) { removeObserver(dep, derivation); } dep.diffValue = 0; } while (i0--) { var dep = observing[i0]; if (dep.diffValue === 1) { dep.diffValue = 0; addObserver(dep, derivation); } } } function clearObserving(derivation) { var obs = derivation.observing; var i = obs.length; while (i--) { removeObserver(obs[i], derivation); }derivation.dependenciesState = IDerivationState.NOT_TRACKING; obs.length = 0; } function untracked(action) { var prev = untrackedStart(); var res = action(); untrackedEnd(prev); return res; } exports.untracked = untracked; function untrackedStart() { var prev = globalState.trackingDerivation; globalState.trackingDerivation = null; return prev; } function untrackedEnd(prev) { globalState.trackingDerivation = prev; } function changeDependenciesStateTo0(derivation) { if (derivation.dependenciesState === IDerivationState.UP_TO_DATE) return; derivation.dependenciesState = IDerivationState.UP_TO_DATE; var obs = derivation.observing; var i = obs.length; while (i--) { obs[i].lowestObserverState = IDerivationState.UP_TO_DATE; } } var persistentKeys = ["mobxGuid", "resetId", "spyListeners", "strictMode", "runId"]; var MobXGlobals = function () { function MobXGlobals() { this.version = 5; this.trackingDerivation = null; this.computationDepth = 0; this.runId = 0; this.mobxGuid = 0; this.inBatch = 0; this.pendingUnobservations = []; this.pendingReactions = []; this.isRunningReactions = false; this.allowStateChanges = true; this.strictMode = false; this.resetId = 0; this.spyListeners = []; this.globalReactionErrorHandlers = []; } return MobXGlobals; }(); var globalState = new MobXGlobals(); function shareGlobalState() { var global = getGlobal(); var ownState = globalState; if (global.__mobservableTrackingStack || global.__mobservableViewStack) throw new Error("[mobx] An incompatible version of mobservable is already loaded."); if (global.__mobxGlobal && global.__mobxGlobal.version !== ownState.version) throw new Error("[mobx] An incompatible version of mobx is already loaded."); if (global.__mobxGlobal) globalState = global.__mobxGlobal;else global.__mobxGlobal = ownState; } function getGlobalState() { return globalState; } function registerGlobals() {} function resetGlobalState() { globalState.resetId++; var defaultGlobals = new MobXGlobals(); for (var key in defaultGlobals) { if (persistentKeys.indexOf(key) === -1) globalState[key] = defaultGlobals[key]; }globalState.allowStateChanges = !globalState.strictMode; } function hasObservers(observable) { return observable.observers && observable.observers.length > 0; } function getObservers(observable) { return observable.observers; } function invariantObservers(observable) { var list = observable.observers; var map = observable.observersIndexes; var l = list.length; for (var i = 0; i < l; i++) { var id = list[i].__mapid; if (i) { invariant(map[id] === i, "INTERNAL ERROR maps derivation.__mapid to index in list"); } else { invariant(!(id in map), "INTERNAL ERROR observer on index 0 shouldnt be held in map."); } } invariant(list.length === 0 || Object.keys(map).length === list.length - 1, "INTERNAL ERROR there is no junk in map"); } function addObserver(observable, node) { var l = observable.observers.length; if (l) { observable.observersIndexes[node.__mapid] = l; } observable.observers[l] = node; if (observable.lowestObserverState > node.dependenciesState) observable.lowestObserverState = node.dependenciesState; } function removeObserver(observable, node) { if (observable.observers.length === 1) { observable.observers.length = 0; queueForUnobservation(observable); } else { var list = observable.observers; var map_1 = observable.observersIndexes; var filler = list.pop(); if (filler !== node) { var index = map_1[node.__mapid] || 0; if (index) { map_1[filler.__mapid] = index; } else { delete map_1[filler.__mapid]; } list[index] = filler; } delete map_1[node.__mapid]; } } function queueForUnobservation(observable) { if (!observable.isPendingUnobservation) { observable.isPendingUnobservation = true; globalState.pendingUnobservations.push(observable); } } function startBatch() { globalState.inBatch++; } function endBatch() { if (--globalState.inBatch === 0) { runReactions(); var list = globalState.pendingUnobservations; for (var i = 0; i < list.length; i++) { var observable_1 = list[i]; observable_1.isPendingUnobservation = false; if (observable_1.observers.length === 0) { observable_1.onBecomeUnobserved(); } } globalState.pendingUnobservations = []; } } function reportObserved(observable) { var derivation = globalState.trackingDerivation; if (derivation !== null) { if (derivation.runId !== observable.lastAccessedBy) { observable.lastAccessedBy = derivation.runId; derivation.newObserving[derivation.unboundDepsCount++] = observable; } } else if (observable.observers.length === 0) { queueForUnobservation(observable); } } function invariantLOS(observable, msg) { var min = getObservers(observable).reduce(function (a, b) { return Math.min(a, b.dependenciesState); }, 2); if (min >= observable.lowestObserverState) return; throw new Error("lowestObserverState is wrong for " + msg + " because " + min + " < " + observable.lowestObserverState); } function propagateChanged(observable) { if (observable.lowestObserverState === IDerivationState.STALE) return; observable.lowestObserverState = IDerivationState.STALE; var observers = observable.observers; var i = observers.length; while (i--) { var d = observers[i]; if (d.dependenciesState === IDerivationState.UP_TO_DATE) d.onBecomeStale(); d.dependenciesState = IDerivationState.STALE; } } function propagateChangeConfirmed(observable) { if (observable.lowestObserverState === IDerivationState.STALE) return; observable.lowestObserverState = IDerivationState.STALE; var observers = observable.observers; var i = observers.length; while (i--) { var d = observers[i]; if (d.dependenciesState === IDerivationState.POSSIBLY_STALE) d.dependenciesState = IDerivationState.STALE;else if (d.dependenciesState === IDerivationState.UP_TO_DATE) observable.lowestObserverState = IDerivationState.UP_TO_DATE; } } function propagateMaybeChanged(observable) { if (observable.lowestObserverState !== IDerivationState.UP_TO_DATE) return; observable.lowestObserverState = IDerivationState.POSSIBLY_STALE; var observers = observable.observers; var i = observers.length; while (i--) { var d = observers[i]; if (d.dependenciesState === IDerivationState.UP_TO_DATE) { d.dependenciesState = IDerivationState.POSSIBLY_STALE; d.onBecomeStale(); } } } var Reaction = function () { function Reaction(name, onInvalidate) { if (name === void 0) { name = "Reaction@" + getNextId(); } this.name = name; this.onInvalidate = onInvalidate; this.observing = []; this.newObserving = []; this.dependenciesState = IDerivationState.NOT_TRACKING; this.diffValue = 0; this.runId = 0; this.unboundDepsCount = 0; this.__mapid = "#" + getNextId(); this.isDisposed = false; this._isScheduled = false; this._isTrackPending =