-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitment.browser.js
3710 lines (3555 loc) · 146 KB
/
gitment.browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var Gitment =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var LS_ACCESS_TOKEN_KEY = exports.LS_ACCESS_TOKEN_KEY = 'gitment-comments-token';
var LS_USER_KEY = exports.LS_USER_KEY = 'gitment-user-info';
var NOT_INITIALIZED_ERROR = exports.NOT_INITIALIZED_ERROR = new Error('Comments Not Initialized');
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(global) {
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var __extends = undefined && undefined.__extends || function () {
var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) d[p] = b[p];
}
};
return function (d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
Object.defineProperty(exports, "__esModule", { value: true });
registerGlobals();
exports.extras = {
allowStateChanges: allowStateChanges,
deepEqual: deepEqual,
getAtom: getAtom,
getDebugName: getDebugName,
getDependencyTree: getDependencyTree,
getAdministration: getAdministration,
getGlobalState: getGlobalState,
getObserverTree: getObserverTree,
isComputingDerivation: isComputingDerivation,
isSpyEnabled: isSpyEnabled,
onReactionError: onReactionError,
resetGlobalState: resetGlobalState,
shareGlobalState: shareGlobalState,
spyReport: spyReport,
spyReportEnd: spyReportEnd,
spyReportStart: spyReportStart,
setReactionScheduler: setReactionScheduler
};
if ((typeof __MOBX_DEVTOOLS_GLOBAL_HOOK__ === "undefined" ? "undefined" : _typeof(__MOBX_DEVTOOLS_GLOBAL_HOOK__)) === "object") {
__MOBX_DEVTOOLS_GLOBAL_HOOK__.injectMobx(module.exports);
}
module.exports.default = module.exports;
var actionFieldDecorator = createClassPropertyDecorator(function (target, key, value, args, originalDescriptor) {
var actionName = args && args.length === 1 ? args[0] : value.name || key || "<unnamed action>";
var wrappedAction = action(actionName, value);
addHiddenProp(target, key, wrappedAction);
}, function (key) {
return this[key];
}, function () {
invariant(false, getMessage("m001"));
}, false, true);
var boundActionDecorator = createClassPropertyDecorator(function (target, key, value) {
defineBoundAction(target, key, value);
}, function (key) {
return this[key];
}, function () {
invariant(false, getMessage("m001"));
}, false, false);
var action = function action(arg1, arg2, arg3, arg4) {
if (arguments.length === 1 && typeof arg1 === "function") return createAction(arg1.name || "<unnamed action>", arg1);
if (arguments.length === 2 && typeof arg2 === "function") return createAction(arg1, arg2);
if (arguments.length === 1 && typeof arg1 === "string") return namedActionDecorator(arg1);
return namedActionDecorator(arg2).apply(null, arguments);
};
exports.action = action;
action.bound = function boundAction(arg1, arg2, arg3) {
if (typeof arg1 === "function") {
var action_1 = createAction("<not yet bound action>", arg1);
action_1.autoBind = true;
return action_1;
}
return boundActionDecorator.apply(null, arguments);
};
function namedActionDecorator(name) {
return function (target, prop, descriptor) {
if (descriptor && typeof descriptor.value === "function") {
descriptor.value = createAction(name, descriptor.value);
descriptor.enumerable = false;
descriptor.configurable = true;
return descriptor;
}
return actionFieldDecorator(name).apply(this, arguments);
};
}
function runInAction(arg1, arg2, arg3) {
var actionName = typeof arg1 === "string" ? arg1 : arg1.name || "<unnamed action>";
var fn = typeof arg1 === "function" ? arg1 : arg2;
var scope = typeof arg1 === "function" ? arg2 : arg3;
invariant(typeof fn === "function", getMessage("m002"));
invariant(fn.length === 0, getMessage("m003"));
invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'");
return executeAction(actionName, fn, scope, undefined);
}
exports.runInAction = runInAction;
function isAction(thing) {
return typeof thing === "function" && thing.isMobxAction === true;
}
exports.isAction = isAction;
function defineBoundAction(target, propertyName, fn) {
var res = function res() {
return executeAction(propertyName, fn, target, arguments);
};
res.isMobxAction = true;
addHiddenProp(target, propertyName, res);
}
function autorun(arg1, arg2, arg3) {
var name, view, scope;
if (typeof arg1 === "string") {
name = arg1;
view = arg2;
scope = arg3;
} else {
name = arg1.name || "Autorun@" + getNextId();
view = arg1;
scope = arg2;
}
invariant(typeof view === "function", getMessage("m004"));
invariant(isAction(view) === false, getMessage("m005"));
if (scope) view = view.bind(scope);
var reaction = new Reaction(name, function () {
this.track(reactionRunner);
});
function reactionRunner() {
view(reaction);
}
reaction.schedule();
return reaction.getDisposer();
}
exports.autorun = autorun;
function when(arg1, arg2, arg3, arg4) {
var name, predicate, effect, scope;
if (typeof arg1 === "string") {
name = arg1;
predicate = arg2;
effect = arg3;
scope = arg4;
} else {
name = "When@" + getNextId();
predicate = arg1;
effect = arg2;
scope = arg3;
}
var disposer = autorun(name, function (r) {
if (predicate.call(scope)) {
r.dispose();
var prevUntracked = untrackedStart();
effect.call(scope);
untrackedEnd(prevUntracked);
}
});
return disposer;
}
exports.when = when;
function autorunAsync(arg1, arg2, arg3, arg4) {
var name, func, delay, scope;
if (typeof arg1 === "string") {
name = arg1;
func = arg2;
delay = arg3;
scope = arg4;
} else {
name = arg1.name || "AutorunAsync@" + getNextId();
func = arg1;
delay = arg2;
scope = arg3;
}
invariant(isAction(func) === false, getMessage("m006"));
if (delay === void 0) delay = 1;
if (scope) func = func.bind(scope);
var isScheduled = false;
var r = new Reaction(name, function () {
if (!isScheduled) {
isScheduled = true;
setTimeout(function () {
isScheduled = false;
if (!r.isDisposed) r.track(reactionRunner);
}, delay);
}
});
function reactionRunner() {
func(r);
}
r.schedule();
return r.getDisposer();
}
exports.autorunAsync = autorunAsync;
function reaction(expression, effect, arg3) {
if (arguments.length > 3) {
fail(getMessage("m007"));
}
if (isModifierDescriptor(expression)) {
fail(getMessage("m008"));
}
var opts;
if ((typeof arg3 === "undefined" ? "undefined" : _typeof(arg3)) === "object") {
opts = arg3;
} else {
opts = {};
}
opts.name = opts.name || expression.name || effect.name || "Reaction@" + getNextId();
opts.fireImmediately = arg3 === true || opts.fireImmediately === true;
opts.delay = opts.delay || 0;
opts.compareStructural = opts.compareStructural || opts.struct || false;
effect = action(opts.name, opts.context ? effect.bind(opts.context) : effect);
if (opts.context) {
expression = expression.bind(opts.context);
}
var firstTime = true;
var isScheduled = false;
var nextValue;
var r = new Reaction(opts.name, function () {
if (firstTime || opts.delay < 1) {
reactionRunner();
} else if (!isScheduled) {
isScheduled = true;
setTimeout(function () {
isScheduled = false;
reactionRunner();
}, opts.delay);
}
});
function reactionRunner() {
if (r.isDisposed) return;
var changed = false;
r.track(function () {
var v = expression(r);
changed = valueDidChange(opts.compareStructural, nextValue, v);
nextValue = v;
});
if (firstTime && opts.fireImmediately) effect(nextValue, r);
if (!firstTime && changed === true) effect(nextValue, r);
if (firstTime) firstTime = false;
}
r.schedule();
return r.getDisposer();
}
exports.reaction = reaction;
function createComputedDecorator(compareStructural) {
return createClassPropertyDecorator(function (target, name, _, __, originalDescriptor) {
invariant(typeof originalDescriptor !== "undefined", getMessage("m009"));
invariant(typeof originalDescriptor.get === "function", getMessage("m010"));
var adm = asObservableObject(target, "");
defineComputedProperty(adm, name, originalDescriptor.get, originalDescriptor.set, compareStructural, false);
}, function (name) {
var observable = this.$mobx.values[name];
if (observable === undefined) return undefined;
return observable.get();
}, function (name, value) {
this.$mobx.values[name].set(value);
}, false, false);
}
var computedDecorator = createComputedDecorator(false);
var computedStructDecorator = createComputedDecorator(true);
var computed = function computed(arg1, arg2, arg3) {
if (typeof arg2 === "string") {
return computedDecorator.apply(null, arguments);
}
invariant(typeof arg1 === "function", getMessage("m011"));
invariant(arguments.length < 3, getMessage("m012"));
var opts = (typeof arg2 === "undefined" ? "undefined" : _typeof(arg2)) === "object" ? arg2 : {};
opts.setter = typeof arg2 === "function" ? arg2 : opts.setter;
return new ComputedValue(arg1, opts.context, opts.compareStructural || opts.struct || false, opts.name || arg1.name || "", opts.setter);
};
exports.computed = computed;
computed.struct = computedStructDecorator;
function createTransformer(transformer, onCleanup) {
invariant(typeof transformer === "function" && transformer.length < 2, "createTransformer expects a function that accepts one argument");
var objectCache = {};
var resetId = globalState.resetId;
var Transformer = function (_super) {
__extends(Transformer, _super);
function Transformer(sourceIdentifier, sourceObject) {
var _this = _super.call(this, function () {
return transformer(sourceObject);
}, undefined, false, "Transformer-" + transformer.name + "-" + sourceIdentifier, undefined) || this;
_this.sourceIdentifier = sourceIdentifier;
_this.sourceObject = sourceObject;
return _this;
}
Transformer.prototype.onBecomeUnobserved = function () {
var lastValue = this.value;
_super.prototype.onBecomeUnobserved.call(this);
delete objectCache[this.sourceIdentifier];
if (onCleanup) onCleanup(lastValue, this.sourceObject);
};
return Transformer;
}(ComputedValue);
return function (object) {
if (resetId !== globalState.resetId) {
objectCache = {};
resetId = globalState.resetId;
}
var identifier = getMemoizationId(object);
var reactiveTransformer = objectCache[identifier];
if (reactiveTransformer) return reactiveTransformer.get();
reactiveTransformer = objectCache[identifier] = new Transformer(identifier, object);
return reactiveTransformer.get();
};
}
exports.createTransformer = createTransformer;
function getMemoizationId(object) {
if (object === null || (typeof object === "undefined" ? "undefined" : _typeof(object)) !== "object") throw new Error("[mobx] transform expected some kind of object, got: " + object);
var tid = object.$transformId;
if (tid === undefined) {
tid = getNextId();
addHiddenProp(object, "$transformId", tid);
}
return tid;
}
function expr(expr, scope) {
if (!isComputingDerivation()) console.warn(getMessage("m013"));
return computed(expr, { context: scope }).get();
}
exports.expr = expr;
function extendObservable(target) {
var properties = [];
for (var _i = 1; _i < arguments.length; _i++) {
properties[_i - 1] = arguments[_i];
}
return extendObservableHelper(target, deepEnhancer, properties);
}
exports.extendObservable = extendObservable;
function extendShallowObservable(target) {
var properties = [];
for (var _i = 1; _i < arguments.length; _i++) {
properties[_i - 1] = arguments[_i];
}
return extendObservableHelper(target, referenceEnhancer, properties);
}
exports.extendShallowObservable = extendShallowObservable;
function extendObservableHelper(target, defaultEnhancer, properties) {
invariant(arguments.length >= 2, getMessage("m014"));
invariant((typeof target === "undefined" ? "undefined" : _typeof(target)) === "object", getMessage("m015"));
invariant(!isObservableMap(target), getMessage("m016"));
properties.forEach(function (propSet) {
invariant((typeof propSet === "undefined" ? "undefined" : _typeof(propSet)) === "object", getMessage("m017"));
invariant(!isObservable(propSet), getMessage("m018"));
});
var adm = asObservableObject(target);
var definedProps = {};
for (var i = properties.length - 1; i >= 0; i--) {
var propSet = properties[i];
for (var key in propSet) {
if (definedProps[key] !== true && hasOwnProperty(propSet, key)) {
definedProps[key] = true;
if (target === propSet && !isPropertyConfigurable(target, key)) continue;
var descriptor = Object.getOwnPropertyDescriptor(propSet, key);
defineObservablePropertyFromDescriptor(adm, key, descriptor, defaultEnhancer);
}
}
}
return target;
}
function getDependencyTree(thing, property) {
return nodeToDependencyTree(getAtom(thing, property));
}
function nodeToDependencyTree(node) {
var result = {
name: node.name
};
if (node.observing && node.observing.length > 0) result.dependencies = unique(node.observing).map(nodeToDependencyTree);
return result;
}
function getObserverTree(thing, property) {
return nodeToObserverTree(getAtom(thing, property));
}
function nodeToObserverTree(node) {
var result = {
name: node.name
};
if (hasObservers(node)) result.observers = getObservers(node).map(nodeToObserverTree);
return result;
}
function intercept(thing, propOrHandler, handler) {
if (typeof handler === "function") return interceptProperty(thing, propOrHandler, handler);else return interceptInterceptable(thing, propOrHandler);
}
exports.intercept = intercept;
function interceptInterceptable(thing, handler) {
return getAdministration(thing).intercept(handler);
}
function interceptProperty(thing, property, handler) {
return getAdministration(thing, property).intercept(handler);
}
function isComputed(value, property) {
if (value === null || value === undefined) return false;
if (property !== undefined) {
if (isObservableObject(value) === false) return false;
var atom = getAtom(value, property);
return isComputedValue(atom);
}
return isComputedValue(value);
}
exports.isComputed = isComputed;
function isObservable(value, property) {
if (value === null || value === undefined) return false;
if (property !== undefined) {
if (isObservableArray(value) || isObservableMap(value)) throw new Error(getMessage("m019"));else if (isObservableObject(value)) {
var o = value.$mobx;
return o.values && !!o.values[property];
}
return false;
}
return isObservableObject(value) || !!value.$mobx || isAtom(value) || isReaction(value) || isComputedValue(value);
}
exports.isObservable = isObservable;
var deepDecorator = createDecoratorForEnhancer(deepEnhancer);
var shallowDecorator = createDecoratorForEnhancer(shallowEnhancer);
var refDecorator = createDecoratorForEnhancer(referenceEnhancer);
var deepStructDecorator = createDecoratorForEnhancer(deepStructEnhancer);
var refStructDecorator = createDecoratorForEnhancer(refStructEnhancer);
function createObservable(v) {
if (v === void 0) {
v = undefined;
}
if (typeof arguments[1] === "string") return deepDecorator.apply(null, arguments);
invariant(arguments.length <= 1, getmessage("m021")); invariant(!ismodifierdescriptor(v), getmessage("m020")); if (isobservable(v)) return v; var res="deepEnhancer(v," undefined, undefined); (res !="=" v) res; observable.box(v); } iobservablefactories="function" () { function iobservablefactories() {} iobservablefactories.prototype.box="function" (value, name) (arguments.length> 2) incorrectlyUsedAsDecorator("box");
return new ObservableValue(value, deepEnhancer, name);
};
IObservableFactories.prototype.shallowBox = function (value, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowBox");
return new ObservableValue(value, referenceEnhancer, name);
};
IObservableFactories.prototype.array = function (initialValues, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("array");
return new ObservableArray(initialValues, deepEnhancer, name);
};
IObservableFactories.prototype.shallowArray = function (initialValues, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowArray");
return new ObservableArray(initialValues, referenceEnhancer, name);
};
IObservableFactories.prototype.map = function (initialValues, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("map");
return new ObservableMap(initialValues, deepEnhancer, name);
};
IObservableFactories.prototype.shallowMap = function (initialValues, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowMap");
return new ObservableMap(initialValues, referenceEnhancer, name);
};
IObservableFactories.prototype.object = function (props, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("object");
var res = {};
asObservableObject(res, name);
extendObservable(res, props);
return res;
};
IObservableFactories.prototype.shallowObject = function (props, name) {
if (arguments.length > 2) incorrectlyUsedAsDecorator("shallowObject");
var res = {};
asObservableObject(res, name);
extendShallowObservable(res, props);
return res;
};
IObservableFactories.prototype.ref = function () {
if (arguments.length < 2) {
return createModifierDescriptor(referenceEnhancer, arguments[0]);
} else {
return refDecorator.apply(null, arguments);
}
};
IObservableFactories.prototype.shallow = function () {
if (arguments.length < 2) {
return createModifierDescriptor(shallowEnhancer, arguments[0]);
} else {
return shallowDecorator.apply(null, arguments);
}
};
IObservableFactories.prototype.deep = function () {
if (arguments.length < 2) {
return createModifierDescriptor(deepEnhancer, arguments[0]);
} else {
return deepDecorator.apply(null, arguments);
}
};
IObservableFactories.prototype.struct = function () {
if (arguments.length < 2) {
return createModifierDescriptor(deepStructEnhancer, arguments[0]);
} else {
return deepStructDecorator.apply(null, arguments);
}
};
return IObservableFactories;
}();
exports.IObservableFactories = IObservableFactories;
var observable = createObservable;
exports.observable = observable;
Object.keys(IObservableFactories.prototype).forEach(function (key) {
return observable[key] = IObservableFactories.prototype[key];
});
observable.deep.struct = observable.struct;
observable.ref.struct = function () {
if (arguments.length < 2) {
return createModifierDescriptor(refStructEnhancer, arguments[0]);
} else {
return refStructDecorator.apply(null, arguments);
}
};
function incorrectlyUsedAsDecorator(methodName) {
fail("Expected one or two arguments to observable." + methodName + ". Did you accidentally try to use observable." + methodName + " as decorator?");
}
function createDecoratorForEnhancer(enhancer) {
invariant(!!enhancer, ":(");
return createClassPropertyDecorator(function (target, name, baseValue, _, baseDescriptor) {
assertPropertyConfigurable(target, name);
invariant(!baseDescriptor || !baseDescriptor.get, getMessage("m022"));
var adm = asObservableObject(target, undefined);
defineObservableProperty(adm, name, baseValue, enhancer);
}, function (name) {
var observable = this.$mobx.values[name];
if (observable === undefined) return undefined;
return observable.get();
}, function (name, value) {
setPropertyValue(this, name, value);
}, true, false);
}
function observe(thing, propOrCb, cbOrFire, fireImmediately) {
if (typeof cbOrFire === "function") return observeObservableProperty(thing, propOrCb, cbOrFire, fireImmediately);else return observeObservable(thing, propOrCb, cbOrFire);
}
exports.observe = observe;
function observeObservable(thing, listener, fireImmediately) {
return getAdministration(thing).observe(listener, fireImmediately);
}
function observeObservableProperty(thing, property, listener, fireImmediately) {
return getAdministration(thing, property).observe(listener, fireImmediately);
}
function toJS(source, detectCycles, __alreadySeen) {
if (detectCycles === void 0) {
detectCycles = true;
}
if (__alreadySeen === void 0) {
__alreadySeen = [];
}
function cache(value) {
if (detectCycles) __alreadySeen.push([source, value]);
return value;
}
if (isObservable(source)) {
if (detectCycles && __alreadySeen === null) __alreadySeen = [];
if (detectCycles && source !== null && (typeof source === "undefined" ? "undefined" : _typeof(source)) === "object") {
for (var i = 0, l = __alreadySeen.length; i < l; i++) {
if (__alreadySeen[i][0] === source) return __alreadySeen[i][1];
}
}
if (isObservableArray(source)) {
var res = cache([]);
var toAdd = source.map(function (value) {
return toJS(value, detectCycles, __alreadySeen);
});
res.length = toAdd.length;
for (var i = 0, l = toAdd.length; i < l; i++) {
res[i] = toAdd[i];
}return res;
}
if (isObservableObject(source)) {
var res = cache({});
for (var key in source) {
res[key] = toJS(source[key], detectCycles, __alreadySeen);
}return res;
}
if (isObservableMap(source)) {
var res_1 = cache({});
source.forEach(function (value, key) {
return res_1[key] = toJS(value, detectCycles, __alreadySeen);
});
return res_1;
}
if (isObservableValue(source)) return toJS(source.get(), detectCycles, __alreadySeen);
}
return source;
}
exports.toJS = toJS;
function transaction(action, thisArg) {
if (thisArg === void 0) {
thisArg = undefined;
}
deprecated(getMessage("m023"));
return runInTransaction.apply(undefined, arguments);
}
exports.transaction = transaction;
function runInTransaction(action, thisArg) {
if (thisArg === void 0) {
thisArg = undefined;
}
return executeAction("", action);
}
function log(msg) {
console.log(msg);
return msg;
}
function whyRun(thing, prop) {
switch (arguments.length) {
case 0:
thing = globalState.trackingDerivation;
if (!thing) return log(getMessage("m024"));
break;
case 2:
thing = getAtom(thing, prop);
break;
}
thing = getAtom(thing);
if (isComputedValue(thing)) return log(thing.whyRun());else if (isReaction(thing)) return log(thing.whyRun());
return fail(getMessage("m025"));
}
exports.whyRun = whyRun;
function createAction(actionName, fn) {
invariant(typeof fn === "function", getMessage("m026"));
invariant(typeof actionName === "string" && actionName.length > 0, "actions should have valid names, got: '" + actionName + "'");
var res = function res() {
return executeAction(actionName, fn, this, arguments);
};
res.originalFn = fn;
res.isMobxAction = true;
return res;
}
function executeAction(actionName, fn, scope, args) {
var runInfo = startAction(actionName, fn, scope, args);
try {
return fn.apply(scope, args);
} finally {
endAction(runInfo);
}
}
function startAction(actionName, fn, scope, args) {
var notifySpy = isSpyEnabled() && !!actionName;
var startTime = 0;
if (notifySpy) {
startTime = Date.now();
var l = args && args.length || 0;
var flattendArgs = new Array(l);
if (l > 0) for (var i = 0; i < l; i++) {
flattendArgs[i] = args[i];
}spyReportStart({
type: "action",
name: actionName,
fn: fn,
object: scope,
arguments: flattendArgs
});
}
var prevDerivation = untrackedStart();
startBatch();
var prevAllowStateChanges = allowStateChangesStart(true);
return {
prevDerivation: prevDerivation,
prevAllowStateChanges: prevAllowStateChanges,
notifySpy: notifySpy,
startTime: startTime
};
}
function endAction(runInfo) {
allowStateChangesEnd(runInfo.prevAllowStateChanges);
endBatch();
untrackedEnd(runInfo.prevDerivation);
if (runInfo.notifySpy) spyReportEnd({ time: Date.now() - runInfo.startTime });
}
function useStrict(strict) {
invariant(globalState.trackingDerivation === null, getMessage("m028"));
globalState.strictMode = strict;
globalState.allowStateChanges = !strict;
}
exports.useStrict = useStrict;
function isStrictModeEnabled() {
return globalState.strictMode;
}
exports.isStrictModeEnabled = isStrictModeEnabled;
function allowStateChanges(allowStateChanges, func) {
var prev = allowStateChangesStart(allowStateChanges);
var res;
try {
res = func();
} finally {
allowStateChangesEnd(prev);
}
return res;
}
function allowStateChangesStart(allowStateChanges) {
var prev = globalState.allowStateChanges;
globalState.allowStateChanges = allowStateChanges;
return prev;
}
function allowStateChangesEnd(prev) {
globalState.allowStateChanges = prev;
}
var BaseAtom = function () {
function BaseAtom(name) {
if (name === void 0) {
name = "Atom@" + getNextId();
}
this.name = name;
this.isPendingUnobservation = true;
this.observers = [];
this.observersIndexes = {};
this.diffValue = 0;
this.lastAccessedBy = 0;
this.lowestObserverState = IDerivationState.NOT_TRACKING;
}
BaseAtom.prototype.onBecomeUnobserved = function () {};
BaseAtom.prototype.reportObserved = function () {
reportObserved(this);
};
BaseAtom.prototype.reportChanged = function () {
startBatch();
propagateChanged(this);
endBatch();
};
BaseAtom.prototype.toString = function () {
return this.name;
};
return BaseAtom;
}();
exports.BaseAtom = BaseAtom;
var Atom = function (_super) {
__extends(Atom, _super);
function Atom(name, onBecomeObservedHandler, onBecomeUnobservedHandler) {
if (name === void 0) {
name = "Atom@" + getNextId();
}
if (onBecomeObservedHandler === void 0) {
onBecomeObservedHandler = noop;
}
if (onBecomeUnobservedHandler === void 0) {
onBecomeUnobservedHandler = noop;
}
var _this = _super.call(this, name) || this;
_this.name = name;
_this.onBecomeObservedHandler = onBecomeObservedHandler;
_this.onBecomeUnobservedHandler = onBecomeUnobservedHandler;
_this.isPendingUnobservation = false;
_this.isBeingTracked = false;
return _this;
}
Atom.prototype.reportObserved = function () {
startBatch();
_super.prototype.reportObserved.call(this);
if (!this.isBeingTracked) {
this.isBeingTracked = true;
this.onBecomeObservedHandler();
}
endBatch();
return !!globalState.trackingDerivation;
};
Atom.prototype.onBecomeUnobserved = function () {
this.isBeingTracked = false;
this.onBecomeUnobservedHandler();
};
return Atom;
}(BaseAtom);
exports.Atom = Atom;
var isAtom = createInstanceofPredicate("Atom", BaseAtom);
var ComputedValue = function () {
function ComputedValue(derivation, scope, compareStructural, name, setter) {
this.derivation = derivation;
this.scope = scope;
this.compareStructural = compareStructural;
this.dependenciesState = IDerivationState.NOT_TRACKING;
this.observing = [];
this.newObserving = null;
this.isPendingUnobservation = false;
this.observers = [];
this.observersIndexes = {};
this.diffValue = 0;
this.runId = 0;
this.lastAccessedBy = 0;
this.lowestObserverState = IDerivationState.UP_TO_DATE;
this.unboundDepsCount = 0;
this.__mapid = "#" + getNextId();
this.value = undefined;
this.isComputing = false;
this.isRunningSetter = false;
this.name = name || "ComputedValue@" + getNextId();
if (setter) this.setter = createAction(name + "-setter", setter);
}
ComputedValue.prototype.onBecomeStale = function () {
propagateMaybeChanged(this);
};
ComputedValue.prototype.onBecomeUnobserved = function () {
invariant(this.dependenciesState !== IDerivationState.NOT_TRACKING, getMessage("m029"));
clearObserving(this);
this.value = undefined;
};
ComputedValue.prototype.get = function () {
invariant(!this.isComputing, "Cycle detected in computation " + this.name, this.derivation);
if (globalState.inBatch === 0) {
startBatch();
if (shouldCompute(this)) this.value = this.computeValue(false);
endBatch();
} else {
reportObserved(this);
if (shouldCompute(this)) if (this.trackAndCompute()) propagateChangeConfirmed(this);
}
var result = this.value;
if (isCaughtException(result)) throw result.cause;
return result;
};
ComputedValue.prototype.peek = function () {
var res = this.computeValue(false);
if (isCaughtException(res)) throw res.cause;
return res;
};
ComputedValue.prototype.set = function (value) {
if (this.setter) {
invariant(!this.isRunningSetter, "The setter of computed value '" + this.name + "' is trying to update itself. Did you intend to update an _observable_ value, instead of the computed property?");
this.isRunningSetter = true;
try {
this.setter.call(this.scope, value);
} finally {
this.isRunningSetter = false;
}
} else invariant(false, "[ComputedValue '" + this.name + "'] It is not possible to assign a new value to a computed value.");
};
ComputedValue.prototype.trackAndCompute = function () {
if (isSpyEnabled()) {
spyReport({
object: this.scope,
type: "compute",
fn: this.derivation
});
}
var oldValue = this.value;
var newValue = this.value = this.computeValue(true);
return isCaughtException(newValue) || valueDidChange(this.compareStructural, newValue, oldValue);
};
ComputedValue.prototype.computeValue = function (track) {
this.isComputing = true;
globalState.computationDepth++;
var res;
if (track) {
res = trackDerivedFunction(this, this.derivation, this.scope);
} else {
try {
res = this.derivation.call(this.scope);
} catch (e) {
res = new CaughtException(e);
}
}
globalState.computationDepth--;
this.isComputing = false;
return res;
};
;
ComputedValue.prototype.observe = function (listener, fireImmediately) {
var _this = this;
var firstTime = true;
var prevValue = undefined;
return autorun(function () {
var newValue = _this.get();
if (!firstTime || fireImmediately) {
var prevU = untrackedStart();
listener({
type: "update",
object: _this,
newValue: newValue,
oldValue: prevValue
});
untrackedEnd(prevU);
}
firstTime = false;
prevValue = newValue;
});
};
ComputedValue.prototype.toJSON = function () {
return this.get();
};
ComputedValue.prototype.toString = function () {
return this.name + "[" + this.derivation.toString() + "]";
};
ComputedValue.prototype.valueOf = function () {
return toPrimitive(this.get());
};
;
ComputedValue.prototype.whyRun = function () {
var isTracking = Boolean(globalState.trackingDerivation);
var observing = unique(this.isComputing ? this.newObserving : this.observing).map(function (dep) {
return dep.name;
});
var observers = unique(getObservers(this).map(function (dep) {
return dep.name;
}));
return "\nWhyRun? computation '" + this.name + "':\n * Running because: " + (isTracking ? "[active] the value of this computation is needed by a reaction" : this.isComputing ? "[get] The value of this computed was requested outside a reaction" : "[idle] not running at the moment") + "\n" + (this.dependenciesState === IDerivationState.NOT_TRACKING ? getMessage("m032") : " * This computation will re-run if any of the following observables changes:\n " + joinStrings(observing) + "\n " + (this.isComputing && isTracking ? " (... or any observable accessed during the remainder of the current run)" : "") + "\n\t" + getMessage("m038") + "\n\n * If the outcome of this computation changes, the following observers will be re-run:\n " + joinStrings(observers) + "\n");
};
return ComputedValue;
}();
ComputedValue.prototype[primitiveSymbol()] = ComputedValue.prototype.valueOf;
var isComputedValue = createInstanceofPredicate("ComputedValue", ComputedValue);
var IDerivationState;
(function (IDerivationState) {
IDerivationState[IDerivationState["NOT_TRACKING"] = -1] = "NOT_TRACKING";
IDerivationState[IDerivationState["UP_TO_DATE"] = 0] = "UP_TO_DATE";
IDerivationState[IDerivationState["POSSIBLY_STALE"] = 1] = "POSSIBLY_STALE";
IDerivationState[IDerivationState["STALE"] = 2] = "STALE";
})(IDerivationState || (IDerivationState = {}));
exports.IDerivationState = IDerivationState;
var CaughtException = function () {
function CaughtException(cause) {
this.cause = cause;
}
return CaughtException;
}();
function isCaughtException(e) {
return e instanceof CaughtException;
}
function shouldCompute(derivation) {
switch (derivation.dependenciesState) {
case IDerivationState.UP_TO_DATE:
return false;
case IDerivationState.NOT_TRACKING:
case IDerivationState.STALE:
return true;
case IDerivationState.POSSIBLY_STALE: