forked from aimingoo/gitmint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitmint.browser.js
4946 lines (4593 loc) · 198 KB
/
gitmint.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 Gitmint =
/******/
(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) {
Object.defineProperty(exports, "__esModule", {
value: true
});
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;
};
/** MobX - (c) Michel Weststrate 2015, 2016 - MIT Licensed */
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
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];
}
};
function __extends(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/**
* Anything that can be used to _store_ state is an Atom in mobx. Atoms have two important jobs
*
* 1) detect when they are being _used_ and report this (using reportObserved). This allows mobx to make the connection between running functions and the data they used
* 2) they should notify mobx whenever they have _changed_. This way mobx can re-run any functions (derivations) that are using this atom.
*/
var BaseAtom = function() {
/**
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
function BaseAtom(name) {
if (name === void 0) {
name = "Atom@" + getNextId();
}
this.name = name;
this.isPendingUnobservation = true; // for effective unobserving. BaseAtom has true, for extra optimization, so its onBecomeUnobserved never gets called, because it's not needed
this.observers = [];
this.observersIndexes = {};
this.diffValue = 0;
this.lastAccessedBy = 0;
this.lowestObserverState = IDerivationState.NOT_TRACKING;
}
BaseAtom.prototype.onBecomeUnobserved = function() {
// noop
};
/**
* Invoke this method to notify mobx that your atom has been used somehow.
*/
BaseAtom.prototype.reportObserved = function() {
reportObserved(this);
};
/**
* Invoke this method _after_ this method has changed to signal mobx that all its observers should invalidate.
*/
BaseAtom.prototype.reportChanged = function() {
startBatch();
propagateChanged(this);
endBatch();
};
BaseAtom.prototype.toString = function() {
return this.name;
};
return BaseAtom;
}();
var Atom = function(_super) {
__extends(Atom, _super);
/**
* Create a new atom. For debugging purposes it is recommended to give it a name.
* The onBecomeObserved and onBecomeUnobserved callbacks can be used for resource management.
*/
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; // for effective unobserving.
_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;
// return doesn't really give useful info, because it can be as well calling computed which calls atom (no reactions)
// also it could not trigger when calculating reaction dependent on Atom because Atom's value was cached by computed called by given reaction.
};
Atom.prototype.onBecomeUnobserved = function() {
this.isBeingTracked = false;
this.onBecomeUnobservedHandler();
};
return Atom;
}(BaseAtom);
var isAtom = createInstanceofPredicate("Atom", BaseAtom);
function hasInterceptors(interceptable) {
return interceptable.interceptors && interceptable.interceptors.length > 0;
}
function registerInterceptor(interceptable, handler) {
var interceptors = interceptable.interceptors || (interceptable.interceptors = []);
interceptors.push(handler);
return once(function() {
var idx = interceptors.indexOf(handler);
if (idx !== -1) interceptors.splice(idx, 1);
});
}
function interceptChange(interceptable, change) {
var prevU = untrackedStart();
try {
var interceptors = interceptable.interceptors;
if (interceptors)
for (var i = 0, l = interceptors.length; i < l; i++) {
change = interceptors[i](change);
invariant(!change || change.type, "Intercept handlers should return nothing or a change object");
if (!change) break;
}
return change;
} finally {
untrackedEnd(prevU);
}
}
function hasListeners(listenable) {
return listenable.changeListeners && listenable.changeListeners.length > 0;
}
function registerListener(listenable, handler) {
var listeners = listenable.changeListeners || (listenable.changeListeners = []);
listeners.push(handler);
return once(function() {
var idx = listeners.indexOf(handler);
if (idx !== -1) listeners.splice(idx, 1);
});
}
function notifyListeners(listenable, change) {
var prevU = untrackedStart();
var listeners = listenable.changeListeners;
if (!listeners) return;
listeners = listeners.slice();
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i](change);
}
untrackedEnd(prevU);
}
function isSpyEnabled() {
return !!globalState.spyListeners.length;
}
function spyReport(event) {
if (!globalState.spyListeners.length) return;
var listeners = globalState.spyListeners;
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i](event);
}
}
function spyReportStart(event) {
var change = objectAssign({}, event, {
spyReportStart: true
});
spyReport(change);
}
var END_EVENT = {
spyReportEnd: true
};
function spyReportEnd(change) {
if (change) spyReport(objectAssign({}, change, END_EVENT));
else spyReport(END_EVENT);
}
function spy(listener) {
globalState.spyListeners.push(listener);
return once(function() {
var idx = globalState.spyListeners.indexOf(listener);
if (idx !== -1) globalState.spyListeners.splice(idx, 1);
});
}
function iteratorSymbol() {
return typeof Symbol === "function" && Symbol.iterator || "@@iterator";
}
var IS_ITERATING_MARKER = "__$$iterating";
function arrayAsIterator(array) {
// returning an array for entries(), values() etc for maps was a mis-interpretation of the specs..,
// yet it is quite convenient to be able to use the response both as array directly and as iterator
// it is suboptimal, but alas...
invariant(array[IS_ITERATING_MARKER] !== true, "Illegal state: cannot recycle array as iterator");
addHiddenFinalProp(array, IS_ITERATING_MARKER, true);
var idx = -1;
addHiddenFinalProp(array, "next", function next() {
idx++;
return {
done: idx >= this.length,
value: idx < this.length ? this[idx] : undefined
};
});
return array;
}
function declareIterator(prototType, iteratorFactory) {
addHiddenFinalProp(prototType, iteratorSymbol(), iteratorFactory);
}
var MAX_SPLICE_SIZE = 10000; // See e.g. https://github.com/mobxjs/mobx/issues/859
// Detects bug in safari 9.1.1 (or iOS 9 safari mobile). See #364
var safariPrototypeSetterInheritanceBug = function() {
var v = false;
var p = {};
Object.defineProperty(p, "0", {
set: function set() {
v = true;
}
});
Object.create(p)["0"] = 1;
return v === false;
}();
/**
* This array buffer contains two lists of properties, so that all arrays
* can recycle their property definitions, which significantly improves performance of creating
* properties on the fly.
*/
var OBSERVABLE_ARRAY_BUFFER_SIZE = 0;
// Typescript workaround to make sure ObservableArray extends Array
var StubArray = function() {
function StubArray() {}
return StubArray;
}();
function inherit(ctor, proto) {
if (typeof Object["setPrototypeOf"] !== "undefined") {
Object["setPrototypeOf"](ctor.prototype, proto);
} else if (typeof ctor.prototype.__proto__ !== "undefined") {
ctor.prototype.__proto__ = proto;
} else {
ctor["prototype"] = proto;
}
}
inherit(StubArray, Array.prototype);
var ObservableArrayAdministration = function() {
function ObservableArrayAdministration(name, enhancer, array, owned) {
this.array = array;
this.owned = owned;
this.values = [];
this.lastKnownLength = 0;
this.interceptors = null;
this.changeListeners = null;
this.atom = new BaseAtom(name || "ObservableArray@" + getNextId());
this.enhancer = function(newV, oldV) {
return enhancer(newV, oldV, name + "[..]");
};
}
ObservableArrayAdministration.prototype.dehanceValue = function(value) {
if (this.dehancer !== undefined) return this.dehancer(value);
return value;
};
ObservableArrayAdministration.prototype.dehanceValues = function(values) {
if (this.dehancer !== undefined) return values.map(this.dehancer);
return values;
};
ObservableArrayAdministration.prototype.intercept = function(handler) {
return registerInterceptor(this, handler);
};
ObservableArrayAdministration.prototype.observe = function(listener, fireImmediately) {
if (fireImmediately === void 0) {
fireImmediately = false;
}
if (fireImmediately) {
listener({
object: this.array,
type: "splice",
index: 0,
added: this.values.slice(),
addedCount: this.values.length,
removed: [],
removedCount: 0
});
}
return registerListener(this, listener);
};
ObservableArrayAdministration.prototype.getArrayLength = function() {
this.atom.reportObserved();
return this.values.length;
};
ObservableArrayAdministration.prototype.setArrayLength = function(newLength) {
if (typeof newLength !== "number" || newLength < 0) throw new Error("[mobx.array] Out of range: " + newLength);
var currentLength = this.values.length;
if (newLength === currentLength) return;
else if (newLength > currentLength) {
var newItems = new Array(newLength - currentLength);
for (var i = 0; i < newLength - currentLength; i++) {
newItems[i] = undefined;
} // No Array.fill everywhere...
this.spliceWithArray(currentLength, 0, newItems);
} else this.spliceWithArray(newLength, currentLength - newLength);
};
// adds / removes the necessary numeric properties to this object
ObservableArrayAdministration.prototype.updateArrayLength = function(oldLength, delta) {
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?");
this.lastKnownLength += delta;
if (delta > 0 && oldLength + delta + 1 > OBSERVABLE_ARRAY_BUFFER_SIZE) reserveArrayBuffer(oldLength + delta + 1);
};
ObservableArrayAdministration.prototype.spliceWithArray = function(index, deleteCount, newItems) {
var _this = this;
checkIfStateModificationsAreAllowed(this.atom);
var length = this.values.length;
if (index === undefined) index = 0;
else if (index > length) index = length;
else if (index < 0) index = Math.max(0, length + index);
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));
if (newItems === undefined) newItems = [];
if (hasInterceptors(this)) {
var change = interceptChange(this, {
object: this.array,
type: "splice",
index: index,
removedCount: deleteCount,
added: newItems
});
if (!change) return EMPTY_ARRAY;
deleteCount = change.removedCount;
newItems = change.added;
}
newItems = newItems.map(function(v) {
return _this.enhancer(v, undefined);
});
var lengthDelta = newItems.length - deleteCount;
this.updateArrayLength(length, lengthDelta); // create or remove new entries
var res = this.spliceItemsIntoValues(index, deleteCount, newItems);
if (deleteCount !== 0 || newItems.length !== 0) this.notifyArraySplice(index, newItems, res);
return this.dehanceValues(res);
};
ObservableArrayAdministration.prototype.spliceItemsIntoValues = function(index, deleteCount, newItems) {
if (newItems.length < MAX_SPLICE_SIZE) {
return (_a = this.values).splice.apply(_a, [index, deleteCount].concat(newItems));
} else {
var res = this.values.slice(index, index + deleteCount);
this.values = this.values.slice(0, index).concat(newItems, this.values.slice(index + deleteCount));
return res;
}
var _a;
};
ObservableArrayAdministration.prototype.notifyArrayChildUpdate = function(index, newValue, oldValue) {
var notifySpy = !this.owned && isSpyEnabled();
var notify = hasListeners(this);
var change = notify || notifySpy ? {
object: this.array,
type: "update",
index: index,
newValue: newValue,
oldValue: oldValue
} : null;
if (notifySpy) spyReportStart(change);
this.atom.reportChanged();
if (notify) notifyListeners(this, change);
if (notifySpy) spyReportEnd();
};
ObservableArrayAdministration.prototype.notifyArraySplice = function(index, added, removed) {
var notifySpy = !this.owned && isSpyEnabled();
var notify = hasListeners(this);
var change = notify || notifySpy ? {
object: this.array,
type: "splice",
index: index,
removed: removed,
added: added,
removedCount: removed.length,
addedCount: added.length
} : null;
if (notifySpy) spyReportStart(change);
this.atom.reportChanged();
// conform: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe
if (notify) notifyListeners(this, change);
if (notifySpy) spyReportEnd();
};
return ObservableArrayAdministration;
}();
var ObservableArray = function(_super) {
__extends(ObservableArray, _super);
function ObservableArray(initialValues, enhancer, name, owned) {
if (name === void 0) {
name = "ObservableArray@" + getNextId();
}
if (owned === void 0) {
owned = false;
}
var _this = _super.call(this) || this;
var adm = new ObservableArrayAdministration(name, enhancer, _this, owned);
addHiddenFinalProp(_this, "$mobx", adm);
if (initialValues && initialValues.length) {
_this.spliceWithArray(0, 0, initialValues);
}
if (safariPrototypeSetterInheritanceBug) {
// Seems that Safari won't use numeric prototype setter untill any * numeric property is
// defined on the instance. After that it works fine, even if this property is deleted.
Object.defineProperty(adm.array, "0", ENTRY_0);
}
return _this;
}
ObservableArray.prototype.intercept = function(handler) {
return this.$mobx.intercept(handler);
};
ObservableArray.prototype.observe = function(listener, fireImmediately) {
if (fireImmediately === void 0) {
fireImmediately = false;
}
return this.$mobx.observe(listener, fireImmediately);
};
ObservableArray.prototype.clear = function() {
return this.splice(0);
};
ObservableArray.prototype.concat = function() {
var arrays = [];
for (var _i = 0; _i < arguments.length; _i++) {
arrays[_i] = arguments[_i];
}
this.$mobx.atom.reportObserved();
return Array.prototype.concat.apply(this.peek(), arrays.map(function(a) {
return isObservableArray(a) ? a.peek() : a;
}));
};
ObservableArray.prototype.replace = function(newItems) {
return this.$mobx.spliceWithArray(0, this.$mobx.values.length, newItems);
};
/**
* Converts this array back to a (shallow) javascript structure.
* For a deep clone use mobx.toJS
*/
ObservableArray.prototype.toJS = function() {
return this.slice();
};
ObservableArray.prototype.toJSON = function() {
// Used by JSON.stringify
return this.toJS();
};
ObservableArray.prototype.peek = function() {
this.$mobx.atom.reportObserved();
return this.$mobx.dehanceValues(this.$mobx.values);
};
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
ObservableArray.prototype.find = function(predicate, thisArg, fromIndex) {
if (fromIndex === void 0) {
fromIndex = 0;
}
var idx = this.findIndex.apply(this, arguments);
return idx === -1 ? undefined : this.get(idx);
};
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
ObservableArray.prototype.findIndex = function(predicate, thisArg, fromIndex) {
if (fromIndex === void 0) {
fromIndex = 0;
}
var items = this.peek(),
l = items.length;
for (var i = fromIndex; i < l; i++) {
if (predicate.call(thisArg, items[i], i, this)) return i;
}
return -1;
};
/*
functions that do alter the internal structure of the array, (based on lib.es6.d.ts)
since these functions alter the inner structure of the array, the have side effects.
Because the have side effects, they should not be used in computed function,
and for that reason the do not call dependencyState.notifyObserved
*/
ObservableArray.prototype.splice = function(index, deleteCount) {
var newItems = [];
for (var _i = 2; _i < arguments.length; _i++) {
newItems[_i - 2] = arguments[_i];
}
switch (arguments.length) {
case 0:
return [];
case 1:
return this.$mobx.spliceWithArray(index);
case 2:
return this.$mobx.spliceWithArray(index, deleteCount);
}
return this.$mobx.spliceWithArray(index, deleteCount, newItems);
};
ObservableArray.prototype.spliceWithArray = function(index, deleteCount, newItems) {
return this.$mobx.spliceWithArray(index, deleteCount, newItems);
};
ObservableArray.prototype.push = function() {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
var adm = this.$mobx;
adm.spliceWithArray(adm.values.length, 0, items);
return adm.values.length;
};
ObservableArray.prototype.pop = function() {
return this.splice(Math.max(this.$mobx.values.length - 1, 0), 1)[0];
};
ObservableArray.prototype.shift = function() {
return this.splice(0, 1)[0];
};
ObservableArray.prototype.unshift = function() {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
var adm = this.$mobx;
adm.spliceWithArray(0, 0, items);
return adm.values.length;
};
ObservableArray.prototype.reverse = function() {
// reverse by default mutates in place before returning the result
// which makes it both a 'derivation' and a 'mutation'.
// so we deviate from the default and just make it an dervitation
var clone = this.slice();
return clone.reverse.apply(clone, arguments);
};
ObservableArray.prototype.sort = function(compareFn) {
// sort by default mutates in place before returning the result
// which goes against all good practices. Let's not change the array in place!
var clone = this.slice();
return clone.sort.apply(clone, arguments);
};
ObservableArray.prototype.remove = function(value) {
var idx = this.$mobx.dehanceValues(this.$mobx.values).indexOf(value);
if (idx > -1) {
this.splice(idx, 1);
return true;
}
return false;
};
ObservableArray.prototype.move = function(fromIndex, toIndex) {
function checkIndex(index) {
if (index < 0) {
throw new Error("[mobx.array] Index out of bounds: " + index + " is negative");
}
var length = this.$mobx.values.length;
if (index >= length) {
throw new Error("[mobx.array] Index out of bounds: " + index + " is not smaller than " + length);
}
}
checkIndex.call(this, fromIndex);
checkIndex.call(this, toIndex);
if (fromIndex === toIndex) {
return;
}
var oldItems = this.$mobx.values;
var newItems;
if (fromIndex < toIndex) {
newItems = oldItems.slice(0, fromIndex).concat(oldItems.slice(fromIndex + 1, toIndex + 1), [oldItems[fromIndex]], oldItems.slice(toIndex + 1));
} else {
newItems = oldItems.slice(0, toIndex).concat([oldItems[fromIndex]], oldItems.slice(toIndex, fromIndex), oldItems.slice(fromIndex + 1));
}
this.replace(newItems);
};
// See #734, in case property accessors are unreliable...
ObservableArray.prototype.get = function(index) {
var impl = this.$mobx;
if (impl) {
if (index < impl.values.length) {
impl.atom.reportObserved();
return impl.dehanceValue(impl.values[index]);
}
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");
}
return undefined;
};
// See #734, in case property accessors are unreliable...
ObservableArray.prototype.set = function(index, newValue) {
var adm = this.$mobx;
var values = adm.values;
if (index < values.length) {
// update at index in range
checkIfStateModificationsAreAllowed(adm.atom);
var oldValue = values[index];
if (hasInterceptors(adm)) {
var change = interceptChange(adm, {
type: "update",
object: this,
index: index,
newValue: newValue
});
if (!change) return;
newValue = change.newValue;
}
newValue = adm.enhancer(newValue, oldValue);
var changed = newValue !== oldValue;
if (changed) {
values[index] = newValue;
adm.notifyArrayChildUpdate(index, newValue, oldValue);
}
} else if (index === values.length) {
// add a new item
adm.spliceWithArray(index, 0, [newValue]);
} else {
// out of bounds
throw new Error("[mobx.array] Index out of bounds, " + index + " is larger than " + values.length);
}
};
return ObservableArray;
}(StubArray);
declareIterator(ObservableArray.prototype, function() {
return arrayAsIterator(this.slice());
});
Object.defineProperty(ObservableArray.prototype, "length", {
enumerable: false,
configurable: true,
get: function get() {
return this.$mobx.getArrayLength();
},
set: function set(newLength) {
this.$mobx.setArrayLength(newLength);
}
});
/**
* Wrap function from prototype
*/
["every", "filter", "forEach", "indexOf", "join", "lastIndexOf", "map", "reduce", "reduceRight", "slice", "some", "toString", "toLocaleString"].forEach(function(funcName) {
var baseFunc = Array.prototype[funcName];
invariant(typeof baseFunc === "function", "Base function not defined on Array prototype: '" + funcName + "'");
addHiddenProp(ObservableArray.prototype, funcName, function() {
return baseFunc.apply(this.peek(), arguments);
});
});
/**
* We don't want those to show up in `for (const key in ar)` ...
*/
makeNonEnumerable(ObservableArray.prototype, ["constructor", "intercept", "observe", "clear", "concat", "get", "replace", "toJS", "toJSON", "peek", "find", "findIndex", "splice", "spliceWithArray", "push", "pop", "set", "shift", "unshift", "reverse", "sort", "remove", "move", "toString", "toLocaleString"]);
// See #364
var ENTRY_0 = createArrayEntryDescriptor(0);
function createArrayEntryDescriptor(index) {
return {
enumerable: false,
configurable: false,
get: function get() {
// TODO: Check `this`?, see #752?
return this.get(index);
},
set: function set(value) {
this.set(index, value);
}
};
}
function createArrayBufferItem(index) {
Object.defineProperty(ObservableArray.prototype, "" + index, createArrayEntryDescriptor(index));
}
function reserveArrayBuffer(max) {
for (var index = OBSERVABLE_ARRAY_BUFFER_SIZE; index < max; index++) {
createArrayBufferItem(index);
}
OBSERVABLE_ARRAY_BUFFER_SIZE = max;
}
reserveArrayBuffer(1000);
var isObservableArrayAdministration = createInstanceofPredicate("ObservableArrayAdministration", ObservableArrayAdministration);
function isObservableArray(thing) {
return isObject(thing) && isObservableArrayAdministration(thing.$mobx);
}
var UNCHANGED = {};
var ObservableValue = function(_super) {
__extends(ObservableValue, _super);
function ObservableValue(value, enhancer, name, notifySpy) {
if (name === void 0) {
name = "ObservableValue@" + getNextId();
}
if (notifySpy === void 0) {
notifySpy = true;
}
var _this = _super.call(this, name) || this;
_this.enhancer = enhancer;
_this.hasUnreportedChange = false;
_this.dehancer = undefined;
_this.value = enhancer(value, undefined, name);
if (notifySpy && isSpyEnabled()) {
// only notify spy if this is a stand-alone observable
spyReport({
type: "create",
object: _this,
newValue: _this.value
});
}
return _this;
}
ObservableValue.prototype.dehanceValue = function(value) {
if (this.dehancer !== undefined) return this.dehancer(value);
return value;
};
ObservableValue.prototype.set = function(newValue) {
var oldValue = this.value;
newValue = this.prepareNewValue(newValue);
if (newValue !== UNCHANGED) {
var notifySpy = isSpyEnabled();
if (notifySpy) {
spyReportStart({
type: "update",
object: this,
newValue: newValue,
oldValue: oldValue
});
}
this.setNewValue(newValue);
if (notifySpy) spyReportEnd();
}
};
ObservableValue.prototype.prepareNewValue = function(newValue) {
checkIfStateModificationsAreAllowed(this);
if (hasInterceptors(this)) {
var change = interceptChange(this, {
object: this,
type: "update",
newValue: newValue
});
if (!change) return UNCHANGED;
newValue = change.newValue;
}
// apply modifier
newValue = this.enhancer(newValue, this.value, this.name);
return this.value !== newValue ? newValue : UNCHANGED;
};
ObservableValue.prototype.setNewValue = function(newValue) {
var oldValue = this.value;
this.value = newValue;
this.reportChanged();
if (hasListeners(this)) {
notifyListeners(this, {
type: "update",
object: this,
newValue: newValue,
oldValue: oldValue
});
}
};
ObservableValue.prototype.get = function() {
this.reportObserved();
return this.dehanceValue(this.value);
};
ObservableValue.prototype.intercept = function(handler) {
return registerInterceptor(this, handler);
};
ObservableValue.prototype.observe = function(listener, fireImmediately) {
if (fireImmediately) listener({
object: this,
type: "update",
newValue: this.value,
oldValue: undefined
});
return registerListener(this, listener);
};
ObservableValue.prototype.toJSON = function() {
return this.get();
};
ObservableValue.prototype.toString = function() {
return this.name + "[" + this.value + "]";
};
ObservableValue.prototype.valueOf = function() {
return toPrimitive(this.get());
};
return ObservableValue;
}(BaseAtom);
ObservableValue.prototype[primitiveSymbol()] = ObservableValue.prototype.valueOf;
var isObservableValue = createInstanceofPredicate("ObservableValue", ObservableValue);
var messages = {
"m001": "It is not allowed to assign new values to @action fields",
"m002": "`runInAction` expects a function",
"m003": "`runInAction` expects a function without arguments",
"m004": "autorun expects a function",
"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.",
"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.",
"m007": "reaction only accepts 2 or 3 arguments. If migrating from MobX 2, please provide an options object",
"m008": "wrapping reaction expression in `asReference` is no longer supported, use options object instead",
"m009": "@computed can only be used on getter functions, like: '@computed get myProps() { return ...; }'. It looks like it was used on a property.",
"m010": "@computed can only be used on getter functions, like: '@computed get myProps() { return ...; }'",
"m011": "First argument to `computed` should be an expression. If using computed as decorator, don't pass it arguments",
"m012": "computed takes one or two arguments if used as function",
"m013": "[mobx.expr] 'expr' should only be used inside other reactive functions.",
"m014": "extendObservable expected 2 or more arguments",
"m015": "extendObservable expects an object as first argument",
"m016": "extendObservable should not be used on maps, use map.merge instead",
"m017": "all arguments of extendObservable should be objects",
"m018": "extending an object with another observable (object) is not supported. Please construct an explicit propertymap, using `toJS` if need. See issue #540",
"m019": "[mobx.isObservable] isObservable(object, propertyName) is not supported for arrays and maps. Use map.has or array.length instead.",
"m020": "modifiers can only be used for individual object properties",
"m021": "observable expects zero or one arguments",
"m022": "@observable can not be used on getters, use @computed instead",
"m023": "Using `transaction` is deprecated, use `runInAction` or `(@)action` instead.",
"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.",
"m025": "whyRun can only be used on reactions and computed values",
"m026": "`action` can only be invoked on functions",
"m028": "It is not allowed to set `useStrict` when a derivation is running",
"m029": "INTERNAL ERROR only onBecomeUnobserved shouldn't be called twice in a row",
"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: ",
"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: ",
"m031": "Computed values are not allowed to cause side effects by changing observables that are already being observed. Tried to modify: ",
"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).",
"m033": "`observe` doesn't support the fire immediately property for observable maps.",
"m034": "`mobx.map` is deprecated, use `new ObservableMap` or `mobx.observable.map` instead",
"m035": "Cannot make the designated object observable; it is not extensible",
"m036": "It is not possible to get index atoms from arrays",
"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",
"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"
};
function getMessage(id) {
return messages[id];
}