1var Gitment = 2 /******/ (function(modules) { // webpackBootstrap 3 /******/ // The module cache 4 /******/ var installedModules = {}; 5 /******/ 6 /******/ // The require function 7 /******/ function __webpack_require__(moduleId) { 8 /******/ 9 /******/ // Check if module is in cache 10 /******/ if(installedModules[moduleId]) 11 /******/ return installedModules[moduleId].exports; 12 /******/ 13 /******/ // Create a new module (and put it into the cache) 14 /******/ var module = installedModules[moduleId] = { 15 /******/ i: moduleId, 16 /******/ l: false, 17 /******/ exports: {} 18 /******/ }; 19 /******/ 20 /******/ // Execute the module function 21 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 /******/ 23 /******/ // Flag the module as loaded 24 /******/ module.l = true; 25 /******/ 26 /******/ // Return the exports of the module 27 /******/ return module.exports; 28 /******/ } 29 /******/ 30 /******/ 31 /******/ // expose the modules object (__webpack_modules__) 32 /******/ __webpack_require__.m = modules; 33 /******/ 34 /******/ // expose the module cache 35 /******/ __webpack_require__.c = installedModules; 36 /******/ 37 /******/ // identity function for calling harmony imports with the correct context 38 /******/ __webpack_require__.i = function(value) { return value; }; 39 /******/ 40 /******/ // define getter function for harmony exports 41 /******/ __webpack_require__.d = function(exports, name, getter) { 42 /******/ if(!__webpack_require__.o(exports, name)) { 43 /******/ Object.defineProperty(exports, name, { 44 /******/ configurable: false, 45 /******/ enumerable: true, 46 /******/ get: getter 47 /******/ }); 48 /******/ } 49 /******/ }; 50 /******/ 51 /******/ // getDefaultExport function for compatibility with non-harmony modules 52 /******/ __webpack_require__.n = function(module) { 53 /******/ var getter = module && module.__esModule ? 54 /******/ function getDefault() { return module['default']; } : 55 /******/ function getModuleExports() { return module; }; 56 /******/ __webpack_require__.d(getter, 'a', getter); 57 /******/ return getter; 58 /******/ }; 59 /******/ 60 /******/ // Object.prototype.hasOwnProperty.call 61 /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 62 /******/ 63 /******/ // __webpack_public_path__ 64 /******/ __webpack_require__.p = ""; 65 /******/ 66 /******/ // Load entry module and return exports 67 /******/ return __webpack_require__(__webpack_require__.s = 5); 68 /******/ }) 69/************************************************************************/ 70/******/ ([ 71 /* 0 */ 72 /***/ (function(module, exports, __webpack_require__) { 73 74 "use strict"; 75 76 77 Object.defineProperty(exports, "__esModule", { 78 value: true 79 }); 80 var LS_ACCESS_TOKEN_KEY = exports.LS_ACCESS_TOKEN_KEY = 'gitment-comments-token'; 81 var LS_USER_KEY = exports.LS_USER_KEY = 'gitment-user-info'; 82 83 var NOT_INITIALIZED_ERROR = exports.NOT_INITIALIZED_ERROR = new Error('Comments Not Initialized'); 84 85 /***/ }), 86 /* 1 */ 87 /***/ (function(module, exports, __webpack_require__) { 88 89 "use strict"; 90 /* WEBPACK VAR INJECTION */(function(global) { 91 92 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; }; 93 94 var __extends = undefined && undefined.__extends || function () { 95 var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) { 96 d.__proto__ = b; 97 } || function (d, b) { 98 for (var p in b) { 99 if (b.hasOwnProperty(p)) d[p] = b[p]; 100 } 101 }; 102 return function (d, b) { 103 extendStatics(d, b); 104 function __() { 105 this.constructor = d; 106 } 107 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 108 }; 109 }(); 110 Object.defineProperty(exports, "__esModule", { value: true }); 111 registerGlobals(); 112 exports.extras = { 113 allowStateChanges: allowStateChanges, 114 deepEqual: deepEqual, 115 getAtom: getAtom, 116 getDebugName: getDebugName, 117 getDependencyTree: getDependencyTree, 118 getAdministration: getAdministration, 119 getGlobalState: getGlobalState, 120 getObserverTree: getObserverTree, 121 isComputingDerivation: isComputingDerivation, 122 isSpyEnabled: isSpyEnabled, 123 onReactionError: onReactionError, 124 resetGlobalState: resetGlobalState, 125 shareGlobalState: shareGlobalState, 126 spyReport: spyReport, 127 spyReportEnd: spyReportEnd, 128 spyReportStart: spyReportStart, 129 setReactionScheduler: setReactionScheduler 130 }; 131 if ((typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "undefined" ? "undefined" : _typeof(__MOBX_DEVTOOLS_GLOBAL_HOOK__)) === "object") { 132 __MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx(module.exports); 133 } 134 module.exports.default = module.exports; 135 var actionFieldDecorator = createClassPropertyDecorator(function (target, key, value, args, originalDescriptor) { 136 var actionName = args && args.length === 1 ? args[0] : value.name || key || "<unnamed action>"; 137 var wrappedAction = action(actionName, value); 138 addHiddenProp(target, key, wrappedAction); 139 }, function (key) { 140 return this[key]; 141 }, function () { 142 invariant(false, getMessage("m001")); 143 }, false, true); 144 var boundActionDecorator = createClassPropertyDecorator(function (target, key, value) { 145 defineBoundAction(target, key, value); 146 }, function (key) { 147 return this[key]; 148 }, function () { 149 invariant(false, getMessage("m001")); 150 }, false, false); 151 var action = function action(arg1, arg2, arg3, arg4) { 152 if (arguments.length === 1 && typeof arg1 === "function") return createAction(arg1.name || "<unnamed action>", arg1); 153 if (arguments.length === 2 && typeof arg2 === "function") return createAction(arg1, arg2); 154 if (arguments.length === 1 && typeof arg1 === "string") return namedActionDecorator(arg1); 155 return namedActionDecorator(arg2).apply(null, arguments); 156 }; 157 exports.action = action; 158 action.bound = function boundAction(arg1, arg2, arg3) { 159 if (typeof arg1 === "function") { 160 var action_1 = createAction("<not yet bound action>", arg1); 161 action_1.autoBind = true; 162 return action_1; 163 } 164 return boundActionDecorator.apply(null, arguments); 165 }; 166 function namedActionDecorator(name) { 167 return function (target, prop, descriptor) { 168 if (descriptor && typeof descriptor.value === "function") { 169 descriptor.value = createAction(name, descriptor.value); 170 descriptor.enumerable = false;
171 descriptor.configurable = true; 172 return descriptor; 173 } 174 return actionFieldDecorator(name).apply(this, arguments); 175 }; 176 } 177 function runInAction(arg1, arg2, arg3) { 178 var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>"; 179 var fn = typeof arg1 === "function" ? arg1 : arg2; 180 var scope = typeof arg1 === "function" ? arg2 : arg3; 181 invariant(typeof fn === "function", getMessage("m002")); 182 invariant(fn.length === 0, getMessage("m003")); 183 invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'"); 184 return executeAction(actionName, fn, scope, undefined); 185 } 186 exports.runInAction = runInAction; 187 function isAction(thing) { 188 return typeof thing === "function" && thing.isMobxAction === true; 189 } 190 exports.isAction = isAction; 191 function defineBoundAction(target, propertyName, fn) { 192 var res = function res() { 193 return executeAction(propertyName, fn, target, arguments); 194 }; 195 res.isMobxAction = true; 196 addHiddenProp(target, propertyName, res); 197 } 198 function autorun(arg1, arg2, arg3) { 199 var name, view, scope; 200 if (typeof arg1 === "string") { 201 name = arg1; 202 view = arg2; 203 scope = arg3; 204 } else { 205 name = arg1.name || "Autorun@" + getNextId(); 206 view = arg1; 207 scope = arg2; 208 } 209 invariant(typeof view === "function", getMessage("m004")); 210 invariant(isAction(view) === false, getMessage("m005")); 211 if (scope) view = view.bind(scope); 212 var reaction = new Reaction(name, function () { 213 this.track(reactionRunner); 214 }); 215 function reactionRunner() { 216 view(reaction); 217 } 218 reaction.schedule(); 219 return reaction.getDisposer(); 220 } 221 exports.autorun = autorun; 222 function when(arg1, arg2, arg3, arg4) { 223 var name, predicate, effect, scope; 224 if (typeof arg1 === "string") { 225 name = arg1; 226 predicate = arg2; 227 effect = arg3; 228 scope = arg4; 229 } else { 230 name = "When@" + getNextId(); 231 predicate = arg1; 232 effect = arg2; 233 scope = arg3; 234 } 235 var disposer = autorun(name, function (r) { 236 if (predicate.call(scope)) { 237 r.dispose(); 238 var prevUntracked = untrackedStart(); 239 effect.call(scope); 240 untrackedEnd(prevUntracked); 241 } 242 }); 243 return disposer; 244 } 245 exports.when = when; 246 function autorunAsync(arg1, arg2, arg3, arg4) { 247 var name, func, delay, scope; 248 if (typeof arg1 === "string") { 249 name = arg1; 250 func = arg2; 251 delay = arg3; 252 scope = arg4; 253 } else { 254 name = arg1.name || "AutorunAsync@" + getNextId(); 255 func = arg1; 256 delay = arg2; 257 scope = arg3; 258 } 259 invariant(isAction(func) === false, getMessage("m006")); 260 if (delay === void 0) delay = 1; 261 if (scope) func = func.bind(scope); 262 var isScheduled = false; 263 var r = new Reaction(name, function () { 264 if (!isScheduled) { 265 isScheduled = true; 266 setTimeout(function () { 267 isScheduled = false;
268 if (!r.isDisposed) r.track(reactionRunner); 269 }, delay); 270 } 271 }); 272 function reactionRunner() { 273 func(r); 274 } 275 r.schedule(); 276 return r.getDisposer(); 277 } 278 exports.autorunAsync = autorunAsync; 279 function reaction(expression, effect, arg3) { 280 if (arguments.length > 3) { 281 fail(getMessage("m007")); 282 } 283 if (isModifierDescriptor(expression)) { 284 fail(getMessage("m008")); 285 } 286 var opts; 287 if ((typeof arg3 === "undefined" ? "undefined" : _typeof(arg3)) === "object") { 288 opts = arg3; 289 } else { 290 opts = {}; 291 } 292 opts.name = opts.name || expression.name || effect.name || "Reaction@" + getNextId(); 293 opts.fireImmediately = arg3 === true || opts.fireImmediately === true; 294 opts.delay = opts.delay || 0; 295 opts.compareStructural = opts.compareStructural || opts.struct || false; 296 effect = action(opts.name, opts.context ? effect.bind(opts.context) : effect); 297 if (opts.context) { 298 expression = expression.bind(opts.context); 299 } 300 var firstTime = true; 301 var isScheduled = false; 302 var nextValue; 303 var r = new Reaction(opts.name, function () { 304 if (firstTime || opts.delay < 1) { 305 reactionRunner(); 306 } else if (!isScheduled) { 307 isScheduled = true; 308 setTimeout(function () { 309 isScheduled = false; 310 reactionRunner(); 311 }, opts.delay); 312 } 313 }); 314 function reactionRunner() { 315 if (r.isDisposed) return; 316 var changed = false; 317 r.track(function () { 318 var v = expression(r); 319 changed = valueDidChange(opts.compareStructural, nextValue, v); 320 nextValue = v; 321 }); 322 if (firstTime && opts.fireImmediately) effect(nextValue, r); 323 if (!firstTime && changed === true) effect(nextValue, r); 324 if (firstTime) firstTime = false; 325 } 326 r.schedule(); 327 return r.getDisposer(); 328 } 329 exports.reaction = reaction; 330 function createComputedDecorator(compareStructural) { 331 return createClassPropertyDecorator(function (target, name, _, __, originalDescriptor) { 332 invariant(typeof originalDescriptor !== "undefined", getMessage("m009")); 333 invariant(typeof originalDescriptor.get === "function", getMessage("m010")); 334 var adm = asObservableObject(target, ""); 335 defineComputedProperty(adm, name, originalDescriptor.get, originalDescriptor.set, compareStructural, false); 336 }, function (name) { 337 var observable = this.$mobx.values[name]; 338 if (observable === undefined) return undefined; 339 return observable.get(); 340 }, function (name, value) { 341 this.$mobx.values[name].set(value); 342 }, false, false); 343 } 344 var computedDecorator = createComputedDecorator(false); 345 var computedStructDecorator = createComputedDecorator(true); 346 var computed = function computed(arg1, arg2, arg3) { 347 if (typeof arg2 === "string") { 348 return computedDecorator.apply(null, arguments); 349 } 350 invariant(typeof arg1 === "function", getMessage("m011")); 351 invariant(arguments.length < 3, getMessage("m012")); 352 var opts = (typeof arg2 === "undefined" ? "undefined" : _typeof(arg2)) === "object" ? arg2 : {}; 353 opts.setter = typeof arg2 === "function" ? arg2 : opts.setter; 354 return new ComputedValue(arg1, opts.context, opts.compareStructural || opts.struct || false, opts.name || arg1.name || "", opts.setter); 355 }; 356 exports.computed = computed; 357 computed.struct = computedStructDecorator; 358 function createTransformer(transformer, onCleanup) { 359 invariant(typeof transformer === "function" && transformer.length < 2, "createTransformer expects a function that accepts one argument"); 360 var objectCache = {}; 361 var resetId = globalState.resetId; 362 var Transformer = function (_super) { 363 __extends(Transformer, _super); 364 function Transformer(sourceIdentifier, sourceObject) { 365 var _this = _super.call(this, function () { 366 return transformer(sourceObject); 367 }, undefined, false, "Transformer-" + transformer.name + "-" + sourceIdentifier, undefined) || this; 368 _this.sourceIdentifier = sourceIdentifier; 369 _this.sourceObject = sourceObject; 370 return _this; 371 } 372 Transformer.prototype.onBecomeUnobserved = function () { 373 var lastValue = this.value; 374 _super.prototype.onBecomeUnobserved.call(this); 375 delete objectCache[this.sourceIdentifier]; 376 if (onCleanup) onCleanup(lastValue, this.sourceObject); 377 }; 378 return Transformer; 379 }(ComputedValue); 380 return function (object) { 381 if (resetId !== globalState.resetId) { 382 objectCache = {}; 383 resetId = globalState.resetId; 384 } 385 var identifier = getMemoizationId(object); 386 var reactiveTransformer = objectCache[identifier]; 387 if (reactiveTransformer) return reactiveTransformer.get(); 388 reactiveTransformer = objectCache[identifier] = new Transformer(identifier, object); 389 return reactiveTransformer.get(); 390 }; 391 } 392 exports.createTransformer = createTransformer; 393 function getMemoizationId(object) { 394 if (object === null || (typeof object === "undefined" ? "undefined" : _typeof(object)) !== "object") throw new Error("[mobx] transform expected some kind of object, got: " + object); 395 var tid = object.$transformId; 396 if (tid === undefined) { 397 tid = getNextId(); 398 addHiddenProp(object, "$transformId", tid); 399 } 400 return tid; 401 } 402 function expr(expr, scope) { 403 if (!isComputingDerivation()) console.warn(getMessage("m013")); 404 return computed(expr, { context: scope }).get(); 405 } 406 exports.expr = expr; 407 function extendObservable(target) { 408 var properties = []; 409 for (var _i = 1; _i < arguments.length; _i++) { 410 properties[_i - 1] = arguments[_i]; 411 } 412 return extendObservableHelper(target, deepEnhancer, properties); 413 } 414 exports.extendObservable = extendObservable; 415 function extendShallowObservable(target) { 416 var properties = []; 417 for (var _i = 1; _i < arguments.length; _i++) { 418 properties[_i - 1] = arguments[_i]; 419 } 420 return extendObservableHelper(target, referenceEnhancer, properties); 421 } 422 exports.extendShallowObservable = extendShallowObservable; 423 function extendObservableHelper(target, defaultEnhancer, properties) { 424 invariant(arguments.length >= 2, getMessage("m014")); 425 invariant((typeof target === "undefined" ? "undefined" : _typeof(target)) === "object", getMessage("m015")); 426 invariant(!isObservableMap(target), getMessage("m016"));
427 properties.forEach(function (propSet) { 428 invariant((typeof propSet === "undefined" ? "undefined" : _typeof(propSet)) === "object", getMessage("m017")); 429 invariant(!isObservable(propSet), getMessage("m018")); 430 }); 431 var adm = asObservableObject(target); 432 var definedProps = {}; 433 for (var i = properties.length - 1; i >= 0; i--) { 434 var propSet = properties[i]; 435 for (var key in propSet) { 436 if (definedProps[key] !== true && hasOwnProperty(propSet, key)) { 437 definedProps[key] = true; 438 if (target === propSet && !isPropertyConfigurable(target, key)) continue; 439 var descriptor = Object.getOwnPropertyDescriptor(propSet, key); 440 defineObservablePropertyFromDescriptor(adm, key, descriptor, defaultEnhancer); 441 } 442 } 443 } 444 return target; 445 } 446 function getDependencyTree(thing, property) { 447 return nodeToDependencyTree(getAtom(thing, property)); 448 } 449 function nodeToDependencyTree(node) { 450 var result = { 451 name: node.name 452 }; 453 if (node.observing && node.observing.length >
453 0) result.dependencies = unique(node.observing).map(nodeToDependencyTree); 454 return result; 455 } 456 function getObserverTree(thing, property) { 457 return nodeToObserverTree(getAtom(thing, property)); 458 } 459 function nodeToObserverTree(node) { 460 var result = { 461 name: node.name 462 }; 463 if (hasObservers(node)) result.observers = getObservers(node).map(nodeToObserverTree); 464 return result; 465 } 466 function intercept(thing, propOrHandler, handler) { 467 if (typeof handler === "function") return interceptProperty(thing, propOrHandler, handler);else return interceptInterceptable(thing, propOrHandler); 468 } 469 exports.intercept = intercept; 470 function interceptInterceptable(thing, handler) { 471 return getAdministration(thing).intercept(handler); 472 } 473 function interceptProperty(thing, property, handler) { 474 return getAdministration(thing, property).intercept(handler); 475 } 476 function isComputed(value, property) { 477 if (value === null || value === undefined) return false; 478 if (property !== undefined) { 479 if (isObservableObject(value) === false) return false; 480 var atom = getAtom(value, property); 481 return isComputedValue(atom); 482 } 483 return isComputedValue(value); 484 } 485 exports.isComputed = isComputed; 486 function isObservable(value, property) { 487 if (value === null || value === undefined) return false; 488 if (property !== undefined) { 489 if (isObservableArray(value) || isObservableMap(value)) throw new Error(getMessage("m019"));else if (isObservableObject(value)) { 490 var o = value.$mobx; 491 return o.values && !!o.values[property]; 492 } 493 return false; 494 } 495 return isObservableObject(value) || !!value.$mobx || isAtom(value) || isReaction(value) || isComputedValue(value); 496 } 497 exports.isObservable = isObservable; 498 var deepDecorator = createDecoratorForEnhancer(deepEnhancer); 499 var shallowDecorator = createDecoratorForEnhancer(shallowEnhancer); 500 var refDecorator = createDecoratorForEnhancer(referenceEnhancer); 501 var deepStructDecorator = createDecoratorForEnhancer(deepStructEnhancer); 502 var refStructDecorator = createDecoratorForEnhancer(refStructEnhancer); 503 function createObservable(v) { 504 if (v === void 0) { 505 v = undefined; 506 } 507 if (typeof arguments[1] === "string") return deepDecorator.apply(null, arguments); 508 invariant(arguments.length <= 1, getMessage("m021")); 509 invariant(!isModifierDescriptor(v), getMessage("m020")); 510 if (isObservable(v)) return v; 511 var res = deepEnhancer(v, undefined, undefined); 512 if (res !== v) return res; 513 return observable.box(v); 514 } 515 var IObservableFactories = function () { 516 function IObservableFactories() {} 517 IObservableFactories.prototype.box = function (value, name) { 518 if (arguments.length > 2) incorrectlyUsedAsDecorator("box"); 519 return new ObservableValue(value, deepEnhancer, name); 520 }; 521 IObservableFactories.prototype.shallowBox = function (value, name) { 522 if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowBox"); 523 return new ObservableValue(value, referenceEnhancer, name); 524 }; 525 IObservableFactories.prototype.array = function (initialValues, name) { 526 if (arguments.length > 2) incorrectlyUsedAsDecorator("array"); 527 return new ObservableArray(initialValues, deepEnhancer, name); 528 }; 529 IObservableFactories.prototype.shallowArray = function (initialValues, name) { 530 if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowArray"); 531 return new ObservableArray(initialValues, referenceEnhancer, name); 532 }; 533 IObservableFactories.prototype.map = function (initialValues, name) { 534 if (arguments.length > 2) incorrectlyUsedAsDecorator("map"); 535 return new ObservableMap(initialValues, deepEnhancer, name); 536 }; 537 IObservableFactories.prototype.shallowMap = function (initialValues, name) { 538 if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowMap"); 539 return new ObservableMap(initialValues, referenceEnhancer, name); 540 }; 541 IObservableFactories.prototype.object = function (props, name) { 542 if (arguments.length > 2) incorrectlyUsedAsDecorator("object"); 543 var res = {}; 544 asObservableObject(res, name); 545 extendObservable(res, props); 546 return res; 547 }; 548 IObservableFactories.prototype.shallowObject = function (props, name) { 549 if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowObject"); 550 var res = {}; 551 asObservableObject(res, name); 552 extendShallowObservable(res, props); 553 return res; 554 }; 555 IObservableFactories.prototype.ref = function () { 556 if (arguments.length < 2) { 557 return createModifierDescriptor(referenceEnhancer, arguments[0]); 558 } else { 559 return refDecorator.apply(null, arguments); 560 } 561 }; 562 IObservableFactories.prototype.shallow = function () { 563 if (arguments.length < 2) { 564 return createModifierDescriptor(shallowEnhancer, arguments[0]); 565 } else { 566 return shallowDecorator.apply(null, arguments); 567 } 568 }; 569 IObservableFactories.prototype.deep = function () { 570 if (arguments.length < 2) { 571 return createModifierDescriptor(deepEnhancer, arguments[0]); 572 } else { 573 return deepDecorator.apply(null, arguments); 574 } 575 }; 576 IObservableFactories.prototype.struct = function () { 577 if (arguments.length < 2) { 578 return createModifierDescriptor(deepStructEnhancer, arguments[0]); 579 } else { 580 return deepStructDecorator.apply(null, arguments); 581 } 582 }; 583 return IObservableFactories; 584 }(); 585 exports.IObservableFactories = IObservableFactories; 586 var observable = createObservable; 587 exports.observable = observable; 588 Object.keys(IObservableFactories.prototype).forEach(function (key) { 589 return observable[key] = IObservableFactories.prototype[key]; 590 }); 591 observable.deep.struct = observable.struct; 592 observable.ref.struct = function () { 593 if (arguments.length < 2) { 594 return createModifierDescriptor(refStructEnhancer, arguments[0]); 595 } else { 596 return refStructDecorator.apply(null, arguments); 597 } 598 }; 599 function incorrectlyUsedAsDecorator(methodName) {
600 fail("Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?"); 601 } 602 function createDecoratorForEnhancer(enhancer) { 603 invariant(!!enhancer, ":("); 604 return createClassPropertyDecorator(function (target, name, baseValue, _, baseDescriptor) { 605 assertPropertyConfigurable(target, name); 606 invariant(!baseDescriptor || !baseDescriptor.get, getMessage("m022")); 607 var adm = asObservableObject(target, undefined); 608 defineObservableProperty(adm, name, baseValue, enhancer); 609 }, function (name) { 610 var observable = this.$mobx.values[name]; 611 if (observable === undefined) return undefined; 612 return observable.get(); 613 }, function (name, value) { 614 setPropertyValue(this, name, value); 615 }, true, false); 616 } 617 function observe(thing, propOrCb, cbOrFire, fireImmediately) { 618 if (typeof cbOrFire === "function") return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire); 619 } 620 exports.observe = observe; 621 function observeObservable(thing, listener, fireImmediately) { 622 return getAdministration(thing).observe(listener, fireImmediately); 623 } 624 function observeObservableProperty(thing, property, listener, fireImmediately) { 625 return getAdministration(thing, property).observe(listener, fireImmediately); 626 } 627 function toJS(source, detectCycles, __alreadySeen) { 628 if (detectCycles === void 0) { 629 detectCycles = true; 630 } 631 if (__alreadySeen === void 0) { 632 __alreadySeen = []; 633 } 634 function cache(value) { 635 if (detectCycles) __alreadySeen.push([source, value]); 636 return value; 637 } 638 if (isObservable(source)) { 639 if (detectCycles && __alreadySeen === null) __alreadySeen = []; 640 if (detectCycles && source !== null && (typeof source === "undefined" ? "undefined" : _typeof(source)) === "object") { 641 for (var i = 0, l = __alreadySeen.length; i < l; i++) { 642 if (__alreadySeen[i][0] === source) return __alreadySeen[i][1]; 643 } 644 } 645 if (isObservableArray(source)) { 646 var res = cache([]); 647 var toAdd = source.map(function (value) { 648 return toJS(value, detectCycles, __alreadySeen); 649 }); 650 res.length = toAdd.length; 651 for (var i = 0, l = toAdd.length; i < l; i++) { 652 res[i] = toAdd[i]; 653 }return res; 654 } 655 if (isObservableObject(source)) { 656 var res = cache({}); 657 for (var key in source) { 658 res[key] = toJS(source[key], detectCycles, __alreadySeen); 659 }return res; 660 } 661 if (isObservableMap(source)) { 662 var res_1 = cache({}); 663 source.forEach(function (value, key) { 664 return res_1[key] = toJS(value, detectCycles, __alreadySeen); 665 }); 666 return res_1; 667 } 668 if (isObservableValue(source)) return toJS(source.get(), detectCycles, __alreadySeen); 669 } 670 return source; 671 } 672 exports.toJS = toJS; 673 function transaction(action, thisArg) { 674 if (thisArg === void 0) { 675 thisArg = undefined; 676 } 677 deprecated(getMessage("m023")); 678 return runInTransaction.apply(undefined, arguments); 679 } 680 exports.transaction = transaction; 681 function runInTransaction(action, thisArg) { 682 if (thisArg === void 0) { 683 thisArg = undefined; 684 } 685 return executeAction("", action); 686 } 687 function log(msg) { 688 console.log(msg); 689 return msg; 690 } 691 function whyRun(thing, prop) { 692 switch (arguments.length) { 693 case 0: 694 thing = globalState.trackingDerivation; 695 if (!thing) return log(getMessage("m024")); 696 break; 697 case 2: 698 thing = getAtom(thing, prop); 699 break; 700 } 701 thing = getAtom(thing); 702 if (isComputedValue(thing)) return log(thing.whyRun());else if (isReaction(thing)) return log(thing.whyRun()); 703 return fail(getMessage("m025")); 704 } 705 exports.whyRun = whyRun; 706 function createAction(actionName, fn) { 707 invariant(typeof fn === "function", getMessage("m026")); 708 invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'"); 709 var res = function res() { 710 return executeAction(actionName, fn, this, arguments); 711 }; 712 res.originalFn = fn; 713 res.isMobxAction = true; 714 return res; 715 } 716 function executeAction(actionName, fn, scope, args) { 717 var runInfo = startAction(actionName, fn, scope, args); 718 try { 719 return fn.apply(scope, args); 720 } finally { 721 endAction(runInfo); 722 } 723 } 724 function startAction(actionName, fn, scope, args) { 725 var notifySpy = isSpyEnabled() && !!actionName; 726 var startTime = 0; 727 if (notifySpy) { 728 startTime = Date.now(); 729 var l = args && args.length || 0; 730 var flattendArgs = new Array(l); 731 if (l > 0) for (var i = 0; i < l; i++) { 732 flattendArgs[i] = args[i]; 733 }spyReportStart({ 734 type: "action", 735 name: actionName, 736 fn: fn, 737 object: scope, 738 arguments: flattendArgs 739 }); 740 } 741 var prevDerivation = untrackedStart(); 742 startBatch(); 743 var prevAllowStateChanges = allowStateChangesStart(true); 744 return { 745 prevDerivation: prevDerivation, 746 prevAllowStateChanges: prevAllowStateChanges, 747 notifySpy: notifySpy, 748 startTime: startTime 749 }; 750 } 751 function endAction(runInfo) { 752 allowStateChangesEnd(runInfo.prevAllowStateChanges); 753 endBatch(); 754 untrackedEnd(runInfo.prevDerivation); 755 if (runInfo.notifySpy) spyReportEnd({ time: Date.now() - runInfo.startTime }); 756 } 757 function useStrict(strict) { 758 invariant(globalState.trackingDerivation === null, getMessage("m028")); 759 globalState.strictMode = strict; 760 globalState.allowStateChanges = !strict; 761 } 762 exports.useStrict = useStrict; 763 function isStrictModeEnabled() { 764 return globalState.strictMode; 765 } 766 exports.isStrictModeEnabled = isStrictModeEnabled; 767 function allowStateChanges(allowStateChanges, func) { 768 var prev = allowStateChangesStart(allowStateChanges); 769 var res; 770 try { 771 res = func(); 772 } finally { 773 allowStateChangesEnd(prev); 774 } 775 return res; 776 } 777 function allowStateChangesStart(allowStateChanges) { 778 var prev = globalState.allowStateChanges; 779 globalState.allowStateChanges = allowStateChanges; 780 return prev; 781 } 782 function allowStateChangesEnd(prev) { 783 globalState.allowStateChanges = prev; 784 } 785 var BaseAtom = function () { 786 function BaseAtom(name) { 787 if (name === void 0) { 788 name = "Atom@" + getNextId(); 789 } 790 this.name = name; 791 this.isPendingUnobservation = true; 792 this.observers = []; 793 this.observersIndexes = {}; 794 this.diffValue = 0; 795 this.lastAccessedBy = 0; 796 this.lowestObserverState = IDerivationState.NOT_TRACKING; 797 } 798 BaseAtom.prototype.onBecomeUnobserved = function () {}; 799 BaseAtom.prototype.reportObserved = function () { 800 reportObserved(this); 801 }; 802 BaseAtom.prototype.reportChanged = function () { 803 startBatch(); 804 propagateChanged(this); 805 endBatch(); 806 }; 807 BaseAtom.prototype.toString = function () { 808 return this.name; 809 }; 810 return BaseAtom; 811 }(); 812 exports.BaseAtom = BaseAtom; 813 var Atom = function (_super) { 814 __extends(Atom, _super); 815 function Atom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) { 816 if (name === void 0) { 817 name = "Atom@" + getNextId(); 818 } 819 if (onBecomeObservedHandler === void 0) { 820 onBecomeObservedHandler = noop; 821 } 822 if (onBecomeUnobservedHandler === void 0) { 823 onBecomeUnobservedHandler = noop; 824 } 825 var _this = _super.call(this, name) || this; 826 _this.name = name; 827 _this.onBecomeObservedHandler = onBecomeObservedHandler; 828 _this.onBecomeUnobservedHandler = onBecomeUnobservedHandler; 829 _this.isPendingUnobservation = false;
830 _this.isBeingTracked = false; 831 return _this; 832 } 833 Atom.prototype.reportObserved = function () { 834 startBatch(); 835 _super.prototype.reportObserved.call(this); 836 if (!this.isBeingTracked) { 837 this.isBeingTracked = true; 838 this.onBecomeObservedHandler(); 839 } 840 endBatch(); 841 return !!globalState.trackingDerivation; 842 }; 843 Atom.prototype.onBecomeUnobserved = function () { 844 this.isBeingTracked = false; 845 this.onBecomeUnobservedHandler(); 846 }; 847 return Atom; 848 }(BaseAtom); 849 exports.Atom = Atom; 850 var isAtom = createInstanceofPredicate("Atom", BaseAtom); 851 var ComputedValue = function () { 852 function ComputedValue(derivation, scope, compareStructural, name, setter) { 853 this.derivation = derivation; 854 this.scope = scope; 855 this.compareStructural = compareStructural; 856 this.dependenciesState = IDerivationState.NOT_TRACKING; 857 this.observing = []; 858 this.newObserving = null; 859 this.isPendingUnobservation = false; 860 this.observers = []; 861 this.observersIndexes = {}; 862 this.diffValue = 0; 863 this.runId = 0; 864 this.lastAccessedBy = 0; 865 this.lowestObserverState = IDerivationState.UP_TO_DATE; 866 this.unboundDepsCount = 0; 867 this.__mapid = "#" + getNextId(); 868 this.value = undefined; 869 this.isComputing = false; 870 this.isRunningSetter = false; 871 this.name = name || "ComputedValue@" + getNextId(); 872 if (setter) this.setter = createAction(name + "-setter", setter); 873 } 874 ComputedValue.prototype.onBecomeStale = function () { 875 propagateMaybeChanged(this); 876 }; 877 ComputedValue.prototype.onBecomeUnobserved = function () { 878 invariant(this.dependenciesState !== IDerivationState.NOT_TRACKING, getMessage("m029")); 879 clearObserving(this); 880 this.value = undefined; 881 }; 882 ComputedValue.prototype.get = function () { 883 invariant(!this.isComputing, "Cycle detected in computation " + this.name, this.derivation); 884 if (globalState.inBatch === 0) { 885 startBatch(); 886 if (shouldCompute(this)) this.value = this.computeValue(false); 887 endBatch(); 888 } else { 889 reportObserved(this); 890 if (shouldCompute(this)) if (this.trackAndCompute()) propagateChangeConfirmed(this); 891 } 892 var result = this.value; 893 if (isCaughtException(result)) throw result.cause; 894 return result; 895 }; 896 ComputedValue.prototype.peek = function () { 897 var res = this.computeValue(false); 898 if (isCaughtException(res)) throw res.cause; 899 return res; 900 }; 901 ComputedValue.prototype.set = function (value) { 902 if (this.setter) { 903 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?"); 904 this.isRunningSetter = true; 905 try { 906 this.setter.call(this.scope, value); 907 } finally { 908 this.isRunningSetter = false;
909 } 910 } else invariant(false, "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value."); 911 }; 912 ComputedValue.prototype.trackAndCompute = function () { 913 if (isSpyEnabled()) { 914 spyReport({ 915 object: this.scope, 916 type: "compute", 917 fn: this.derivation 918 }); 919 } 920 var oldValue = this.value; 921 var newValue = this.value = this.computeValue(true); 922 return isCaughtException(newValue) || valueDidChange(this.compareStructural, newValue, oldValue); 923 }; 924 ComputedValue.prototype.computeValue = function (track) { 925 this.isComputing = true; 926 globalState.computationDepth++; 927 var res; 928 if (track) { 929 res = trackDerivedFunction(this, this.derivation, this.scope); 930 } else { 931 try { 932 res = this.derivation.call(this.scope); 933 } catch (e) { 934 res = new CaughtException(e); 935 } 936 } 937 globalState.computationDepth--; 938 this.isComputing = false; 939 return res; 940 }; 941 ; 942 ComputedValue.prototype.observe = function (listener, fireImmediately) { 943 var _this = this; 944 var firstTime = true; 945 var prevValue = undefined; 946 return autorun(function () { 947 var newValue = _this.get(); 948 if (!firstTime || fireImmediately) { 949 var prevU = untrackedStart(); 950 listener({ 951 type: "update", 952 object: _this, 953 newValue: newValue, 954 oldValue: prevValue 955 }); 956 untrackedEnd(prevU); 957 } 958 firstTime = false; 959 prevValue = newValue; 960 }); 961 }; 962 ComputedValue.prototype.toJSON = function () { 963 return this.get(); 964 }; 965 ComputedValue.prototype.toString = function () { 966 return this.name + "[" + this.derivation.toString() + "]"; 967 }; 968 ComputedValue.prototype.valueOf = function () { 969 return toPrimitive(this.get()); 970 }; 971 ; 972 ComputedValue.prototype.whyRun = function () { 973 var isTracking = Boolean(globalState.trackingDerivation); 974 var observing = unique(this.isComputing ? this.newObserving : this.observing).map(function (dep) { 975 return dep.name; 976 }); 977 var observers = unique(getObservers(this).map(function (dep) { 978 return dep.name; 979 })); 980 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"); 981 }; 982 return ComputedValue; 983 }(); 984 ComputedValue.prototype[primitiveSymbol()] = ComputedValue.prototype.valueOf; 985 var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue); 986 var IDerivationState; 987 (function (IDerivationState) { 988 IDerivationState[IDerivationState["NOT_TRACKING"] = -1] = "NOT_TRACKING"; 989 IDerivationState[IDerivationState["UP_TO_DATE"] = 0] = "UP_TO_DATE"; 990 IDerivationState[IDerivationState["POSSIBLY_STALE"] = 1] = "POSSIBLY_STALE"; 991 IDerivationState[IDerivationState["STALE"] = 2] = "STALE"; 992 })(IDerivationState || (IDerivationState = {})); 993 exports.IDerivationState = IDerivationState; 994 var CaughtException = function () { 995 function CaughtException(cause) { 996 this.cause = cause; 997 } 998 return CaughtException; 999 }(); 1000 function isCaughtException(e) { 1001 return e instanceof CaughtException; 1002 } 1003 function shouldCompute(derivation) { 1004 switch (derivation.dependenciesState) { 1005 case IDerivationState.UP_TO_DATE: 1006 return false;
1007 case IDerivationState.NOT_TRACKING: 1008 case IDerivationState.STALE: 1009 return true; 1010 case IDerivationState.POSSIBLY_STALE: 1011 { 1012 var prevUntracked = untrackedStart(); 1013 var obs = derivation.observing, 1014 l = obs.length; 1015 for (var i = 0; i < l; i++) { 1016 var obj = obs[i]; 1017 if (isComputedValue(obj)) { 1018 try { 1019 obj.get(); 1020 } catch (e) { 1021 untrackedEnd(prevUntracked); 1022 return true; 1023 } 1024 if (derivation.dependenciesState === IDerivationState.STALE) { 1025 untrackedEnd(prevUntracked); 1026 return true; 1027 } 1028 } 1029 } 1030 changeDependenciesStateTo0(derivation); 1031 untrackedEnd(prevUntracked); 1032 return false; 1033 } 1034 } 1035 } 1036 function isComputingDerivation() { 1037 return globalState.trackingDerivation !== null; 1038 } 1039 function checkIfStateModificationsAreAllowed(atom) { 1040 var hasObservers = atom.observers.length > 0; 1041 if (globalState.computationDepth > 0 && hasObservers) fail(getMessage("m031") + atom.name); 1042 if (!globalState.allowStateChanges && hasObservers) fail(getMessage(globalState.strictMode ? "m030a" : "m030b") + atom.name); 1043 } 1044 function trackDerivedFunction(derivation, f, context) { 1045 changeDependenciesStateTo0(derivation); 1046 derivation.newObserving = new Array(derivation.observing.length + 100); 1047 derivation.unboundDepsCount = 0; 1048 derivation.runId = ++globalState.runId; 1049 var prevTracking = globalState.trackingDerivation; 1050 globalState.trackingDerivation = derivation; 1051 var result; 1052 try { 1053 result = f.call(context); 1054 } catch (e) { 1055 result = new CaughtException(e); 1056 } 1057 globalState.trackingDerivation = prevTracking; 1058 bindDependencies(derivation); 1059 return result; 1060 } 1061 function bindDependencies(derivation) { 1062 var prevObserving = derivation.observing; 1063 var observing = derivation.observing = derivation.newObserving; 1064 derivation.newObserving = null; 1065 var i0 = 0, 1066 l = derivation.unboundDepsCount; 1067 for (var i = 0; i < l; i++) { 1068 var dep = observing[i]; 1069 if (dep.diffValue === 0) { 1070 dep.diffValue = 1; 1071 if (i0 !== i) observing[i0] = dep; 1072 i0++; 1073 } 1074 } 1075 observing.length = i0; 1076 l = prevObserving.length; 1077 while (l--) { 1078 var dep = prevObserving[l]; 1079 if (dep.diffValue === 0) { 1080 removeObserver(dep, derivation); 1081 } 1082 dep.diffValue = 0; 1083 } 1084 while (i0--) { 1085 var dep = observing[i0]; 1086 if (dep.diffValue === 1) { 1087 dep.diffValue = 0; 1088 addObserver(dep, derivation); 1089 } 1090 } 1091 } 1092 function clearObserving(derivation) { 1093 var obs = derivation.observing; 1094 var i = obs.length; 1095 while (i--) { 1096 removeObserver(obs[i], derivation); 1097 }derivation.dependenciesState = IDerivationState.NOT_TRACKING; 1098 obs.length = 0; 1099 } 1100 function untracked(action) { 1101 var prev = untrackedStart(); 1102 var res = action(); 1103 untrackedEnd(prev); 1104 return res; 1105 } 1106 exports.untracked = untracked; 1107 function untrackedStart() { 1108 var prev = globalState.trackingDerivation; 1109 globalState.trackingDerivation = null; 1110 return prev; 1111 } 1112 function untrackedEnd(prev) { 1113 globalState.trackingDerivation = prev; 1114 } 1115 function changeDependenciesStateTo0(derivation) { 1116 if (derivation.dependenciesState === IDerivationState.UP_TO_DATE) return; 1117 derivation.dependenciesState = IDerivationState.UP_TO_DATE; 1118 var obs = derivation.observing; 1119 var i = obs.length; 1120 while (i--) { 1121 obs[i].lowestObserverState = IDerivationState.UP_TO_DATE; 1122 } 1123 }
1124 var persistentKeys = ["mobxGuid", "resetId", "spyListeners", "strictMode", "runId"]; 1125 var MobXGlobals = function () { 1126 function MobXGlobals() { 1127 this.version = 5; 1128 this.trackingDerivation = null; 1129 this.computationDepth = 0; 1130 this.runId = 0; 1131 this.mobxGuid = 0; 1132 this.inBatch = 0; 1133 this.pendingUnobservations = []; 1134 this.pendingReactions = []; 1135 this.isRunningReactions = false; 1136 this.allowStateChanges = true; 1137 this.strictMode = false; 1138 this.resetId = 0; 1139 this.spyListeners = []; 1140 this.globalReactionErrorHandlers = []; 1141 } 1142 return MobXGlobals; 1143 }(); 1144 var globalState = new MobXGlobals(); 1145 function shareGlobalState() { 1146 var global = getGlobal(); 1147 var ownState = globalState; 1148 if (global.__mobservableTrackingStack || global.__mobservableViewStack) throw new Error("[mobx] An incompatible version of mobservable is already loaded."); 1149 if (global.__mobxGlobal && global.__mobxGlobal.version !== ownState.version) throw new Error("[mobx] An incompatible version of mobx is already loaded."); 1150 if (global.__mobxGlobal) globalState = global.__mobxGlobal;else global.__mobxGlobal = ownState; 1151 } 1152 function getGlobalState() { 1153 return globalState; 1154 } 1155 function registerGlobals() {} 1156 function resetGlobalState() { 1157 globalState.resetId++; 1158 var defaultGlobals = new MobXGlobals(); 1159 for (var key in defaultGlobals) { 1160 if (persistentKeys.indexOf(key) === -1) globalState[key] = defaultGlobals[key]; 1161 }globalState.allowStateChanges = !globalState.strictMode; 1162 } 1163 function hasObservers(observable) { 1164 return observable.observers && observable.observers.length > 0; 1165 } 1166 function getObservers(observable) { 1167 return observable.observers; 1168 } 1169 function invariantObservers(observable) { 1170 var list = observable.observers; 1171 var map = observable.observersIndexes; 1172 var l = list.length; 1173 for (var i = 0; i < l; i++) { 1174 var id = list[i].__mapid; 1175 if (i) { 1176 invariant(map[id] === i, "INTERNAL ERROR maps derivation.__mapid to index in list"); 1177 } else { 1178 invariant(!(id in map), "INTERNAL ERROR observer on index 0 shouldnt be held in map."); 1179 } 1180 } 1181 invariant(list.length === 0 || Object.keys(map).length === list.length - 1, "INTERNAL ERROR there is no junk in map"); 1182 } 1183 function addObserver(observable, node) { 1184 var l = observable.observers.length; 1185 if (l) { 1186 observable.observersIndexes[node.__mapid] = l; 1187 } 1188 observable.observers[l] = node; 1189 if (observable.lowestObserverState > node.dependenciesState) observable.lowestObserverState = node.dependenciesState; 1190 } 1191 function removeObserver(observable, node) { 1192 if (observable.observers.length === 1) { 1193 observable.observers.length = 0; 1194 queueForUnobservation(observable); 1195 } else { 1196 var list = observable.observers; 1197 var map_1 = observable.observersIndexes; 1198 var filler = list.pop();
1199 if (filler !== node) { 1200 var index = map_1[node.__mapid] || 0; 1201 if (index) { 1202 map_1[filler.__mapid] = index; 1203 } else { 1204 delete map_1[filler.__mapid]; 1205 } 1206 list[index] = filler; 1207 } 1208 delete map_1[node.__mapid]; 1209 } 1210 } 1211 function queueForUnobservation(observable) { 1212 if (!observable.isPendingUnobservation) { 1213 observable.isPendingUnobservation = true; 1214 globalState.pendingUnobservations.push(observable); 1215 } 1216 } 1217 function startBatch() { 1218 globalState.inBatch++; 1219 } 1220 function endBatch() { 1221 if (--globalState.inBatch === 0) { 1222 runReactions(); 1223 var list = globalState.pendingUnobservations; 1224 for (var i = 0; i < list.length; i++) { 1225 var observable_1 = list[i]; 1226 observable_1.isPendingUnobservation = false; 1227 if (observable_1.observers.length === 0) { 1228 observable_1.onBecomeUnobserved(); 1229 } 1230 } 1231 globalState.pendingUnobservations = []; 1232 } 1233 } 1234 function reportObserved(observable) { 1235 var derivation = globalState.trackingDerivation; 1236 if (derivation !== null) { 1237 if (derivation.runId !== observable.lastAccessedBy) { 1238 observable.lastAccessedBy = derivation.runId; 1239 derivation.newObserving[derivation.unboundDepsCount++] = observable; 1240 } 1241 } else if (observable.observers.length === 0) { 1242 queueForUnobservation(observable); 1243 } 1244 } 1245 function invariantLOS(observable, msg) { 1246 var min = getObservers(observable).reduce(function (a, b) { 1247 return Math.min(a, b.dependenciesState); 1248 }, 2); 1249 if (min >= observable.lowestObserverState) return; 1250 throw new Error("lowestObserverState is wrong for " + msg + " because " + min + " < " + observable.lowestObserverState); 1251 } 1252 function propagateChanged(observable) { 1253 if (observable.lowestObserverState === IDerivationState.STALE) return; 1254 observable.lowestObserverState = IDerivationState.STALE; 1255 var observers = observable.observers; 1256 var i = observers.length; 1257 while (i--) { 1258 var d = observers[i]; 1259 if (d.dependenciesState === IDerivationState.UP_TO_DATE) d.onBecomeStale(); 1260 d.dependenciesState = IDerivationState.STALE; 1261 } 1262 } 1263 function propagateChangeConfirmed(observable) { 1264 if (observable.lowestObserverState === IDerivationState.STALE) return; 1265 observable.lowestObserverState = IDerivationState.STALE; 1266 var observers = observable.observers; 1267 var i = observers.length; 1268 while (i--) { 1269 var d = observers[i]; 1270 if (d.dependenciesState === IDerivationState.POSSIBLY_STALE) d.dependenciesState = IDerivationState.STALE;else if (d.dependenciesState === IDerivationState.UP_TO_DATE) observable.lowestObserverState = IDerivationState.UP_TO_DATE; 1271 } 1272 } 1273 function propagateMaybeChanged(observable) { 1274 if (observable.lowestObserverState !== IDerivationState.UP_TO_DATE) return; 1275 observable.lowestObserverState = IDerivationState.POSSIBLY_STALE; 1276 var observers = observable.observers; 1277 var i = observers.length; 1278 while (i--) { 1279 var d = observers[i]; 1280 if (d.dependenciesState === IDerivationState.UP_TO_DATE) { 1281 d.dependenciesState = IDerivationState.POSSIBLY_STALE; 1282 d.onBecomeStale(); 1283 } 1284 } 1285 } 1286 var Reaction = function () { 1287 function Reaction(name, onInvalidate) { 1288 if (name === void 0) { 1289 name = "Reaction@" + getNextId(); 1290 } 1291 this.name = name; 1292 this.onInvalidate = onInvalidate; 1293 this.observing = []; 1294 this.newObserving = []; 1295 this.dependenciesState = IDerivationState.NOT_TRACKING; 1296 this.diffValue = 0; 1297 this.runId = 0; 1298 this.unboundDepsCount = 0; 1299 this.__mapid = "#" + getNextId(); 1300 this.isDisposed = false;
1301 this._isScheduled = false; 1302 this._isTrackPending = false; 1303 this._isRunning = false; 1304 } 1305 Reaction.prototype.onBecomeStale = function () { 1306 this.schedule(); 1307 }; 1308 Reaction.prototype.schedule = function () { 1309 if (!this._isScheduled) { 1310 this._isScheduled = true; 1311 globalState.pendingReactions.push(this); 1312 runReactions(); 1313 } 1314 }; 1315 Reaction.prototype.isScheduled = function () { 1316 return this._isScheduled; 1317 }; 1318 Reaction.prototype.runReaction = function () { 1319 if (!this.isDisposed) { 1320 startBatch(); 1321 this._isScheduled = false; 1322 if (shouldCompute(this)) { 1323 this._isTrackPending = true; 1324 this.onInvalidate(); 1325 if (this._isTrackPending && isSpyEnabled()) { 1326 spyReport({ 1327 object: this, 1328 type: "scheduled-reaction" 1329 }); 1330 } 1331 } 1332 endBatch(); 1333 } 1334 }; 1335 Reaction.prototype.track = function (fn) { 1336 startBatch(); 1337 var notify = isSpyEnabled(); 1338 var startTime; 1339 if (notify) { 1340 startTime = Date.now(); 1341 spyReportStart({ 1342 object: this, 1343 type: "reaction", 1344 fn: fn 1345 }); 1346 } 1347 this._isRunning = true; 1348 var result = trackDerivedFunction(this, fn, undefined); 1349 this._isRunning = false; 1350 this._isTrackPending = false; 1351 if (this.isDisposed) { 1352 clearObserving(this); 1353 } 1354 if (isCaughtException(result)) this.reportExceptionInDerivation(result.cause); 1355 if (notify) { 1356 spyReportEnd({ 1357 time: Date.now() - startTime 1358 }); 1359 } 1360 endBatch(); 1361 }; 1362 Reaction.prototype.reportExceptionInDerivation = function (error) { 1363 var _this = this; 1364 if (this.errorHandler) { 1365 this.errorHandler(error, this); 1366 return; 1367 } 1368 var message = "[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: '" + this; 1369 var messageToUser = getMessage("m037"); 1370 console.error(message || messageToUser, error); 1371 if (isSpyEnabled()) { 1372 spyReport({ 1373 type: "error", 1374 message: message, 1375 error: error, 1376 object: this 1377 }); 1378 } 1379 globalState.globalReactionErrorHandlers.forEach(function (f) { 1380 return f(error, _this); 1381 }); 1382 }; 1383 Reaction.prototype.dispose = function () { 1384 if (!this.isDisposed) { 1385 this.isDisposed = true; 1386 if (!this._isRunning) { 1387 startBatch(); 1388 clearObserving(this); 1389 endBatch(); 1390 } 1391 } 1392 }; 1393 Reaction.prototype.getDisposer = function () { 1394 var r = this.dispose.bind(this); 1395 r.$mobx = this; 1396 r.onError = registerErrorHandler; 1397 return r; 1398 }; 1399 Reaction.prototype.toString = function () { 1400 return "Reaction[" + this.name + "]"; 1401 }; 1402 Reaction.prototype.whyRun = function () { 1403 var observing = unique(this._isRunning ? this.newObserving : this.observing).map(function (dep) { 1404 return dep.name; 1405 }); 1406 return "\nWhyRun? reaction '" + this.name + "':\n * Status: [" + (this.isDisposed ? "stopped" : this._isRunning ? "running" : this.isScheduled() ? "scheduled" : "
1406idle") + "]\n * This reaction will re-run if any of the following observables changes:\n " + joinStrings(observing) + "\n " + (this._isRunning ? " (... or any observable accessed during the remainder of the current run)" : "") + "\n\t" + getMessage("m038") + "\n"; 1407 }; 1408 return Reaction; 1409 }(); 1410 exports.Reaction = Reaction; 1411 function registerErrorHandler(handler) { 1412 invariant(this && this.$mobx && isReaction(this.$mobx), "Invalid `this`"); 1413 invariant(!this.$mobx.errorHandler, "Only one onErrorHandler can be registered"); 1414 this.$mobx.errorHandler = handler; 1415 } 1416 function onReactionError(handler) { 1417 globalState.globalReactionErrorHandlers.push(handler); 1418 return function () { 1419 var idx = globalState.globalReactionErrorHandlers.indexOf(handler); 1420 if (idx >= 0) globalState.globalReactionErrorHandlers.splice(idx, 1); 1421 }; 1422 } 1423 var MAX_REACTION_ITERATIONS = 100; 1424 var reactionScheduler = function reactionScheduler(f) { 1425 return f(); 1426 }; 1427 function runReactions() { 1428 if (globalState.inBatch > 0 || globalState.isRunningReactions) return; 1429 reactionScheduler(runReactionsHelper); 1430 } 1431 function runReactionsHelper() { 1432 globalState.isRunningReactions = true; 1433 var allReactions = globalState.pendingReactions; 1434 var iterations = 0; 1435 while (allReactions.length > 0) { 1436 if (++iterations === MAX_REACTION_ITERATIONS) { 1437 console.error("Reaction doesn't converge to a stable state after " + MAX_REACTION_ITERATIONS + " iterations." + (" Probably there is a cycle in the reactive function: " + allReactions[0])); 1438 allReactions.splice(0); 1439 } 1440 var remainingReactions = allReactions.splice(0); 1441 for (var i = 0, l = remainingReactions.length; i < l; i++) { 1442 remainingReactions[i].runReaction(); 1443 } 1444 } 1445 globalState.isRunningReactions = false; 1446 } 1447 var isReaction = createInstanceofPredicate("Reaction", Reaction); 1448 function setReactionScheduler(fn) { 1449 var baseScheduler = reactionScheduler; 1450 reactionScheduler = function reactionScheduler(f) { 1451 return fn(function () { 1452 return baseScheduler(f); 1453 }); 1454 }; 1455 } 1456 function isSpyEnabled() { 1457 return !!globalState.spyListeners.length; 1458 } 1459 function spyReport(event) { 1460 if (!globalState.spyListeners.length) return; 1461 var listeners = globalState.spyListeners; 1462 for (var i = 0, l = listeners.length; i < l; i++) { 1463 listeners[i](event); 1464 } 1465 } 1466 function spyReportStart(event) { 1467 var change = objectAssign({}, event, { spyReportStart: true }); 1468 spyReport(change); 1469 } 1470 var END_EVENT = { spyReportEnd: true }; 1471 function spyReportEnd(change) { 1472 if (change) spyReport(objectAssign({}, change, END_EVENT));else spyReport(END_EVENT); 1473 } 1474 function spy(listener) { 1475 globalState.spyListeners.push(listener); 1476 return once(function () { 1477 var idx = globalState.spyListeners.indexOf(listener); 1478 if (idx !== -1) globalState.spyListeners.splice(idx, 1); 1479 }); 1480 } 1481 exports.spy = spy; 1482 function hasInterceptors(interceptable) { 1483 return interceptable.interceptors && interceptable.interceptors.length > 0; 1484 } 1485 function registerInterceptor(interceptable, handler) { 1486 var interceptors = interceptable.interceptors || (interceptable.interceptors = []); 1487 interceptors.push(handler); 1488 return once(function () { 1489 var idx = interceptors.indexOf(handler); 1490 if (idx !== -1) interceptors.splice(idx, 1); 1491 }); 1492 } 1493 function interceptChange(interceptable, change) { 1494 var prevU = untrackedStart(); 1495 try { 1496 var interceptors = interceptable.interceptors; 1497 if (interceptors) for (var i = 0, l = interceptors.length; i < l; i++) { 1498 change = interceptors[i](change); 1499 invariant(!change || change.type, "Intercept handlers should return nothing or a change object"); 1500 if (!change) break; 1501 } 1502 return change; 1503 } finally { 1504 untrackedEnd(prevU); 1505 } 1506 } 1507 function hasListeners(listenable) { 1508 return listenable.changeListeners && listenable.changeListeners.length > 0; 1509 } 1510 function registerListener(listenable, handler) { 1511 var listeners = listenable.changeListeners || (listenable.changeListeners = []); 1512 listeners.push(handler); 1513 return once(function () { 1514 var idx = listeners.indexOf(handler); 1515 if (idx !== -1) listeners.splice(idx, 1); 1516 }); 1517 } 1518 function notifyListeners(listenable, change) { 1519 var prevU = untrackedStart(); 1520 var listeners = listenable.changeListeners; 1521 if (!listeners) return; 1522 listeners = listeners.slice(); 1523 for (var i = 0, l = listeners.length; i < l; i++) { 1524 listeners[i](change); 1525 } 1526 untrackedEnd(prevU); 1527 } 1528 function asReference(value) { 1529 deprecated("asReference is deprecated, use observable.ref instead"); 1530 return observable.ref(value); 1531 } 1532 exports.asReference = asReference; 1533 function asStructure(value) { 1534 deprecated("asStructure is deprecated. Use observable.struct, computed.struct or reaction options instead."); 1535 return observable.struct(value); 1536 } 1537 exports.asStructure = asStructure; 1538 function asFlat(value) { 1539 deprecated("asFlat is deprecated, use observable.shallow instead"); 1540 return observable.shallow(value); 1541 } 1542 exports.asFlat = asFlat; 1543 function asMap(data) { 1544 deprecated("asMap is deprecated, use observable.map or observable.shallowMap instead"); 1545 return observable.map(data || {}); 1546 } 1547 exports.asMap = asMap; 1548 function isModifierDescriptor(thing) { 1549 return (typeof thing === "undefined" ? "undefined" : _typeof(thing)) === "object" && thing !== null && thing.isMobxModifierDescriptor === true; 1550 } 1551 exports.isModifierDescriptor = isModifierDescriptor; 1552 function createModifierDescriptor(enhancer, initialValue) { 1553 invariant(!isModifierDescriptor(initialValue), "Modifiers cannot be nested"); 1554 return { 1555 isMobxModifierDescriptor: true, 1556 initialValue: initialValue, 1557 enhancer: enhancer 1558 }; 1559 } 1560 function deepEnhancer(v, _, name) { 1561 if (isModifierDescriptor(v)) fail("You tried to assign a modifier wrapped value to a collection, please define modifiers when creating the collection, not when modifying it"); 1562 if (isObservable(v)) return v; 1563 if (Array.isArray(v)) return observable.array(v, name); 1564 if (isPlainObject(v)) return observable.object(v, name); 1565 if (isES6Map(v)) return observable.map(v, name); 1566 return v; 1567 } 1568 function shallowEnhancer(v, _, name) { 1569 if (isModifierDescriptor(v)) fail("You tried to assign a modifier wrapped value to a collection, please define modifiers when creating the collection, not when modifying it"); 1570 if (v === undefined || v === null) return v; 1571 if (isObservableObject(v) || isObservableArray(v) || isObservableMap(v)) return v; 1572 if (Array.isArray(v)) return observable.shallowArray(v, name); 1573 if (isPlainObject(v)) return observable.shallowObject(v, name); 1574 if (isES6Map(v)) return observable.shallowMap(v, name); 1575 return fail("The shallow modifier / decorator can only used in combination with arrays, objects and maps"); 1576 } 1577 function referenceEnhancer(newValue) { 1578 return newValue; 1579 } 1580 function deepStructEnhancer(v, oldValue, name) { 1581 if (deepEqual(v, oldValue)) return oldValue; 1582 if (isObservable(v)) return v; 1583 if (Array.isArray(v)) return new ObservableArray(v, deepStructEnhancer, name); 1584 if (isES6Map(v)) return new ObservableMap(v, deepStructEnhancer, name); 1585 if (isPlainObject(v)) { 1586 var res = {}; 1587 asObservableObject(res, name); 1588 extendObservableHelper(res, deepStructEnhancer, [v]); 1589 return res; 1590 } 1591 return v; 1592 } 1593 function refStructEnhancer(v, oldValue, name) { 1594 if (deepEqual(v, oldValue)) return oldValue; 1595 return v; 1596 } 1597 var MAX_SPLICE_SIZE = 10000; 1598 var safariPrototypeSetterInheritanceBug = function () { 1599 var v = false;
1600 var p = {}; 1601 Object.defineProperty(p, "0", { set: function set() { 1602 v = true; 1603 } }); 1604 Object.create(p)["0"] = 1; 1605 return v === false; 1606 }(); 1607 var OBSERVABLE_ARRAY_BUFFER_SIZE = 0; 1608 var StubArray = function () { 1609 function StubArray() {} 1610 return StubArray; 1611 }(); 1612 StubArray.prototype = []; 1613 var ObservableArrayAdministration = function () { 1614 function ObservableArrayAdministration(name, enhancer, array, owned) { 1615 this.array = array; 1616 this.owned = owned; 1617 this.lastKnownLength = 0; 1618 this.interceptors = null; 1619 this.changeListeners = null; 1620 this.atom = new BaseAtom(name || "ObservableArray@" + getNextId()); 1621 this.enhancer = function (newV, oldV) { 1622 return enhancer(newV, oldV, name + "[..]"); 1623 }; 1624 } 1625 ObservableArrayAdministration.prototype.intercept = function (handler) { 1626 return registerInterceptor(this, handler); 1627 }; 1628 ObservableArrayAdministration.prototype.observe = function (listener, fireImmediately) { 1629 if (fireImmediately === void 0) { 1630 fireImmediately = false; 1631 } 1632 if (fireImmediately) { 1633 listener({ 1634 object: this.array, 1635 type: "splice", 1636 index: 0, 1637 added: this.values.slice(), 1638 addedCount: this.values.length, 1639 removed: [], 1640 removedCount: 0 1641 }); 1642 } 1643 return registerListener(this, listener); 1644 }; 1645 ObservableArrayAdministration.prototype.getArrayLength = function () { 1646 this.atom.reportObserved(); 1647 return this.values.length; 1648 }; 1649 ObservableArrayAdministration.prototype.setArrayLength = function (newLength) { 1650 if (typeof newLength !== "number" || newLength < 0) throw new Error("[mobx.array] Out of range: " + newLength); 1651 var currentLength = this.values.length; 1652 if (newLength === currentLength) return;else if (newLength > currentLength) { 1653 var newItems = new Array(newLength - currentLength); 1654 for (var i = 0; i < newLength - currentLength; i++) { 1655 newItems[i] = undefined; 1656 }this.spliceWithArray(currentLength, 0, newItems); 1657 } else this.spliceWithArray(newLength, currentLength - newLength); 1658 }; 1659 ObservableArrayAdministration.prototype.updateArrayLength = function (oldLength, delta) { 1660 if (oldLength !== this.lastKnownLength) throw new Error("[mobx] Modification exception: the internal structure of an observable array was changed. Did you use peek() to change it?"); 1661 this.lastKnownLength += delta; 1662 if (delta > 0 && oldLength + delta + 1 > OBSERVABLE_ARRAY_BUFFER_SIZE) reserveArrayBuffer(oldLength + delta + 1); 1663 }; 1664 ObservableArrayAdministration.prototype.spliceWithArray = function (index, deleteCount, newItems) { 1665 var _this = this; 1666 checkIfStateModificationsAreAllowed(this.atom); 1667 var length = this.values.length; 1668 if (index === undefined) index = 0;else if (index > length) index = length;else if (index < 0) index = Math.max(0, length + index); 1669 if (arguments.length === 1) deleteCount = length - index;else if (deleteCount === undefined || deleteCount === null) deleteCount = 0;else deleteCount = Math.max(0, Math.min(deleteCount, length - index)); 1670 if (newItems === undefined) newItems = []; 1671 if (hasInterceptors(this)) { 1672 var change = interceptChange(this, { 1673 object: this.array, 1674 type: "splice", 1675 index: index, 1676 removedCount: deleteCount, 1677 added: newItems 1678 }); 1679 if (!change) return EMPTY_ARRAY; 1680 deleteCount = change.removedCount; 1681 newItems = change.added; 1682 } 1683 newItems = newItems.map(function (v) { 1684 return _this.enhancer(v, undefined); 1685 }); 1686 var lengthDelta = newItems.length - deleteCount;
1687 this.updateArrayLength(length, lengthDelta); 1688 var res = this.spliceItemsIntoValues(index, deleteCount, newItems); 1689 if (deleteCount !== 0 || newItems.length !== 0) this.notifyArraySplice(index, newItems, res); 1690 return res; 1691 }; 1692 ObservableArrayAdministration.prototype.spliceItemsIntoValues = function (index, deleteCount, newItems) { 1693 if (newItems.length < MAX_SPLICE_SIZE) { 1694 return (_a = this.values).splice.apply(_a, [index, deleteCount].concat(newItems)); 1695 } else { 1696 var res = this.values.slice(index, index + deleteCount); 1697 this.values = this.values.slice(0, index).concat(newItems, this.values.slice(index + deleteCount)); 1698 return res; 1699 } 1700 var _a; 1701 }; 1702 ObservableArrayAdministration.prototype.notifyArrayChildUpdate = function (index, newValue, oldValue) { 1703 var notifySpy = !this.owned && isSpyEnabled(); 1704 var notify = hasListeners(this); 1705 var change = notify || notifySpy ? { 1706 object: this.array, 1707 type: "update", 1708 index: index, newValue: newValue, oldValue: oldValue 1709 } : null; 1710 if (notifySpy) spyReportStart(change); 1711 this.atom.reportChanged(); 1712 if (notify) notifyListeners(this, change); 1713 if (notifySpy) spyReportEnd(); 1714 }; 1715 ObservableArrayAdministration.prototype.notifyArraySplice = function (index, added, removed) { 1716 var notifySpy = !this.owned && isSpyEnabled(); 1717 var notify = hasListeners(this); 1718 var change = notify || notifySpy ? { 1719 object: this.array, 1720 type: "splice", 1721 index: index, removed: removed, added: added, 1722 removedCount: removed.length, 1723 addedCount: added.length 1724 } : null; 1725 if (notifySpy) spyReportStart(change); 1726 this.atom.reportChanged(); 1727 if (notify) notifyListeners(this, change); 1728 if (notifySpy) spyReportEnd(); 1729 }; 1730 return ObservableArrayAdministration; 1731 }(); 1732 var ObservableArray = function (_super) { 1733 __extends(ObservableArray, _super); 1734 function ObservableArray(initialValues, enhancer, name, owned) { 1735 if (name === void 0) { 1736 name = "ObservableArray@" + getNextId(); 1737 } 1738 if (owned === void 0) { 1739 owned = false; 1740 } 1741 var _this = _super.call(this) || this; 1742 var adm = new ObservableArrayAdministration(name, enhancer, _this, owned); 1743 addHiddenFinalProp(_this, "$mobx", adm); 1744 if (initialValues && initialValues.length) { 1745 adm.updateArrayLength(0, initialValues.length); 1746 adm.values = initialValues.map(function (v) { 1747 return enhancer(v, undefined, name + "[..]"); 1748 }); 1749 adm.notifyArraySplice(0, adm.values.slice(), EMPTY_ARRAY); 1750 } else { 1751 adm.values = []; 1752 } 1753 if (safariPrototypeSetterInheritanceBug) { 1754 Object.defineProperty(adm.array, "0", ENTRY_0); 1755 } 1756 return _this; 1757 } 1758 ObservableArray.prototype.intercept = function (handler) { 1759 return this.$mobx.intercept(handler); 1760 }; 1761 ObservableArray.prototype.observe = function (listener, fireImmediately) { 1762 if (fireImmediately === void 0) { 1763 fireImmediately = false;
1764 } 1765 return this.$mobx.observe(listener, fireImmediately); 1766 }; 1767 ObservableArray.prototype.clear = function () { 1768 return this.splice(0); 1769 }; 1770 ObservableArray.prototype.concat = function () { 1771 var arrays = []; 1772 for (var _i = 0; _i < arguments.length; _i++) { 1773 arrays[_i] = arguments[_i]; 1774 } 1775 this.$mobx.atom.reportObserved(); 1776 return Array.prototype.concat.apply(this.peek(), arrays.map(function (a) { 1777 return isObservableArray(a) ? a.peek() : a; 1778 })); 1779 }; 1780 ObservableArray.prototype.replace = function (newItems) { 1781 return this.$mobx.spliceWithArray(0, this.$mobx.values.length, newItems); 1782 }; 1783 ObservableArray.prototype.toJS = function () { 1784 return this.slice(); 1785 }; 1786 ObservableArray.prototype.toJSON = function () { 1787 return this.toJS(); 1788 }; 1789 ObservableArray.prototype.peek = function () { 1790 return this.$mobx.values; 1791 }; 1792 ObservableArray.prototype.find = function (predicate, thisArg, fromIndex) { 1793 if (fromIndex === void 0) { 1794 fromIndex = 0; 1795 } 1796 this.$mobx.atom.reportObserved(); 1797 var items = this.$mobx.values, 1798 l = items.length; 1799 for (var i = fromIndex; i < l; i++) { 1800 if (predicate.call(thisArg, items[i], i, this)) return items[i]; 1801 }return undefined; 1802 }; 1803 ObservableArray.prototype.splice = function (index, deleteCount) { 1804 var newItems = []; 1805 for (var _i = 2; _i < arguments.length; _i++) { 1806 newItems[_i - 2] = arguments[_i]; 1807 } 1808 switch (arguments.length) { 1809 case 0: 1810 return []; 1811 case 1: 1812 return this.$mobx.spliceWithArray(index); 1813 case 2: 1814 return this.$mobx.spliceWithArray(index, deleteCount); 1815 } 1816 return this.$mobx.spliceWithArray(index, deleteCount, newItems); 1817 }; 1818 ObservableArray.prototype.spliceWithArray = function (index, deleteCount, newItems) { 1819 return this.$mobx.spliceWithArray(index, deleteCount, newItems); 1820 }; 1821 ObservableArray.prototype.push = function () { 1822 var items = []; 1823 for (var _i = 0; _i < arguments.length; _i++) { 1824 items[_i] = arguments[_i]; 1825 } 1826 var adm = this.$mobx; 1827 adm.spliceWithArray(adm.values.length, 0, items); 1828 return adm.values.length; 1829 }; 1830 ObservableArray.prototype.pop = function () { 1831 return this.splice(Math.max(this.$mobx.values.length - 1, 0), 1)[0]; 1832 }; 1833 ObservableArray.prototype.shift = function () { 1834 return this.splice(0, 1)[0]; 1835 }; 1836 ObservableArray.prototype.unshift = function () { 1837 var items = []; 1838 for (var _i = 0; _i < arguments.length; _i++) { 1839 items[_i] = arguments[_i]; 1840 } 1841 var adm = this.$mobx; 1842 adm.spliceWithArray(0, 0, items); 1843 return adm.values.length; 1844 }; 1845 ObservableArray.prototype.reverse = function () { 1846 this.$mobx.atom.reportObserved(); 1847 var clone = this.slice(); 1848 return clone.reverse.apply(clone, arguments); 1849 }; 1850 ObservableArray.prototype.sort = function (compareFn) { 1851 this.$mobx.atom.reportObserved(); 1852 var clone = this.slice(); 1853 return clone.sort.apply(clone, arguments); 1854 }; 1855 ObservableArray.prototype.remove = function (value) { 1856 var idx = this.$mobx.values.indexOf(value); 1857 if (idx > -1) { 1858 this.splice(idx, 1); 1859 return true; 1860 } 1861 return false;
1862 }; 1863 ObservableArray.prototype.move = function (fromIndex, toIndex) { 1864 function checkIndex(index) { 1865 if (index < 0) { 1866 throw new Error("[mobx.array] Index out of bounds: " + index + " is negative"); 1867 } 1868 var length = this.$mobx.values.length; 1869 if (index >= length) { 1870 throw new Error("[mobx.array] Index out of bounds: " + index + " is not smaller than " + length); 1871 } 1872 } 1873 checkIndex.call(this, fromIndex); 1874 checkIndex.call(this, toIndex); 1875 if (fromIndex === toIndex) { 1876 return; 1877 } 1878 var oldItems = this.$mobx.values; 1879 var newItems; 1880 if (fromIndex < toIndex) { 1881 newItems = oldItems.slice(0, fromIndex).concat(oldItems.slice(fromIndex + 1, toIndex + 1), [oldItems[fromIndex]], oldItems.slice(toIndex + 1)); 1882 } else { 1883 newItems = oldItems.slice(0, toIndex).concat([oldItems[fromIndex]], oldItems.slice(toIndex, fromIndex), oldItems.slice(fromIndex + 1)); 1884 } 1885 this.replace(newItems); 1886 }; 1887 ObservableArray.prototype.toString = function () { 1888 this.$mobx.atom.reportObserved(); 1889 return Array.prototype.toString.apply(this.$mobx.values, arguments); 1890 }; 1891 ObservableArray.prototype.toLocaleString = function () { 1892 this.$mobx.atom.reportObserved(); 1893 return Array.prototype.toLocaleString.apply(this.$mobx.values, arguments); 1894 }; 1895 return ObservableArray; 1896 }(StubArray); 1897 declareIterator(ObservableArray.prototype, function () { 1898 return arrayAsIterator(this.slice()); 1899 }); 1900 makeNonEnumerable(ObservableArray.prototype, ["constructor", "intercept", "observe", "clear", "concat", "replace", "toJS", "toJSON", "peek", "find", "splice", "spliceWithArray", "push", "pop", "shift", "unshift", "reverse", "sort", "remove", "move", "toString", "toLocaleString"]); 1901 Object.defineProperty(ObservableArray.prototype, "length", { 1902 enumerable: false, 1903 configurable: true, 1904 get: function get() { 1905 return this.$mobx.getArrayLength(); 1906 }, 1907 set: function set(newLength) { 1908 this.$mobx.setArrayLength(newLength); 1909 } 1910 }); 1911 ["every", "filter", "forEach", "indexOf", "join", "lastIndexOf", "map", "reduce", "reduceRight", "slice", "some"].forEach(function (funcName) { 1912 var baseFunc = Array.prototype[funcName]; 1913 invariant(typeof baseFunc === "function", "Base function not defined on Array prototype: '" + funcName + "'"); 1914 addHiddenProp(ObservableArray.prototype, funcName, function () { 1915 this.$mobx.atom.reportObserved(); 1916 return baseFunc.apply(this.$mobx.values, arguments); 1917 }); 1918 }); 1919 var ENTRY_0 = { 1920 configurable: true, 1921 enumerable: false, 1922 set: createArraySetter(0), 1923 get: createArrayGetter(0) 1924 }; 1925 function createArrayBufferItem(index) { 1926 var set = createArraySetter(index); 1927 var get = createArrayGetter(index); 1928 Object.defineProperty(ObservableArray.prototype, "" + index, { 1929 enumerable: false, 1930 configurable: true, 1931 set: set, get: get 1932 }); 1933 } 1934 function createArraySetter(index) { 1935 return function (newValue) { 1936 var adm = this.$mobx; 1937 var values = adm.values; 1938 if (index < values.length) { 1939 checkIfStateModificationsAreAllowed(adm.atom); 1940 var oldValue = values[index]; 1941 if (hasInterceptors(adm)) { 1942 var change = interceptChange(adm, { 1943 type: "update", 1944 object: adm.array, 1945 index: index, newValue: newValue 1946 }); 1947 if (!change) return; 1948 newValue = change.newValue; 1949 } 1950 newValue = adm.enhancer(newValue, oldValue); 1951 var changed = newValue !== oldValue; 1952 if (changed) { 1953 values[index] = newValue; 1954 adm.notifyArrayChildUpdate(index, newValue, oldValue); 1955 } 1956 } else if (index === values.length) { 1957 adm.spliceWithArray(index, 0, [newValue]); 1958 } else throw new Error("[mobx.array] Index out of bounds, " + index + " is larger than " + values.length); 1959 }; 1960 } 1961 function createArrayGetter(index) { 1962 return function () { 1963 var impl = this.$mobx; 1964 if (impl) { 1965 if (index < impl.values.length) { 1966 impl.atom.reportObserved(); 1967 return impl.values[index]; 1968 } 1969 console.warn("[mobx.array] Attempt to read an array index (" + index + ") that is out of bounds (" + impl.values.length + "). Please check length first. Out of bound indices will not be tracked by MobX"); 1970 } 1971 return undefined; 1972 }; 1973 } 1974 function reserveArrayBuffer(max) { 1975 for (var index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max; index++) { 1976 createArrayBufferItem(index); 1977 }OBSERVABLE_ARRAY_BUFFER_SIZE = max; 1978 } 1979 reserveArrayBuffer(1000);
1980 var isObservableArrayAdministration = createInstanceofPredicate("ObservableArrayAdministration", ObservableArrayAdministration); 1981 function isObservableArray(thing) { 1982 return isObject(thing) && isObservableArrayAdministration(thing.$mobx); 1983 } 1984 exports.isObservableArray = isObservableArray; 1985 var ObservableMapMarker = {}; 1986 var ObservableMap = function () { 1987 function ObservableMap(initialData, enhancer, name) { 1988 if (enhancer === void 0) { 1989 enhancer = deepEnhancer; 1990 } 1991 if (name === void 0) { 1992 name = "ObservableMap@" + getNextId(); 1993 } 1994 this.enhancer = enhancer; 1995 this.name = name; 1996 this.$mobx = ObservableMapMarker; 1997 this._data = {}; 1998 this._hasMap = {}; 1999 this._keys = new ObservableArray(undefined, referenceEnhancer, this.name + ".keys()", true); 2000 this.interceptors = null; 2001 this.changeListeners = null; 2002 this.merge(initialData); 2003 } 2004 ObservableMap.prototype._has = function (key) { 2005 return typeof this._data[key] !== "undefined"; 2006 }; 2007 ObservableMap.prototype.has = function (key) { 2008 if (!this.isValidKey(key)) return false; 2009 key = "" + key; 2010 if (this._hasMap[key]) return this._hasMap[key].get(); 2011 return this._updateHasMapEntry(key, false).get(); 2012 }; 2013 ObservableMap.prototype.set = function (key, value) { 2014 this.assertValidKey(key); 2015 key = "" + key; 2016 var hasKey = this._has(key); 2017 if (hasInterceptors(this)) { 2018 var change = interceptChange(this, { 2019 type: hasKey ? "update" : "add", 2020 object: this, 2021 newValue: value, 2022 name: key 2023 }); 2024 if (!change) return this; 2025 value = change.newValue; 2026 } 2027 if (hasKey) { 2028 this._updateValue(key, value); 2029 } else { 2030 this._addValue(key, value); 2031 } 2032 return this; 2033 }; 2034 ObservableMap.prototype.delete = function (key) { 2035 var _this = this; 2036 this.assertValidKey(key); 2037 key = "" + key; 2038 if (hasInterceptors(this)) { 2039 var change = interceptChange(this, { 2040 type: "delete", 2041 object: this, 2042 name: key 2043 }); 2044 if (!change) return false; 2045 } 2046 if (this._has(key)) { 2047 var notifySpy = isSpyEnabled(); 2048 var notify = hasListeners(this); 2049 var change = notify || notifySpy ? { 2050 type: "delete", 2051 object: this, 2052 oldValue: this._data[key].value, 2053 name: key 2054 } : null; 2055 if (notifySpy) spyReportStart(change); 2056 runInTransaction(function () { 2057 _this._keys.remove(key); 2058 _this._updateHasMapEntry(key, false); 2059 var observable = _this._data[key]; 2060 observable.setNewValue(undefined); 2061 _this._data[key] = undefined; 2062 }); 2063 if (notify) notifyListeners(this, change); 2064 if (notifySpy) spyReportEnd(); 2065 return true; 2066 } 2067 return false;
2068 }; 2069 ObservableMap.prototype._updateHasMapEntry = function (key, value) { 2070 var entry = this._hasMap[key]; 2071 if (entry) { 2072 entry.setNewValue(value); 2073 } else { 2074 entry = this._hasMap[key] = new ObservableValue(value, referenceEnhancer, this.name + "." + key + "?", false); 2075 } 2076 return entry; 2077 }; 2078 ObservableMap.prototype._updateValue = function (name, newValue) { 2079 var observable = this._data[name]; 2080 newValue = observable.prepareNewValue(newValue); 2081 if (newValue !== UNCHANGED) { 2082 var notifySpy = isSpyEnabled(); 2083 var notify = hasListeners(this); 2084 var change = notify || notifySpy ? { 2085 type: "update", 2086 object: this, 2087 oldValue: observable.value, 2088 name: name, newValue: newValue 2089 } : null; 2090 if (notifySpy) spyReportStart(change); 2091 observable.setNewValue(newValue); 2092 if (notify) notifyListeners(this, change); 2093 if (notifySpy) spyReportEnd(); 2094 } 2095 }; 2096 ObservableMap.prototype._addValue = function (name, newValue) { 2097 var _this = this; 2098 runInTransaction(function () { 2099 var observable = _this._data[name] = new ObservableValue(newValue, _this.enhancer, _this.name + "." + name, false); 2100 newValue = observable.value; 2101 _this._updateHasMapEntry(name, true); 2102 _this._keys.push(name); 2103 }); 2104 var notifySpy = isSpyEnabled(); 2105 var notify = hasListeners(this); 2106 var change = notify || notifySpy ? { 2107 type: "add", 2108 object: this, 2109 name: name, newValue: newValue 2110 } : null; 2111 if (notifySpy) spyReportStart(change); 2112 if (notify) notifyListeners(this, change); 2113 if (notifySpy) spyReportEnd(); 2114 }; 2115 ObservableMap.prototype.get = function (key) { 2116 key = "" + key; 2117 if (this.has(key)) return this._data[key].get(); 2118 return undefined; 2119 }; 2120 ObservableMap.prototype.keys = function () { 2121 return arrayAsIterator(this._keys.slice()); 2122 }; 2123 ObservableMap.prototype.values = function () { 2124 return arrayAsIterator(this._keys.map(this.get, this)); 2125 }; 2126 ObservableMap.prototype.entries = function () { 2127 var _this = this; 2128 return arrayAsIterator(this._keys.map(function (key) { 2129 return [key, _this.get(key)]; 2130 })); 2131 }; 2132 ObservableMap.prototype.forEach = function (callback, thisArg) { 2133 var _this = this; 2134 this.keys().forEach(function (key) { 2135 return callback.call(thisArg, _this.get(key), key, _this); 2136 }); 2137 }; 2138 ObservableMap.prototype.merge = function (other) { 2139 var _this = this; 2140 if (isObservableMap(other)) { 2141 other = other.toJS(); 2142 } 2143 runInTransaction(function () { 2144 if (isPlainObject(other)) Object.keys(other).forEach(function (key) { 2145 return _this.set(key, other[key]); 2146 });else if (Array.isArray(other)) other.forEach(function (_a) { 2147 var key = _a[0], 2148 value = _a[1]; 2149 return _this.set(key, value); 2150 });else if (isES6Map(other)) other.forEach(function (value, key) { 2151 return _this.set(key, value); 2152 });else if (other !== null && other !== undefined) fail("Cannot initialize map from " + other); 2153 }); 2154 return this; 2155 }; 2156 ObservableMap.prototype.clear = function () { 2157 var _this = this; 2158 runInTransaction(function () { 2159 untracked(function () {
2160 _this.keys().forEach(_this.delete, _this); 2161 }); 2162 }); 2163 }; 2164 ObservableMap.prototype.replace = function (values) { 2165 var _this = this; 2166 runInTransaction(function () { 2167 _this.clear(); 2168 _this.merge(values); 2169 }); 2170 return this; 2171 }; 2172 Object.defineProperty(ObservableMap.prototype, "size", { 2173 get: function get() { 2174 return this._keys.length; 2175 }, 2176 enumerable: true, 2177 configurable: true 2178 }); 2179 ObservableMap.prototype.toJS = function () { 2180 var _this = this; 2181 var res = {}; 2182 this.keys().forEach(function (key) { 2183 return res[key] = _this.get(key); 2184 }); 2185 return res; 2186 }; 2187 ObservableMap.prototype.toJSON = function () { 2188 return this.toJS(); 2189 }; 2190 ObservableMap.prototype.isValidKey = function (key) { 2191 if (key === null || key === undefined) return false; 2192 if (typeof key === "string" || typeof key === "number" || typeof key === "boolean") return true; 2193 return false; 2194 }; 2195 ObservableMap.prototype.assertValidKey = function (key) { 2196 if (!this.isValidKey(key)) throw new Error("[mobx.map] Invalid key: '" + key + "', only strings, numbers and booleans are accepted as key in observable maps."); 2197 }; 2198 ObservableMap.prototype.toString = function () { 2199 var _this = this; 2200 return this.name + "[{ " + this.keys().map(function (key) { 2201 return key + ": " + ("" + _this.get(key)); 2202 }).join(", ") + " }]"; 2203 }; 2204 ObservableMap.prototype.observe = function (listener, fireImmediately) { 2205 invariant(fireImmediately !== true, getMessage("m033")); 2206 return registerListener(this, listener); 2207 }; 2208 ObservableMap.prototype.intercept = function (handler) { 2209 return registerInterceptor(this, handler); 2210 }; 2211 return ObservableMap; 2212 }(); 2213 exports.ObservableMap = ObservableMap; 2214 declareIterator(ObservableMap.prototype, function () { 2215 return this.entries(); 2216 }); 2217 function map(initialValues) { 2218 deprecated("`mobx.map` is deprecated, use `new ObservableMap` or `mobx.observable.map` instead"); 2219 return observable.map(initialValues); 2220 } 2221 exports.map = map; 2222 var isObservableMap = createInstanceofPredicate("ObservableMap", ObservableMap); 2223 exports.isObservableMap = isObservableMap; 2224 var ObservableObjectAdministration = function () { 2225 function ObservableObjectAdministration(target, name) { 2226 this.target = target; 2227 this.name = name; 2228 this.values = {}; 2229 this.changeListeners = null; 2230 this.interceptors = null; 2231 } 2232 ObservableObjectAdministration.prototype.observe = function (callback, fireImmediately) { 2233 invariant(fireImmediately !== true, "`observe` doesn't support the fire immediately property for observable objects."); 2234 return registerListener(this, callback); 2235 }; 2236 ObservableObjectAdministration.prototype.intercept = function (handler) { 2237 return registerInterceptor(this, handler); 2238 }; 2239 return ObservableObjectAdministration; 2240 }(); 2241 function asObservableObject(target, name) { 2242 if (isObservableObject(target)) return target.$mobx; 2243 invariant(Object.isExtensible(target), getMessage("m035")); 2244 if (!isPlainObject(target)) name = (target.constructor.name || "ObservableObject") + "@" + getNextId(); 2245 if (!name) name = "ObservableObject@" + getNextId(); 2246 var adm = new ObservableObjectAdministration(target, name); 2247 addHiddenFinalProp(target, "$mobx", adm); 2248 return adm; 2249 } 2250 function defineObservablePropertyFromDescriptor(adm, propName, descriptor, defaultEnhancer) { 2251 if (adm.values[propName]) { 2252 invariant("value" in descriptor, "The property " + propName + " in " + adm.name + " is already observable, cannot redefine it as computed property"); 2253 adm.target[propName] = descriptor.value; 2254 return; 2255 } 2256 if ("value" in descriptor) { 2257 if (isModifierDescriptor(descriptor.value)) { 2258 var modifierDescriptor = descriptor.value; 2259 defineObservableProperty(adm, propName, modifierDescriptor.initialValue, modifierDescriptor.enhancer); 2260 } else if (isAction(descriptor.value) && descriptor.value.autoBind === true) { 2261 defineBoundAction(adm.target, propName, descriptor.value.originalFn); 2262 } else if (isComputedValue(descriptor.value)) { 2263 defineComputedPropertyFromComputedValue(adm, propName, descriptor.value); 2264 } else { 2265 defineObservableProperty(adm, propName, descriptor.value, defaultEnhancer); 2266 } 2267 } else { 2268 defineComputedProperty(adm, propName, descriptor.get, descriptor.set, false, true); 2269 } 2270 } 2271 function defineObservableProperty(adm, propName, newValue, enhancer) { 2272 assertPropertyConfigurable(adm.target, propName); 2273 if (hasInterceptors(adm)) { 2274 var change = interceptChange(adm, { 2275 object: adm.target, 2276 name: propName, 2277 type: "add", 2278 newValue: newValue 2279 }); 2280 if (!change) return; 2281 newValue = change.newValue; 2282 } 2283 var observable = adm.values[propName] = new ObservableValue(newValue, enhancer, adm.name + "." + propName, false); 2284 newValue = observable.value; 2285 Object.defineProperty(adm.target, propName, generateObservablePropConfig(propName)); 2286 notifyPropertyAddition(adm, adm.target, propName, newValue); 2287 } 2288 function defineComputedProperty(adm, propName, getter, setter, compareStructural, asInstanceProperty) { 2289 if (asInstanceProperty) assertPropertyConfigurable(adm.target, propName); 2290 adm.values[propName] = new ComputedValue(getter, adm.target, compareStructural, adm.name + "." + propName, setter); 2291 if (asInstanceProperty) { 2292 Object.defineProperty(adm.target, propName, generateComputedPropConfig(propName)); 2293 } 2294 } 2295 function defineComputedPropertyFromComputedValue(adm, propName, computedValue) { 2296 var name = adm.name + "." + propName; 2297 computedValue.name = name; 2298 if (!computedValue.scope) computedValue.scope = adm.target; 2299 adm.values[propName] = computedValue; 2300 Object.defineProperty(adm.target, propName, generateComputedPropConfig(propName)); 2301 } 2302 var observablePropertyConfigs = {}; 2303 var computedPropertyConfigs = {}; 2304 function generateObservablePropConfig(propName) {
2305 return observablePropertyConfigs[propName] || (observablePropertyConfigs[propName] = { 2306 configurable: true, 2307 enumerable: true, 2308 get: function get() { 2309 return this.$mobx.values[propName].get(); 2310 }, 2311 set: function set(v) { 2312 setPropertyValue(this, propName, v); 2313 } 2314 }); 2315 } 2316 function generateComputedPropConfig(propName) { 2317 return computedPropertyConfigs[propName] || (computedPropertyConfigs[propName] = { 2318 configurable: true, 2319 enumerable: false, 2320 get: function get() { 2321 return this.$mobx.values[propName].get(); 2322 }, 2323 set: function set(v) { 2324 return this.$mobx.values[propName].set(v); 2325 } 2326 }); 2327 } 2328 function setPropertyValue(instance, name, newValue) { 2329 var adm = instance.$mobx; 2330 var observable = adm.values[name]; 2331 if (hasInterceptors(adm)) { 2332 var change = interceptChange(adm, { 2333 type: "update", 2334 object: instance, 2335 name: name, newValue: newValue 2336 }); 2337 if (!change) return; 2338 newValue = change.newValue; 2339 } 2340 newValue = observable.prepareNewValue(newValue); 2341 if (newValue !== UNCHANGED) { 2342 var notify = hasListeners(adm); 2343 var notifySpy = isSpyEnabled(); 2344 var change = notify || notifySpy ? { 2345 type: "update", 2346 object: instance, 2347 oldValue: observable.value, 2348 name: name, newValue: newValue 2349 } : null; 2350 if (notifySpy) spyReportStart(change); 2351 observable.setNewValue(newValue); 2352 if (notify) notifyListeners(adm, change); 2353 if (notifySpy) spyReportEnd(); 2354 } 2355 } 2356 function notifyPropertyAddition(adm, object, name, newValue) { 2357 var notify = hasListeners(adm); 2358 var notifySpy = isSpyEnabled(); 2359 var change = notify || notifySpy ? { 2360 type: "add", 2361 object: object, name: name, newValue: newValue 2362 } : null; 2363 if (notifySpy) spyReportStart(change); 2364 if (notify) notifyListeners(adm, change); 2365 if (notifySpy) spyReportEnd(); 2366 } 2367 var isObservableObjectAdministration = createInstanceofPredicate("ObservableObjectAdministration", ObservableObjectAdministration); 2368 function isObservableObject(thing) { 2369 if (isObject(thing)) { 2370 runLazyInitializers(thing); 2371 return isObservableObjectAdministration(thing.$mobx); 2372 } 2373 return false; 2374 } 2375 exports.isObservableObject = isObservableObject; 2376 var UNCHANGED = {}; 2377 var ObservableValue = function (_super) { 2378 __extends(ObservableValue, _super); 2379 function ObservableValue(value, enhancer, name, notifySpy) { 2380 if (name === void 0) { 2381 name = "ObservableValue@" + getNextId(); 2382 } 2383 if (notifySpy === void 0) { 2384 notifySpy = true; 2385 } 2386 var _this = _super.call(this, name) || this; 2387 _this.enhancer = enhancer; 2388 _this.hasUnreportedChange = false; 2389 _this.value = enhancer(value, undefined, name); 2390 if (notifySpy && isSpyEnabled()) { 2391 spyReport({ type: "create", object: _this, newValue: _this.value }); 2392 } 2393 return _this; 2394 } 2395 ObservableValue.prototype.set = function (newValue) { 2396 var oldValue = this.value; 2397 newValue = this.prepareNewValue(newValue); 2398 if (newValue !== UNCHANGED) { 2399 var notifySpy = isSpyEnabled(); 2400 if (notifySpy) { 2401 spyReportStart({ 2402 type: "update", 2403 object: this, 2404 newValue: newValue, oldValue: oldValue 2405 }); 2406 } 2407 this.setNewValue(newValue); 2408 if (notifySpy) spyReportEnd(); 2409 } 2410 }; 2411 ObservableValue.prototype.prepareNewValue = function (newValue) { 2412 checkIfStateModificationsAreAllowed(this); 2413 if (hasInterceptors(this)) { 2414 var change = interceptChange(this, { object: this, type: "update", newValue: newValue }); 2415 if (!change) return UNCHANGED; 2416 newValue = change.newValue; 2417 } 2418 newValue = this.enhancer(newValue, this.value, this.name); 2419 return this.value !== newValue ? newValue : UNCHANGED; 2420 }; 2421 ObservableValue.prototype.setNewValue = function (newValue) { 2422 var oldValue = this.value; 2423 this.value = newValue; 2424 this.reportChanged(); 2425 if (hasListeners(this)) { 2426 notifyListeners(this, { 2427 type: "update", 2428 object: this, 2429 newValue: newValue, 2430 oldValue: oldValue 2431 }); 2432 } 2433 }; 2434 ObservableValue.prototype.get = function () { 2435 this.reportObserved(); 2436 return this.value; 2437 }; 2438 ObservableValue.prototype.intercept = function (handler) { 2439 return registerInterceptor(this, handler); 2440 }; 2441 ObservableValue.prototype.observe = function (listener, fireImmediately) { 2442 if (fireImmediately) listener({ 2443 object: this, 2444 type: "update", 2445 newValue: this.value, 2446 oldValue: undefined 2447 }); 2448 return registerListener(this, listener); 2449 }; 2450 ObservableValue.prototype.toJSON = function () { 2451 return this.get(); 2452 }; 2453 ObservableValue.prototype.toString = function () { 2454 return this.name + "[" + this.value + "]"; 2455 }; 2456 ObservableValue.prototype.valueOf = function () { 2457 return toPrimitive(this.get()); 2458 }; 2459 return ObservableValue; 2460 }(BaseAtom); 2461 ObservableValue.prototype[primitiveSymbol()] = ObservableValue.prototype.valueOf; 2462 var isObservableValue = createInstanceofPredicate("ObservableValue", ObservableValue); 2463 exports.isBoxedObservable = isObservableValue; 2464 function getAtom(thing, property) { 2465 if ((typeof thing === "undefined" ? "undefined" : _typeof(thing)) === "object" && thing !== null) { 2466 if (isObservableArray(thing)) { 2467 invariant(property === undefined, getMessage("m036")); 2468 return thing.$mobx.atom; 2469 } 2470 if (isObservableMap(thing)) { 2471 var anyThing = thing; 2472 if (property === undefined) return getAtom(anyThing._keys); 2473 var observable_2 = anyThing._data[property] || anyThing._hasMap[property]; 2474 invariant(!!observable_2, "the entry '" + property + "' does not exist in the observable map '" + getDebugName(thing) + "'"); 2475 return observable_2; 2476 }
2477 runLazyInitializers(thing); 2478 if (isObservableObject(thing)) { 2479 if (!property) return fail("please specify a property"); 2480 var observable_3 = thing.$mobx.values[property]; 2481 invariant(!!observable_3, "no observable property '" + property + "' found on the observable object '" + getDebugName(thing) + "'"); 2482 return observable_3; 2483 } 2484 if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) { 2485 return thing; 2486 } 2487 } else if (typeof thing === "function") { 2488 if (isReaction(thing.$mobx)) { 2489 return thing.$mobx; 2490 } 2491 } 2492 return fail("Cannot obtain atom from " + thing); 2493 } 2494 function getAdministration(thing, property) { 2495 invariant(thing, "Expecting some object"); 2496 if (property !== undefined) return getAdministration(getAtom(thing, property)); 2497 if (isAtom(thing) || isComputedValue(thing) || isReaction(thing)) return thing; 2498 if (isObservableMap(thing)) return thing; 2499 runLazyInitializers(thing); 2500 if (thing.$mobx) return thing.$mobx; 2501 invariant(false, "Cannot obtain administration from " + thing); 2502 } 2503 function getDebugName(thing, property) { 2504 var named; 2505 if (property !== undefined) named = getAtom(thing, property);else if (isObservableObject(thing) || isObservableMap(thing)) named = getAdministration(thing);else named = getAtom(thing); 2506 return named.name; 2507 } 2508 function createClassPropertyDecorator(onInitialize, _get, _set, enumerable, allowCustomArguments) { 2509 function classPropertyDecorator(target, key, descriptor, customArgs, argLen) { 2510 if (argLen === void 0) { 2511 argLen = 0; 2512 } 2513 invariant(allowCustomArguments || quacksLikeADecorator(arguments), "This function is a decorator, but it wasn't invoked like a decorator"); 2514 if (!descriptor) { 2515 var newDescriptor = { 2516 enumerable: enumerable, 2517 configurable: true, 2518 get: function get() { 2519 if (!this.__mobxInitializedProps || this.__mobxInitializedProps[key] !== true) typescriptInitializeProperty(this, key, undefined, onInitialize, customArgs, descriptor); 2520 return _get.call(this, key); 2521 }, 2522 set: function set(v) { 2523 if (!this.__mobxInitializedProps || this.__mobxInitializedProps[key] !== true) { 2524 typescriptInitializeProperty(this, key, v, onInitialize, customArgs, descriptor); 2525 } else { 2526 _set.call(this, key, v); 2527 } 2528 } 2529 }; 2530 if (arguments.length < 3 || arguments.length === 5 && argLen < 3) { 2531 Object.defineProperty(target, key, newDescriptor); 2532 } 2533 return newDescriptor; 2534 } else { 2535 if (!hasOwnProperty(target, "__mobxLazyInitializers")) { 2536 addHiddenProp(target, "__mobxLazyInitializers", target.__mobxLazyInitializers && target.__mobxLazyInitializers.slice() || []); 2537 } 2538 var value_1 = descriptor.value, 2539 initializer_1 = descriptor.initializer; 2540 target.__mobxLazyInitializers.push(function (instance) { 2541 onInitialize(instance, key, initializer_1 ? initializer_1.call(instance) : value_1, customArgs, descriptor); 2542 }); 2543 return { 2544 enumerable: enumerable, configurable: true, 2545 get: function get() { 2546 if (this.__mobxDidRunLazyInitializer
2546s !== true) runLazyInitializers(this); 2547 return _get.call(this, key); 2548 }, 2549 set: function set(v) { 2550 if (this.__mobxDidRunLazyInitializers !== true) runLazyInitializers(this); 2551 _set.call(this, key, v); 2552 } 2553 }; 2554 } 2555 } 2556 if (allowCustomArguments) { 2557 return function () { 2558 if (quacksLikeADecorator(arguments)) return classPropertyDecorator.apply(null, arguments); 2559 var outerArgs = arguments; 2560 var argLen = arguments.length; 2561 return function (target, key, descriptor) { 2562 return classPropertyDecorator(target, key, descriptor, outerArgs, argLen); 2563 }; 2564 }; 2565 } 2566 return classPropertyDecorator; 2567 } 2568 function typescriptInitializeProperty(instance, key, v, onInitialize, customArgs, baseDescriptor) { 2569 if (!hasOwnProperty(instance, "__mobxInitializedProps")) addHiddenProp(instance, "__mobxInitializedProps", {}); 2570 instance.__mobxInitializedProps[key] = true; 2571 onInitialize(instance, key, v, customArgs, baseDescriptor); 2572 } 2573 function runLazyInitializers(instance) { 2574 if (instance.__mobxDidRunLazyInitializers === true) return; 2575 if (instance.__mobxLazyInitializers) { 2576 addHiddenProp(instance, "__mobxDidRunLazyInitializers", true); 2577 instance.__mobxDidRunLazyInitializers && instance.__mobxLazyInitializers.forEach(function (initializer) { 2578 return initializer(instance); 2579 }); 2580 } 2581 } 2582 function quacksLikeADecorator(args) { 2583 return (args.length === 2 || args.length === 3) && typeof args[1] === "string"; 2584 } 2585 function iteratorSymbol() { 2586 return typeof Symbol === "function" && Symbol.iterator || "@@iterator"; 2587 } 2588 var IS_ITERATING_MARKER = "__$$iterating"; 2589 function arrayAsIterator(array) { 2590 invariant(array[IS_ITERATING_MARKER] !== true, "Illegal state: cannot recycle array as iterator"); 2591 addHiddenFinalProp(array, IS_ITERATING_MARKER, true); 2592 var idx = -1; 2593 addHiddenFinalProp(array, "next", function next() { 2594 idx++; 2595 return { 2596 done: idx >= this.length, 2597 value: idx < this.length ? this[idx] : undefined 2598 }; 2599 }); 2600 return array; 2601 } 2602 function declareIterator(prototType, iteratorFactory) { 2603 addHiddenFinalProp(prototType, iteratorSymbol(), iteratorFactory); 2604 } 2605 var messages = { 2606 "m001": "It is not allowed to assign new values to @action fields", 2607 "m002": "`runInAction` expects a function", 2608 "m003": "`runInAction` expects a function without arguments", 2609 "m004": "autorun expects a function", 2610 "m005": "Warning: attempted to pass an action to autorun. Actions are untracked and will not trigger on state changes. Use `reaction` or wrap only your state modification code in an action.", 2611 "m006": "Warning: attempted to pass an action to autorunAsync. Actions are untracked and will not trigger on state changes. Use `reaction` or wrap only your state modification code in an action.", 2612 "m007": "reaction only accepts 2 or 3 arguments. If migrating from MobX 2, please provide an options object", 2613 "m008": "wrapping reaction expression in `asReference` is no longer supported, use options object instead", 2614 "m009": "@computed can only be used on getter functions, like: '@computed get myProps() { return ...; }'. It looks like it was used on a property.", 2615 "m010": "@computed can only be used on getter functions, like: '@computed get myProps() { return ...; }'", 2616 "m011": "First argument to `computed` should be an expression. If using computed as decorator, don't pass it arguments",
2617 "m012": "computed takes one or two arguments if used as function", 2618 "m013": "[mobx.expr] 'expr' should only be used inside other reactive functions.", 2619 "m014": "extendObservable expected 2 or more arguments", 2620 "m015": "extendObservable expects an object as first argument", 2621 "m016": "extendObservable should not be used on maps, use map.merge instead", 2622 "m017": "all arguments of extendObservable should be objects", 2623 "m018": "extending an object with another observable (object) is not supported. Please construct an explicit propertymap, using `toJS` if need. See issue #540", 2624 "m019": "[mobx.isObservable] isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.", 2625 "m020": "modifiers can only be used for individual object properties", 2626 "m021": "observable expects zero or one arguments", 2627 "m022": "@observable can not be used on getters, use @computed instead", 2628 "m023": "Using `transaction` is deprecated, use `runInAction` or `(@)action` instead.", 2629 "m024": "whyRun() can only be used if a derivation is active, or by passing an computed value / reaction explicitly. If you invoked whyRun from inside a computation; the computation is currently suspended but re-evaluating because somebody requested its value.", 2630 "m025": "whyRun can only be used on reactions and computed values", 2631 "m026": "`action` can only be invoked on functions", 2632 "m028": "It is not allowed to set `useStrict` when a derivation is running", 2633 "m029": "INTERNAL ERROR only onBecomeUnobserved shouldn't be called twice in a row", 2634 "m030a": "Since strict-mode is enabled, changing observed observable values outside actions is not allowed. Please wrap the code in an `action` if this change is intended. Tried to modify: ", 2635 "m030b": "Side effects like changing state are not allowed at this point. Are you trying to modify state from, for example, the render function of a React component? Tried to modify: ", 2636 "m031": "Computed values are not allowed to not cause side effects by changing observables that are already being observed. Tried to modify: ", 2637 "m032": "* This computation is suspended (not in use by any reaction) and won't run automatically.\n Didn't expect this computation to be suspended at this point?\n 1. Make sure this computation is used by a reaction (reaction, autorun, observer).\n 2. Check whether you are using this computation synchronously (in the same stack as they reaction that needs it).", 2638 "m033": "`observe` doesn't support the fire immediately property for observable maps.", 2639 "m034": "`mobx.map` is deprecated, use `new ObservableMap` or `mobx.observable.map` instead", 2640 "m035": "Cannot make the designated object observable; it is not extensible", 2641 "m036": "It is not possible to get index atoms from arrays", 2642 "m037": "Hi there! I'm sorry you have just run into an exception.\nIf your debugger ends up here, know that some reaction (like the render() of an observer component, autorun or reaction)\nthrew an exception and that mobx caught it, to avoid that it brings the rest of your application down.\nThe original cause of the exception (the code that caused this reaction to run (again)), is still in the stack.\n\nHowever, more interesting is the actual stack trace of the error itself.\nHopefully the error is an instanceof Error, because in that case you can inspect the original stack of the error from where it was thrown.\nSee `error.stack` property, or press the very subtle \"(...)\" link you see near the console.error message that probably brought you here.\nThat stack is more interesting than the stack of this console.error itself.\n\nIf the exception you see is an exception you created yourself, make sure to use `throw new Error(\"Oops\")` instead of `throw \"Oops\"`,\nbecause the javascript environment will only preserve the original stack trace in the first form.\n\nYou can also make sure the debugger pauses the next time this very same exception is thrown by enabling \"Pause on caught exception\".\n(Note that it might pause on many other, unrelated exception as well).\n\nIf that all doesn't help you out, feel free to open an issue https://github.com/mobxjs/mobx/issues!\n", 2643 "m038": "Missing items in this list?\n 1. Check whether all used values are properly marked as observable (use isObservable to verify)\n 2. Make sure you didn't dereference values too early. MobX observes props, not primitives. E.g: use 'person.name' instead of 'name' in your computation.\n" 2644 };
2645 function getMessage(id) { 2646 return messages[id]; 2647 } 2648 var EMPTY_ARRAY = []; 2649 Object.freeze(EMPTY_ARRAY); 2650 function getGlobal() { 2651 return global; 2652 } 2653 function getNextId() { 2654 return ++globalState.mobxGuid; 2655 } 2656 function fail(message, thing) { 2657 invariant(false, message, thing); 2658 throw "X"; 2659 } 2660 function invariant(check, message, thing) { 2661 if (!check) throw new Error("[mobx] Invariant failed: " + message + (thing ? " in '" + thing + "'" : "")); 2662 } 2663 var deprecatedMessages = []; 2664 function deprecated(msg) { 2665 if (deprecatedMessages.indexOf(msg) !== -1) return false; 2666 deprecatedMessages.push(msg); 2667 console.error("[mobx] Deprecated: " + msg); 2668 return true; 2669 } 2670 function once(func) { 2671 var invoked = false; 2672 return function () { 2673 if (invoked) return; 2674 invoked = true; 2675 return func.apply(this, arguments); 2676 }; 2677 } 2678 var noop = function noop() {}; 2679 function unique(list) { 2680 var res = []; 2681 list.forEach(function (item) { 2682 if (res.indexOf(item) === -1) res.push(item); 2683 }); 2684 return res; 2685 } 2686 function joinStrings(things, limit, separator) { 2687 if (limit === void 0) { 2688 limit = 100; 2689 } 2690 if (separator === void 0) { 2691 separator = " - "; 2692 } 2693 if (!things) return ""; 2694 var sliced = things.slice(0, limit); 2695 return "" + sliced.join(separator) + (things.length > limit ? " (... and " + (things.length - limit) + "more)" : ""); 2696 } 2697 function isObject(value) { 2698 return value !== null && (typeof value === "undefined" ? "undefined" : _typeof(value)) === "object"; 2699 } 2700 function isPlainObject(value) { 2701 if (value === null || (typeof value === "undefined" ? "undefined" : _typeof(value)) !== "object") return false; 2702 var proto = Object.getPrototypeOf(value); 2703 return proto === Object.prototype || proto === null; 2704 } 2705 function objectAssign() { 2706 var res = arguments[0]; 2707 for (var i = 1, l = arguments.length; i < l; i++) { 2708 var source = arguments[i]; 2709 for (var key in source) { 2710 if (hasOwnProperty(source, key)) { 2711 res[key] = source[key]; 2712 } 2713 } 2714 } 2715 return res; 2716 } 2717 function valueDidChange(compareStructural, oldValue, newValue) { 2718 if (typeof oldValue === 'number' && isNaN(oldValue)) { 2719 return typeof newValue !== 'number' || !isNaN(newValue); 2720 } 2721 return compareStructural ? !deepEqual(oldValue, newValue) : oldValue !== newValue; 2722 } 2723 var prototypeHasOwnProperty = Object.prototype.hasOwnProperty; 2724 function hasOwnProperty(object, propName) { 2725 return prototypeHasOwnProperty.call(object, propName); 2726 } 2727 function makeNonEnumerable(object, propNames) { 2728 for (var i = 0; i < propNames.length; i++) { 2729 addHiddenProp(object, propNames[i], object[propNames[i]]); 2730 } 2731 } 2732 function addHiddenProp(object, propName, value) { 2733 Object.defineProperty(object, propName, { 2734 enumerable: false, 2735 writable: true, 2736 configurable: true, 2737 value: value 2738 }); 2739 } 2740 function addHiddenFinalProp(object, propName, value) { 2741 Object.defineProperty(object, propName, { 2742 enumerable: false, 2743 writable: false, 2744 configurable: true, 2745 value: value 2746 }); 2747 } 2748 function isPropertyConfigurable(object, prop) { 2749 var descriptor = Object.getOwnPropertyDescriptor(object, prop); 2750 return !descriptor || descriptor.configurable !== false && descriptor.writable !== false; 2751 } 2752 function assertPropertyConfigurable(object, prop) { 2753 invariant(isPropertyConfigurable(object, prop), "Cannot make property '" + prop + "' observable, it is not configurable and writable in the target object"); 2754 } 2755 function getEnumerableKeys(obj) { 2756 var res = []; 2757 for (var key in obj) { 2758 res.push(key); 2759 }return res; 2760 } 2761 function deepEqual(a, b) { 2762 if (a === null && b === null) return true; 2763 if (a === undefined && b === undefined) return true; 2764 if ((typeof a === "undefined" ? "undefined" : _typeof(a)) !== "object") return a === b; 2765 var aIsArray = isArrayLike(a); 2766 var aIsMap = isMapLike(a); 2767 if (aIsArray !== isArrayLike(b)) { 2768 return false;
2769 } else if (aIsMap !== isMapLike(b)) { 2770 return false; 2771 } else if (aIsArray) { 2772 if (a.length !== b.length) return false; 2773 for (var i = a.length - 1; i >= 0; i--) { 2774 if (!deepEqual(a[i], b[i])) return false; 2775 }return true; 2776 } else if (aIsMap) { 2777 if (a.size !== b.size) return false; 2778 var equals_1 = true; 2779 a.forEach(function (value, key) { 2780 equals_1 = equals_1 && deepEqual(b.get(key), value); 2781 }); 2782 return equals_1; 2783 } else if ((typeof a === "undefined" ? "undefined" : _typeof(a)) === "object" && (typeof b === "undefined" ? "undefined" : _typeof(b)) === "object") { 2784 if (a === null || b === null) return false; 2785 if (isMapLike(a) && isMapLike(b)) { 2786 if (a.size !== b.size) return false; 2787 return deepEqual(observable.shallowMap(a).entries(), observable.shallowMap(b).entries()); 2788 } 2789 if (getEnumerableKeys(a).length !== getEnumerableKeys(b).length) return false; 2790 for (var prop in a) { 2791 if (!(prop in b)) return false; 2792 if (!deepEqual(a[prop], b[prop])) return false; 2793 } 2794 return true; 2795 } 2796 return false; 2797 } 2798 function createInstanceofPredicate(name, clazz) { 2799 var propName = "isMobX" + name; 2800 clazz.prototype[propName] = true; 2801 return function (x) { 2802 return isObject(x) && x[propName] === true; 2803 }; 2804 } 2805 function isArrayLike(x) { 2806 return Array.isArray(x) || isObservableArray(x); 2807 } 2808 exports.isArrayLike = isArrayLike; 2809 function isMapLike(x) { 2810 return isES6Map(x) || isObservableMap(x); 2811 } 2812 function isES6Map(thing) { 2813 if (getGlobal().Map !== undefined && thing instanceof getGlobal().Map) return true; 2814 return false; 2815 } 2816 function primitiveSymbol() { 2817 return typeof Symbol === "function" && Symbol.toPrimitive || "@@toPrimitive"; 2818 } 2819 function toPrimitive(value) { 2820 return value === null ? null : (typeof value === "undefined" ? "undefined" : _typeof(value)) === "object" ? "" + value : value; 2821 } 2822 /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4))) 2823 2824 /***/ }), 2825 /* 2 */ 2826 /***/ (function(module, exports, __webpack_require__) { 2827 2828 "use strict"; 2829 2830 2831 Object.defineProperty(exports, "__esModule", { 2832 value: true 2833 }); 2834 2835 var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); 2836 2837 var _icons = __webpack_require__(6); 2838 2839 var _constants = __webpack_require__(0); 2840 2841 function renderHeader(_ref, instance) { 2842 var meta = _ref.meta, 2843 user = _ref.user, 2844 reactions = _ref.reactions; 2845 2846 var container = document.createElement('div'); 2847 container.lang = "en-US"; 2848 container.className = 'gitment-container gitment-header-container'; 2849 2850 var likeButton = document.createElement('span'); 2851 var likedReaction = reactions.find(function (reaction) { 2852 return reaction.content === 'heart' && reaction.user.login === user.login; 2853 }); 2854 likeButton.className = 'gitment-header-like-btn'; 2855 likeButton.innerHTML = '\n ' + _icons.heart + '\n ' + (likedReaction ? 'Unlike' : 'Like') + '\n ' + (meta.reactions && meta.reactions.heart ? ' \u2022 <strong>' + meta.reactions.heart + '</strong> Liked' : '') + '\n '; 2856 2857 if (likedReaction) { 2858 likeButton.classList.add('liked'); 2859 likeButton.onclick = function () { 2860 return instance.unlike(); 2861 }; 2862 } else { 2863 likeButton.classList.remove('liked'); 2864 likeButton.onclick = function () { 2865 return instance.like(); 2866 }; 2867 } 2868 container.appendChild(likeButton); 2869 2870 var commentsCount = document.createElement('span'); 2871 commentsCount.innerHTML = '\n ' + (meta.comments ? ' \u2022 <strong>' + meta.comments + '</strong> Comments' : '') + '\n '; 2872 container.appendChild(commentsCount); 2873 2874 var issueLink = document.createElement('a'); 2875 issueLink.className = 'gitment-header-issue-link'; 2876 issueLink.href = meta.html_url; 2877 issueLink.target = '_blank'; 2878 issueLink.innerText = 'Issue Page'; 2879 container.appendChild(issueLink); 2880 2881 return container; 2882 } 2883 2884 function renderComments(_ref2, instance) { 2885 var meta = _ref2.meta, 2886 comments = _ref2.comments, 2887 commentReactions = _ref2.commentReactions, 2888 currentPage = _ref2.currentPage, 2889 user = _ref2.user, 2890 error = _ref2.error; 2891 2892 var container = document.createElement('div'); 2893 container.lang = "en-US"; 2894 container.className = 'gitment-container gitment-comments-container'; 2895 2896 if (error) { 2897 var errorBlock = document.createElement('div'); 2898 errorBlock.className = 'gitment-comments-error'; 2899 2900 if (error === _constants.NOT_INITIALIZED_ERROR && user.login && user.login.toLowerCase() === instance.owner.toLowerCase()) { 2901 var initHint = document.createElement('div'); 2902 var initButton = document.createElement('button'); 2903 initButton.className = 'gitment-comments-init-btn'; 2904 initButton.onclick = function () { 2905 initButton.setAttribute('disabled', true); 2906 instance.init().catch(function (e) { 2907 initButton.removeAttribute('disabled'); 2908 alert(e); 2909 }); 2910 }; 2911 initButton.innerText = 'Initialize Comments'; 2912 initHint.appendChild(initButton); 2913 errorBlock.appendChild(initHint); 2914 } else { 2915 errorBlock.innerText = error; 2916 } 2917 container.appendChild(errorBlock); 2918 return container; 2919 } else if (comments === undefined) { 2920 var loading = document.createElement('div'); 2921 loading.innerText = 'Loading comments...'; 2922 loading.className = 'gitment-comments-loading'; 2923 container.appendChild(loading); 2924 return container; 2925 } else if (!comments.length) { 2926 var emptyBlock = document.createElement('div'); 2927 emptyBlock.className = 'gitment-comments-empty'; 2928 emptyBlock.innerText = 'No Comment Yet'; 2929 container.appendChild(emptyBlock); 2930 return container; 2931 } 2932 2933 var commentsList = document.createElement('ul'); 2934 commentsList.className = 'gitment-comments-list'; 2935
2936 comments.forEach(function (comment) { 2937 var createDate = new Date(comment.created_at); 2938 var updateDate = new Date(comment.updated_at); 2939 var commentItem = document.createElement('li'); 2940 commentItem.className = 'gitment-comment'; 2941 commentItem.innerHTML = '\n <a class="gitment-comment-avatar" href="' + comment.user.html_url + '" target="_blank">\n <img class="gitment-comment-avatar-img" src="' + comment.user.avatar_url + '"/>\n </a>\n <div class="gitment-comment-main">\n <div class="gitment-comment-header">\n <a class="gitment-comment-name" href="' + comment.user.html_url + '" target="_blank">\n ' + comment.user.login + '\n </a>\n commented on\n <span title="' + createDate + '">' + createDate.toDateString() + '</span>\n ' + (createDate.toString() !== updateDate.toString() ? ' \u2022 <span title="comment was edited at ' + updateDate + '">edited</span>' : '') + '\n <div class="gitment-comment-like-btn">' + _icons.heart + ' ' + (comment.reactions.heart || '') + '</div>\n </div>\n <div class="gitment-comment-body gitment-markdown">' + comment.body_html + '</div>\n </div>\n '; 2942 var likeButton = commentItem.querySelector('.gitment-comment-like-btn'); 2943 var likedReaction = commentReactions[comment.id] && commentReactions[comment.id].find(function (reaction) { 2944 return reaction.content === 'heart' && reaction.user.login === user.login; 2945 }); 2946 if (likedReaction) { 2947 likeButton.classList.add('liked'); 2948 likeButton.onclick = function () { 2949 return instance.unlikeAComment(comment.id); 2950 }; 2951 } else { 2952 likeButton.classList.remove('liked'); 2953 likeButton.onclick = function () { 2954 return instance.likeAComment(comment.id); 2955 }; 2956 } 2957 2958 // dirty 2959 // use a blank image to trigger height calculating when element rendered 2960 var imgTrigger = document.createElement('img'); 2961 var markdownBody = commentItem.querySelector('.gitment-comment-body'); 2962 imgTrigger.className = 'gitment-hidden'; 2963 imgTrigger.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; 2964 imgTrigger.onload = function () { 2965 if (markdownBody.clientHeight > instance.maxCommentHeight) { 2966 markdownBody.classList.add('gitment-comment-body-folded'); 2967 markdownBody.style.maxHeight = instance.maxCommentHeight + 'px'; 2968 markdownBody.title = 'Click to Expand'; 2969 markdownBody.onclick = function () { 2970 markdownBody.classList.remove('gitment-comment-body-folded'); 2971 markdownBody.style.maxHeight = ''; 2972 markdownBody.title = ''; 2973 markdownBody.onclick = null; 2974 }; 2975 } 2976 }; 2977 commentItem.appendChild(imgTrigger); 2978 2979 commentsList.appendChild(commentItem); 2980 }); 2981 2982 container.appendChild(commentsList); 2983 2984 if (meta) { 2985 var pageCount = Math.ceil(meta.comments / instance.perPage); 2986 if (pageCount > 1) { 2987 var pagination = document.createElement('ul'); 2988 pagination.className = 'gitment-comments-pagination'; 2989 2990 if (currentPage > 1) { 2991 var previousButton = document.createElement('li'); 2992 previousButton.className = 'gitment-comments-page-item'; 2993 previousButton.innerText = 'Previous'; 2994 previousButton.onclick = function () { 2995 return instance.goto(currentPage - 1); 2996 }; 2997 pagination.appendChild(previousButton); 2998 } 2999 3000 var _loop = function _loop(i) { 3001 var pageItem = document.createElement('li'); 3002 pageItem.className = 'gitment-comments-page-item';
3003 pageItem.innerText = i; 3004 pageItem.onclick = function () { 3005 return instance.goto(i); 3006 }; 3007 if (currentPage === i) pageItem.classList.add('gitment-selected'); 3008 pagination.appendChild(pageItem); 3009 }; 3010 3011 for (var i = 1; i <= pageCount; i++) { 3012 _loop(i); 3013 } 3014 3015 if (currentPage < pageCount) { 3016 var nextButton = document.createElement('li'); 3017 nextButton.className = 'gitment-comments-page-item'; 3018 nextButton.innerText = 'Next'; 3019 nextButton.onclick = function () { 3020 return instance.goto(currentPage + 1); 3021 }; 3022 pagination.appendChild(nextButton); 3023 } 3024 3025 container.appendChild(pagination); 3026 } 3027 } 3028 3029 return container; 3030 } 3031 3032 function renderEditor(_ref3, instance) { 3033 var user = _ref3.user, 3034 error = _ref3.error; 3035 3036 var container = document.createElement('div'); 3037 container.lang = "en-US"; 3038 container.className = 'gitment-container gitment-editor-container'; 3039 3040 var shouldDisable = user.login && !error ? '' : 'disabled'; 3041 var disabledTip = user.login ? '' : 'Login to Comment'; 3042 container.innerHTML = '\n ' + (user.login ? '<a class="gitment-editor-avatar" href="' + user.html_url + '" target="_blank">\n <img class="gitment-editor-avatar-img" src="' + user.avatar_url + '"/>\n </a>' : user.isLoggingIn ? '<div class="gitment-editor-avatar">' + _icons.spinner + '</div>' : '<a class="gitment-editor-avatar" href="' + instance.loginLink + '" title="login with GitHub">\n ' + _icons.github + '\n </a>') + '\n </a>\n <div class="gitment-editor-main">\n <div class="gitment-editor-header">\n <nav class="gitment-editor-tabs">\n <button class="gitment-editor-tab gitment-selected">Write</button>\n <button class="gitment-editor-tab">Preview</button>\n </nav>\n <div class="gitment-editor-login">\n ' + (user.login ? '<a class="gitment-editor-logout-link">Logout</a>' : user.isLoggingIn ? 'Logging in...' : '<a class="gitment-editor-login-link" href="' + instance.loginLink + '">Login</a> with GitHub') + '\n </div>\n </div>\n <div class="gitment-editor-body">\n <div class="gitment-editor-write-field">\n <textarea placeholder="Leave a comment" title="' + disabledTip + '" ' + shouldDisable + '></textarea>\n </div>\n <div class="gitment-editor-preview-field gitment-hidden">\n <div class="gitment-editor-preview gitment-markdown"></div>\n </div>\n </div>\n </div>\n <div class="gitment-editor-footer">\n <a class="gitment-editor-footer-tip" href="https://guides.github.com/features/mastering-markdown/" target="_blank">\n Styling with Markdown is supported\n </a>\n <button class="gitment-editor-submit" title="' + disabledTip + '" ' + shouldDisable + '>Comment</button>\n </div>\n '; 3043 if (user.login) { 3044 container.querySelector('.gitment-editor-logout-link').onclick = function () { 3045 return instance.logout(); 3046 }; 3047 } 3048 3049 var writeField = container.querySelector('.gitment-editor-write-field'); 3050 var previewField = container.querySelector('.gitment-editor-preview-field'); 3051 3052 var textarea = writeField.querySelector('textarea'); 3053 textarea.oninput = function () { 3054 textarea.style.height = 'auto'; 3055 var style = window.getComputedStyle(textarea, null); 3056 var height = parseInt(style.height, 10); 3057 var clientHeight = textarea.clientHeight; 3058 var scrollHeight = textarea.scrollHeight; 3059 if (clientHeight < scrollHeight) { 3060 textarea.style.height = height + scrollHeight - clientHeight + 'px'; 3061 } 3062 }; 3063 3064 var _container$querySelec = container.querySelectorAll('.gitment-editor-tab'), 3065 _container$querySelec2 = _slicedToArray(_container$querySelec, 2), 3066 writeTab = _container$querySelec2[0], 3067 previewTab = _container$querySelec2[1]; 3068 3069 writeTab.onclick = function () { 3070 writeTab.classList.add('gitment-selected'); 3071 previewTab.classList.remove('gitment-selected'); 3072 writeField.classList.remove('gitment-hidden'); 3073 previewField.classList.add('gitment-hidden'); 3074 3075 textarea.focus(); 3076 }; 3077 previewTab.onclick = function () { 3078 previewTab.classList.add('gitment-selected'); 3079 writeTab.classList.remove('gitment-selected'); 3080 previewField.classList.remove('gitment-hidden'); 3081 writeField.classList.add('gitment-hidden'); 3082 3083 var preview = previewField.querySelector('.gitment-editor-preview'); 3084 var content = textarea.value.trim(); 3085 if (!content) { 3086 preview.innerText = 'Nothing to preview'; 3087 return; 3088 } 3089 3090 preview.innerText = 'Loading preview...'; 3091 instance.markdown(content).then(function (html) { 3092 return preview.innerHTML = html; 3093 }); 3094 }; 3095 3096 var submitButton = container.querySelector('.gitment-editor-submit'); 3097 submitButton.onclick = function () { 3098 submitButton.innerText = 'Submitting...'; 3099 submitButton.setAttribute('disabled', true); 3100 instance.post(textarea.value.trim()).then(function (data) { 3101 textarea.value = ''; 3102 textarea.style.height = 'auto'; 3103 submitButton.removeAttribute('disabled'); 3104 submitButton.innerText = 'Comment'; 3105 }).catch(function (e) { 3106 alert(e); 3107 submitButton.removeAttribute('disabled'); 3108 submitButton.innerText = 'Comment'; 3109 }); 3110 }; 3111 3112 return container; 3113 } 3114 3115 function renderFooter() { 3116 var container = document.createElement('div'); 3117 container.lang = "en-US"; 3118 container.className = 'gitment-container gitment-footer-container'; 3119 container.innerHTML = '\n Powered by\n <a class="gitment-footer-project-link" href="https://github.com/imsun/gitment" target="_blank">\n Gitment\n </a>\n '; 3120 return container; 3121 } 3122 3123 function render(state, instance) { 3124 var container = document.createElement('div'); 3125 container.lang = "en-US"; 3126 container.className = 'gitment-container gitment-root-container'; 3127 container.appendChild(instance.renderHeader(state, instance)); 3128 container.appendChild(instance.renderComments(state, instance)); 3129 container.appendChild(instance.renderEditor(state, instance)); 3130 container.appendChild(instance.renderFooter(state, instance)); 3131 return container; 3132 } 3133 3134 exports.default = { render: render, renderHeader: renderHeader, renderComments: renderComments, renderEditor: renderEditor, renderFooter: renderFooter }; 3135 3136 /***/ }), 3137 /* 3 */ 3138 /***/ (function(module, exports, __webpack_require__) { 3139 3140 "use strict"; 3141 3142 3143 Object.defineProperty(exports, "__esModule", { 3144 value: true 3145 }); 3146 exports.http = exports.Query = exports.isString = undefined; 3147 3148 var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); }
3148 else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); 3149 3150 exports.getTargetContainer = getTargetContainer; 3151 3152 var _constants = __webpack_require__(0); 3153 3154 var isString = exports.isString = function isString(s) { 3155 return toString.call(s) === '[object String]'; 3156 }; 3157 3158 function getTargetContainer(container) { 3159 var targetContainer = void 0; 3160 if (container instanceof Element) { 3161 targetContainer = container; 3162 } else if (isString(container)) { 3163 targetContainer = document.getElementById(container); 3164 } else { 3165 targetContainer = document.createElement('div'); 3166 } 3167 3168 return targetContainer; 3169 } 3170 3171 var Query = exports.Query = { 3172 parse: function parse() { 3173 var search = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.search; 3174 3175 if (!search) return {}; 3176 var queryString = search[0] === '?' ? search.substring(1) : search; 3177 var query = {}; 3178 queryString.split('&').forEach(function (queryStr) { 3179 var _queryStr$split = queryStr.split('='), 3180 _queryStr$split2 = _slicedToArray(_queryStr$split, 2), 3181 key = _queryStr$split2[0], 3182 value = _queryStr$split2[1]; 3183 3184 if (key) query[key] = value; 3185 }); 3186 3187 return query; 3188 }, 3189 stringify: function stringify(query) { 3190 var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '?'; 3191 3192 var queryString = Object.keys(query).map(function (key) { 3193 return key + '=' + encodeURIComponent(query[key] || ''); 3194 }).join('&'); 3195 return queryString ? prefix + queryString : ''; 3196 } 3197 }; 3198 3199 function ajaxFactory(method) { 3200 return function (apiPath) { 3201 var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 3202 var base = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'https://api.github.com'; 3203 3204 var req = new XMLHttpRequest(); 3205 var token = localStorage.getItem(_constants.LS_ACCESS_TOKEN_KEY); 3206 3207 var url = '' + base + apiPath; 3208 var body = null; 3209 if (method === 'GET' || method === 'DELETE') { 3210 url += Query.stringify(data); 3211 } 3212 3213 var p = new Promise(function (resolve, reject) { 3214 req.addEventListener('load', function () { 3215 var contentType = req.getResponseHeader('content-type'); 3216 var res = req.responseText; 3217 if (!/json/.test(contentType)) { 3218 resolve(res); 3219 return; 3220 } 3221 var data = req.responseText ? JSON.parse(res) : {}; 3222 if (data.message) { 3223 reject(new Error(data.message)); 3224 } else { 3225 resolve(data); 3226 } 3227 }); 3228 req.addEventListener('error', function (error) { 3229 return reject(error); 3230 }); 3231 }); 3232 req.open(method, url, true); 3233 3234 req.setRequestHeader('Accept', 'application/vnd.github.squirrel-girl-preview, application/vnd.github.html+json'); 3235 if (token) { 3236 req.setRequestHeader('Authorization', 'token ' + token); 3237 } 3238 if (method !== 'GET' && method !== 'DELETE') { 3239 body = JSON.stringify(data); 3240 req.setRequestHeader('Content-Type', 'application/json'); 3241 } 3242 3243 req.send(body); 3244 return p; 3245 }; 3246 } 3247 3248 var http = exports.http = { 3249 get: ajaxFactory('GET'), 3250 post: ajaxFactory('POST'), 3251 delete: ajaxFactory('DELETE'), 3252 put: ajaxFactory('PUT') 3253 }; 3254 3255 /***/ }), 3256 /* 4 */ 3257 /***/ (function(module, exports, __webpack_require__) { 3258 3259 "use strict"; 3260 3261 3262 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; }; 3263 3264 var g; 3265 3266// This works in non-strict mode 3267 g = function () { 3268 return this; 3269 }(); 3270 3271 try { 3272 // This works if eval is allowed (see CSP) 3273 g = g || Function("return this")() || (1, eval)("this"); 3274 } catch (e) { 3275 // This works if the window reference is available 3276 if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === "object") g = window; 3277 } 3278 3279// g can still be undefined, but nothing to do about it... 3280// We return undefined, instead of nothing here, so it's 3281// easier to handle this case. if(!global) { ...} 3282 3283 module.exports = g; 3284 3285 /***/ }), 3286 /* 5 */ 3287 /***/ (function(module, exports, __webpack_require__) { 3288 3289 "use strict"; 3290 3291 3292 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 3293 3294 var _mobx = __webpack_require__(1); 3295 3296 var _constants = __webpack_require__(0); 3297 3298 var _utils = __webpack_require__(3); 3299 3300 var _default = __webpack_require__(2); 3301 3302 var _default2 = _interopRequireDefault(_default); 3303 3304 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 3305 3306 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 3307 3308 var scope = 'public_repo'; 3309 3310 function extendRenderer(instance, renderer) { 3311 instance[renderer] = function (container) { 3312 var targetContainer = (0, _utils.getTargetContainer)(container); 3313 var render = instance.theme[renderer] || instance.defaultTheme[renderer]; 3314 3315 (0, _mobx.autorun)(function () { 3316 var e = render(instance.state, instance); 3317 if (targetContainer.firstChild) { 3318 targetContainer.replaceChild(e, targetContainer.firstChild); 3319 } else { 3320 targetContainer.appendChild(e); 3321 } 3322 }); 3323 3324 return targetContainer; 3325 }; 3326 } 3327 3328 var Gitment = function () { 3329 _createClass(Gitment, [{ 3330 key: 'accessToken', 3331 get: function get() { 3332 return localStorage.getItem(_constants.LS_ACCESS_TOKEN_KEY); 3333 }, 3334 set: function set(token) { 3335 localStorage.setItem(_constants.LS_ACCESS_TOKEN_KEY, token); 3336 } 3337 }, { 3338 key: 'loginLink', 3339 get: function get() { 3340 var oauthUri = 'https://github.com/login/oauth/authorize'; 3341 var redirect_uri = this.oauth.redirect_uri || window.location.href; 3342 3343 var oauthParams = Object.assign({ 3344 scope: scope, 3345 redirect_uri: redirect_uri 3346 }, this.oauth); 3347 3348 return '' + oauthUri + _utils.Query.stringify(oauthParams); 3349 } 3350 }]); 3351 3352 function Gitment() { 3353 var _this = this; 3354 3355 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 3356 3357 _classCallCheck(this, Gitment); 3358 3359 this.defaultTheme = _default2.default; 3360 this.useTheme(_default2.default); 3361 3362 Object.assign(this, { 3363 id: window.location.href, 3364 title: window.document.title, 3365 link: window.location.href, 3366 desc: '', 3367 labels: [], 3368 theme: _default2.default, 3369 oauth: {}, 3370 perPage: 20, 3371 maxCommentHeight: 250 3372 }, options); 3373 3374 this.useTheme(this.theme); 3375 3376 var user = {}; 3377 try { 3378 var userInfo = localStorage.getItem(_constants.LS_USER_KEY); 3379 if (this.accessToken && userInfo) { 3380 Object.assign(user, JSON.parse(userInfo), { 3381 fromCache: true 3382 }); 3383 } 3384 } catch (e) { 3385 localStorage.removeItem(_constants.LS_USER_KEY); 3386 } 3387 3388 this.state = (0, _mobx.observable)({ 3389 user: user, 3390 error: null, 3391 meta: {}, 3392 comments: undefined, 3393 reactions: [], 3394 commentReactions: {}, 3395 currentPage: 1 3396 }); 3397 3398 var query = _utils.Query.parse(); 3399 if (query.code) { 3400 var _oauth = this.oauth, 3401 client_id = _oauth.client_id, 3402 client_secret = _oauth.client_secret; 3403 3404 var code = query.code; 3405 delete query.code; 3406 var search = _utils.Query.stringify(query); 3407 var replacedUrl = '' + window.location.origin + window.location.pathname + search + window.location.hash; 3408 history.replaceState({}, '', replacedUrl); 3409 3410 Object.assign(this, { 3411 id: replacedUrl, 3412 link: replacedUrl 3413 }, options); 3414 3415 this.state.user.isLoggingIn = true; 3416 _utils.http.post('https://auth.baixiaotu.cc', { 3417 code: code, 3418 client_id: client_id, 3419 client_secret: client_secret 3420 }, '').then(function (data) { 3421 _this.accessToken = data.access_token; 3422 _this.update(); 3423 }).catch(function (e) { 3424 _this.state.user.isLoggingIn = false;
3425 alert(e); 3426 }); 3427 } else { 3428 this.update(); 3429 } 3430 } 3431 3432 _createClass(Gitment, [{ 3433 key: 'init', 3434 value: function init() { 3435 var _this2 = this; 3436 3437 return this.createIssue().then(function () { 3438 return _this2.loadComments(); 3439 }).then(function (comments) { 3440 _this2.state.error = null; 3441 return comments; 3442 }); 3443 } 3444 }, { 3445 key: 'useTheme', 3446 value: function useTheme() { 3447 var _this3 = this; 3448 3449 var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 3450 3451 this.theme = theme; 3452 3453 var renderers = Object.keys(this.theme); 3454 renderers.forEach(function (renderer) { 3455 return extendRenderer(_this3, renderer); 3456 }); 3457 } 3458 }, { 3459 key: 'update', 3460 value: function update() { 3461 var _this4 = this; 3462 3463 return Promise.all([this.loadMeta(), this.loadUserInfo()]).then(function () { 3464 return Promise.all([_this4.loadComments().then(function () { 3465 return _this4.loadCommentReactions(); 3466 }), _this4.loadReactions()]); 3467 }).catch(function (e) { 3468 return _this4.state.error = e; 3469 }); 3470 } 3471 }, { 3472 key: 'markdown', 3473 value: function markdown(text) { 3474 return _utils.http.post('/markdown', { 3475 text: text, 3476 mode: 'gfm' 3477 }); 3478 } 3479 }, { 3480 key: 'createIssue', 3481 value: function createIssue() { 3482 var _this5 = this; 3483 3484 var id = this.id, 3485 owner = this.owner, 3486 repo = this.repo, 3487 title = this.title, 3488 link = this.link, 3489 desc = this.desc, 3490 labels = this.labels; 3491 3492 3493 return _utils.http.post('/repos/' + owner + '/' + repo + '/issues', { 3494 title: title, 3495 labels: labels.concat(['gitment', id]), 3496 body: link + '\n\n' + desc 3497 }).then(function (meta) { 3498 _this5.state.meta = meta; 3499 return meta; 3500 }); 3501 } 3502 }, { 3503 key: 'getIssue', 3504 value: function getIssue() { 3505 if (this.state.meta.id) return Promise.resolve(this.state.meta); 3506 3507 return this.loadMeta(); 3508 } 3509 }, { 3510 key: 'post', 3511 value: function post(body) { 3512 var _this6 = this; 3513 3514 return this.getIssue().then(function (issue) { 3515 return _utils.http.post(issue.comments_url, { body: body }, ''); 3516 }).then(function (data) { 3517 _this6.state.meta.comments++; 3518 var pageCount = Math.ceil(_this6.state.meta.comments / _this6.perPage); 3519 if (_this6.state.currentPage === pageCount) { 3520 _this6.state.comments.push(data); 3521 } 3522 return data; 3523 }); 3524 } 3525 }, { 3526 key: 'loadMeta', 3527 value: function loadMeta() { 3528 var _this7 = this; 3529 3530 var id = this.id, 3531 owner = this.owner, 3532 repo = this.repo; 3533 3534 return _utils.http.get('/repos/' + owner + '/' + repo + '/issues', { 3535 creator: owner, 3536 labels: id 3537 }).then(function (issues) { 3538 if (!issues.length) return Promise.reject(_constants.NOT_INITIALIZED_ERROR); 3539 _this7.state.meta = issues[0]; 3540 return issues[0]; 3541 }); 3542 } 3543 }, { 3544 key: 'loadComments', 3545 value: function loadComments() { 3546 var _this8 = this; 3547 3548 var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.state.currentPage; 3549 3550 return this.getIssue().then(function (issue) { 3551 return _utils.http.get(issue.comments_url, { page: page, per_page: _this8.perPage }, ''); 3552 }).then(function (comments) { 3553 _this8.state.comments = comments; 3554 return comments; 3555 }); 3556 } 3557 }, { 3558 key: 'loadUserInfo', 3559 value: function loadUserInfo() { 3560 var _this9 = this; 3561 3562 if (!this.accessToken) { 3563 this.logout(); 3564 return Promise.resolve({}); 3565 } 3566 3567 return _utils.http.get('/user').then(function (user) { 3568 _this9.state.user = user; 3569 localStorage.setItem(_constants.LS_USER_KEY, JSON.stringify(user)); 3570 return user; 3571 }); 3572 } 3573 }, { 3574 key: 'loadReactions', 3575 value: function loadReactions() { 3576 var _this10 = this; 3577 3578 if (!this.accessToken) { 3579 this.state.reactions = []; 3580 return Promise.resolve([]); 3581 } 3582 3583 return this.getIssue().then(function (issue) { 3584 if (!issue.reactions.total_count) return []; 3585 return _utils.http.get(issue.reactions.url, {}, ''); 3586 }).then(function (reactions) { 3587 _this10.state.reactions = reactions; 3588 return reactions; 3589 }); 3590 } 3591 }, { 3592 key: 'loadCommentReactions', 3593 value: function loadCommentReactions() { 3594 var _this11 = this; 3595 3596 if (!this.accessToken) { 3597 this.state.commentReactions = {}; 3598 return Promise.resolve([]); 3599 } 3600 3601 var comments = this.state.comments; 3602 var comentReactions = {}; 3603 3604 return Promise.all(comments.map(function (comment) { 3605 if (!comment.reactions.total_count) return []; 3606 3607 var owner = _this11.owner, 3608 repo = _this11.repo; 3609 3610 return _utils.http.get('/repos/' + owner + '/' + repo + '/issues/comments/' + comment.id + '/reactions', {}); 3611 })).then(function (reactionsArray) {
3612 comments.forEach(function (comment, index) { 3613 comentReactions[comment.id] = reactionsArray[index]; 3614 }); 3615 _this11.state.commentReactions = comentReactions; 3616 3617 return comentReactions; 3618 }); 3619 } 3620 }, { 3621 key: 'login', 3622 value: function login() { 3623 window.location.href = this.loginLink; 3624 } 3625 }, { 3626 key: 'logout', 3627 value: function logout() { 3628 localStorage.removeItem(_constants.LS_ACCESS_TOKEN_KEY); 3629 localStorage.removeItem(_constants.LS_USER_KEY); 3630 this.state.user = {}; 3631 } 3632 }, { 3633 key: 'goto', 3634 value: function goto(page) { 3635 this.state.currentPage = page; 3636 this.state.comments = undefined; 3637 return this.loadComments(page); 3638 } 3639 }, { 3640 key: 'like', 3641 value: function like() { 3642 var _this12 = this; 3643 3644 if (!this.accessToken) { 3645 alert('Login to Like'); 3646 return Promise.reject(); 3647 } 3648 3649 var owner = this.owner, 3650 repo = this.repo; 3651 3652 3653 return _utils.http.post('/repos/' + owner + '/' + repo + '/issues/' + this.state.meta.number + '/reactions', { 3654 content: 'heart' 3655 }).then(function (reaction) { 3656 _this12.state.reactions.push(reaction); 3657 _this12.state.meta.reactions.heart++; 3658 }); 3659 } 3660 }, { 3661 key: 'unlike', 3662 value: function unlike() { 3663 var _this13 = this; 3664 3665 if (!this.accessToken) return Promise.reject(); 3666 3667 var _state = this.state, 3668 user = _state.user, 3669 reactions = _state.reactions; 3670 3671 var index = reactions.findIndex(function (reaction) { 3672 return reaction.user.login === user.login; 3673 }); 3674 return _utils.http.delete('/reactions/' + reactions[index].id).then(function () { 3675 reactions.splice(index, 1); 3676 _this13.state.meta.reactions.heart--; 3677 }); 3678 } 3679 }, { 3680 key: 'likeAComment', 3681 value: function likeAComment(commentId) { 3682 var _this14 = this; 3683 3684 if (!this.accessToken) { 3685 alert('Login to Like'); 3686 return Promise.reject(); 3687 } 3688 3689 var owner = this.owner, 3690 repo = this.repo; 3691 3692 var comment = this.state.comments.find(function (comment) { 3693 return comment.id === commentId; 3694 }); 3695 3696 return _utils.http.post('/repos/' + owner + '/' + repo + '/issues/comments/' + commentId + '/reactions', { 3697 content: 'heart' 3698 }).then(function (reaction) { 3699 _this14.state.commentReactions[commentId].push(reaction); 3700 comment.reactions.heart++; 3701 }); 3702 } 3703 }, { 3704 key: 'unlikeAComment', 3705 value: function unlikeAComment(commentId) { 3706 if (!this.accessToken) return Promise.reject(); 3707 3708 var reactions = this.state.commentReactions[commentId]; 3709 var comment = this.state.comments.find(function (comment) { 3710 return comment.id === commentId; 3711 }); 3712 var user = this.state.user; 3713 3714 var index = reactions.findIndex(function (reaction) { 3715 return reaction.user.login === user.login; 3716 }); 3717 3718 return _utils.http.delete('/reactions/' + reactions[index].id).then(function () { 3719 reactions.splice(index, 1); 3720 comment.reactions.heart--; 3721 }); 3722 } 3723 }]); 3724 3725 return Gitment; 3726 }(); 3727 3728 module.exports = Gitment; 3729 3730 /***/ }), 3731 /* 6 */ 3732 /***/ (function(module, exports, __webpack_require__) { 3733 3734 "use strict"; 3735 3736 3737 Object.defineProperty(exports, "__esModule", { 3738 value: true 3739 }); 3740 /** 3741 * Modified from https://github.com/evil-icons/evil-icons 3742 */ 3743 3744 var close = exports.close = '<svg class="gitment-close-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M37.304 11.282l1.414 1.414-26.022 26.02-1.414-1.413z"/><path d="M12.696 11.282l26.022 26.02-1.414 1.415-26.022-26.02z"/></svg>'; 3745 var github = exports.github = '<svg class="gitment-github-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M25 10c-8.3 0-15 6.7-15 15 0 6.6 4.3 12.2 10.3 14.2.8.1 1-.3 1-.7v-2.6c-4.2.9-5.1-2-5.1-2-.7-1.7-1.7-2.2-1.7-2.2-1.4-.9.1-.9.1-.9 1.5.1 2.3 1.5 2.3 1.5 1.3 2.3 3.5 1.6 4.4 1.2.1-1 .5-1.6 1-2-3.3-.4-6.8-1.7-6.8-7.4 0-1.6.6-3 1.5-4-.2-.4-.7-1.9.1-4 0 0 1.3-.4 4.1 1.5 1.2-.3 2.5-.5 3.8-.5 1.3 0 2.6.2 3.8.5 2.9-1.9 4.1-1.5 4.1-1.5.8 2.1.3 3.6.1 4 1 1 1.5 2.4 1.5 4 0 5.8-3.5 7-6.8 7.4.5.5 1 1.4 1 2.8v4.1c0 .4.3.9 1 .7 6-2 10.2-7.6 10.2-14.2C40 16.7 33.3 10 25 10z"/></svg>'; 3746 var heart = exports.heart = '<svg class="gitment-heart-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M25 39.7l-.6-.5C11.5 28.7 8 25 8 19c0-5 4-9 9-9 4.1 0 6.4 2.3 8 4.1 1.6-1.8 3.9-4.1 8-4.1 5 0 9 4 9 9 0 6-3.5 9.7-16.4 20.2l-.6.5zM17 12c-3.9 0-7 3.1-7 7 0 5.1 3.2 8.5 15 18.1 11.8-9.6 15-13 15-18.1 0-3.9-3.1-7-7-7-3.5 0-5.4 2.1-6.9 3.8L25 17.1l-1.1-1.3C22.4 14.1 20.5 12 17 12z"/></svg>'; 3747 var spinner = exports.spinner = '<svg class="gitment-spinner-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M25 18c-.6 0-1-.4-1-1V9c0-.6.4-1 1-1s1 .4 1 1v8c0 .6-.4 1-1 1z"/><path opacity=".3" d="M25 42c-.6 0-1-.4-1-1v-8c0-.6.4-1 1-1s1 .4 1 1v8c0 .6-.4 1-1 1z"/><path opacity=".3" d="M29 19c-.2 0-.3 0-.5-.1-.4-.3-.6-.8-.3-1.3l4-6.9c.3-.4.8-.6 1.3-.3.4.3.6.8.3 1.3l-4 6.9c-.2.2-.5.4-.8.4z"/><path opacity=".3" d="M17 39.8c-.2 0-.3 0-.5-.1-.4-.3-.6-.8-.3-1.3l4-6.9c.3-.4.8-.6 1.3-.3.4.3.6.8.3 1.3l-4 6.9c-.2.2-.5.4-.8.4z"/><path opacity=".93" d="M21 19c-.3 0-.6-.2-.8-.5l-4-6.9c-.3-.4-.1-1 .3-1.3.4-.3 1-.1 1.3.3l4 6.9c.3.4.1 1-.3 1.3-.2.2-.3.2-.5.2z"/><path opacity=".3" d="M33 39.8c-.3 0-.6-.2-.8-.5l-4-6.9c-.3-.4-.1-1 .3-1.3.4-.3 1-.1 1.3.3l4 6.9c.3.4.1 1-.3 1.3-.2.1-.3.2-.5.2z"/><path opacity=".65" d="M17 26H9c-.6 0-1-.4-1-1s.4-1 1-1h8c.6 0 1 .4 1 1s-.4 1-1 1z"/><path opacity=".3" d="M41 26h-8c-.6 0-1-.4-1-1s.4-1 1-1h8c.6 0 1 .4 1 1s-.4 1-1 1z"/><path opacity=".86" d="M18.1 21.9c-.2 0-.3 0-.5-.1l-6.9-4c-.4-.3-.6-.8-.3-1.3.3-.4.8-.6 1.3-.3l6.9 4c.4.3.6.8.3 1.3-.2.3-.5.4-.8.4z"/><path opacity=".3" d="M38.9 33.9c-.2 0-.3 0-.5-.1l-6.9-4c-.4-.3-.6-.8-.3-1.3.3-.4.8-.6 1.3-.3l6.9 4c.4.3.6.8.3 1.3-.2.3-.5.4-.8.4z"/><path opacity=".44" d="M11.1 33.9c-.3 0-.6-.2-.8-.5-.3-.4-.1-1 .3-1.3l6.9-4c.4-.3 1-.1 1.3.3.3.4.1 1-.3 1.3l-6.9 4c-.1.2-.3.2-.5.2z"/><path opacity=".3" d="M31.9 21.9c-.3 0-.6-.2-.8-.5-.3-.4-.1-1 .3-1.3l6.9-4c.4-.3 1-.1 1.3.3.3.4.1 1-.3 1.3l-6.9 4c-.2.2-.3.2-.5.2z"/></svg>'; 3748 3749 /***/ }) 3750 /******/ ]); 3751//# sourceMappingURL=gitment.browser.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.