/
bundle.js
1338 lines (1161 loc) · 46.5 KB
/
bundle.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
"use strict";
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; };
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
(function e(t, n, r) {
function s(o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);var f = new Error("Cannot find module '" + o + "'");throw f.code = "MODULE_NOT_FOUND", f;
}var l = n[o] = { exports: {} };t[o][0].call(l.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, l, l.exports, e, t, n, r);
}return n[o].exports;
}var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) {
s(r[o]);
}return s;
})({ 1: [function (require, module, exports) {}, {}], 2: [function (require, module, exports) {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function (n) {
if (!isNumber(n) || n < 0 || isNaN(n)) throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function (type) {
var er, handler, len, args, i, listeners;
if (!this._events) this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error || isObject(this._events.error) && !this._events.error.length) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
err.context = er;
throw err;
}
}
}
handler = this._events[type];
if (isUndefined(handler)) return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
args = Array.prototype.slice.call(arguments, 1);
handler.apply(this, args);
}
} else if (isObject(handler)) {
args = Array.prototype.slice.call(arguments, 1);
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++) {
listeners[i].apply(this, args);
}
}
return true;
};
EventEmitter.prototype.addListener = function (type, listener) {
var m;
if (!isFunction(listener)) throw TypeError('listener must be a function');
if (!this._events) this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener) this.emit('newListener', type, isFunction(listener.listener) ? listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function (type, listener) {
if (!isFunction(listener)) throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function (type, listener) {
var list, position, length, i;
if (!isFunction(listener)) throw TypeError('listener must be a function');
if (!this._events || !this._events[type]) return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener || isFunction(list.listener) && list.listener === listener) {
delete this._events[type];
if (this._events.removeListener) this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener || list[i].listener && list[i].listener === listener) {
position = i;
break;
}
}
if (position < 0) return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener) this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function (type) {
var key, listeners;
if (!this._events) return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0) this._events = {};else if (this._events[type]) delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else if (listeners) {
// LIFO order
while (listeners.length) {
this.removeListener(type, listeners[listeners.length - 1]);
}
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function (type) {
var ret;
if (!this._events || !this._events[type]) ret = [];else if (isFunction(this._events[type])) ret = [this._events[type]];else ret = this._events[type].slice();
return ret;
};
EventEmitter.prototype.listenerCount = function (type) {
if (this._events) {
var evlistener = this._events[type];
if (isFunction(evlistener)) return 1;else if (evlistener) return evlistener.length;
}
return 0;
};
EventEmitter.listenerCount = function (emitter, type) {
return emitter.listenerCount(type);
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return (typeof arg === "undefined" ? "undefined" : _typeof(arg)) === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
}, {}], 3: [function (require, module, exports) {
var html = {};
var _ = require('../');
var state = _({ list: [] });
var list = _(function (state) {
return function () {
var ac = require('/Users/lburns/Dropbox/morphable/node_modules/yo-yoify/lib/appendChild.js');
var bel0 = document.createElement("ul");
ac(bel0, ["\n ", arguments[0], "\n"]);
return bel0;
}(state.list.map(function (num) {
return function () {
var ac = require('/Users/lburns/Dropbox/morphable/node_modules/yo-yoify/lib/appendChild.js');
var bel0 = document.createElement("li");
ac(bel0, [arguments[0]]);
return bel0;
}(num);
}));
});
var body = _(function (state) {
return function () {
var ac = require('/Users/lburns/Dropbox/morphable/node_modules/yo-yoify/lib/appendChild.js');
var bel1 = document.createElement("body");
var bel0 = document.createElement("button");
bel0["onclick"] = arguments[0];
ac(bel0, ["Append random number"]);
ac(bel1, ["\n ", bel0, "\n ", arguments[1], "\n"]);
return bel1;
}(function () {
return state.list.push(Math.random());
}, list(state));
});
document.body = body(state);
list.on('load', function (state) {
return console.log('loaded list', state);
});
list.on('morph', function () {
return console.log('morphed list');
});
list.on('unload', function () {
return console.log('unloaded list');
});
}, { "../": 4, "/Users/lburns/Dropbox/morphable/node_modules/yo-yoify/lib/appendChild.js": 13 }], 4: [function (require, module, exports) {
var onload = require('on-load');
var morph = require('nanomorph');
var util = require('@nx-js/observer-util');
var events = require('events');
var observable = util.observable,
observe = util.observe,
unobserve = util.unobserve;
var KEY_ID = onload.KEY_ID;
var i = 1;
function morphable(view) {
if (typeof view !== 'function') return observable(view);
var id = i++;
var reaction = void 0;
var cached = void 0;
var self = this;
var fn = function fn() {
var args = Array.from(arguments);
var rawArgs = args.map(function (state) {
return morphable.raw(state);
});
var element = cached || view.apply(self, rawArgs);
element.id = element.id || id;
return onload(element, function (el) {
if (reaction) return;
cached = el;
fn.emit.apply(fn, ['load', morphable.raw(self), el].concat(_toConsumableArray(rawArgs)));
reaction = observe(function () {
fn.emit.apply(fn, ['morph', morphable.raw(self), el].concat(_toConsumableArray(rawArgs)));
var update = view.apply(self, args);
update.id = update.id || id;
update.dataset[KEY_ID] = el.dataset[KEY_ID];
morph(el, update);
});
}, function (el) {
if (!reaction) return;
fn.emit.apply(fn, ['unload', morphable.raw(self), el].concat(_toConsumableArray(rawArgs)));
unobserve(reaction);
reaction = null;
}, id);
};
events.call(fn);
Object.assign(fn, events.prototype);
return fn;
}
Object.assign(morphable, util);
module.exports = morphable;
}, { "@nx-js/observer-util": 5, "events": 2, "nanomorph": 9, "on-load": 12 }], 5: [function (require, module, exports) {
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var connectionStore = new WeakMap();
var ITERATION_KEY = Symbol('iteration key');
function storeObservable(obj) {
// this will be used to save (obj.key -> reaction) connections later
connectionStore.set(obj, Object.create(null));
}
function registerReactionForOperation(reaction, ref) {
var target = ref.target;
var key = ref.key;
var type = ref.type;
if (type === 'iterate') {
key = ITERATION_KEY;
}
var reactionsForObj = connectionStore.get(target);
var reactionsForKey = reactionsForObj[key];
if (!reactionsForKey) {
reactionsForObj[key] = reactionsForKey = new Set();
}
// save the fact that the key is used by the reaction during its current run
if (!reactionsForKey.has(reaction)) {
reactionsForKey.add(reaction);
reaction.cleaners.push(reactionsForKey);
}
}
function getReactionsForOperation(ref) {
var target = ref.target;
var key = ref.key;
var type = ref.type;
var reactionsForTarget = connectionStore.get(target);
var reactionsForKey = new Set();
if (type === 'clear') {
for (var key$1 in reactionsForTarget) {
addReactionsForKey(reactionsForKey, reactionsForTarget, key$1);
}
} else {
addReactionsForKey(reactionsForKey, reactionsForTarget, key);
}
if (type === 'add' || type === 'delete' || type === 'clear') {
var iterationKey = Array.isArray(target) ? 'length' : ITERATION_KEY;
addReactionsForKey(reactionsForKey, reactionsForTarget, iterationKey);
}
return reactionsForKey;
}
function addReactionsForKey(reactionsForKey, reactionsForTarget, key) {
var reactions = reactionsForTarget[key];
reactions && reactions.forEach(reactionsForKey.add, reactionsForKey);
}
function releaseReaction(reaction) {
if (reaction.cleaners) {
reaction.cleaners.forEach(releaseReactionKeyConnection, reaction);
}
reaction.cleaners = [];
}
function releaseReactionKeyConnection(reactionsForKey) {
reactionsForKey.delete(this);
}
var runningReaction;
var isDebugging = false;
function runAsReaction(reaction, fn, context, args) {
// do not build reactive relations, if the reaction is unobserved
if (reaction.unobserved) {
return fn.apply(context, args);
}
// release the (obj -> key -> reactions) connections
// and reset the cleaner connections
releaseReaction(reaction);
try {
// set the reaction as the currently running one
// this is required so that we can create (observable.prop -> reaction) pairs in the get trap
runningReaction = reaction;
return fn.apply(context, args);
} finally {
// always remove the currently running flag from the reaction when it stops execution
runningReaction = undefined;
}
}
// register the currently running reaction to be queued again on obj.key mutations
function registerRunningReactionForOperation(operation) {
if (runningReaction) {
debugOperation(runningReaction, operation);
registerReactionForOperation(runningReaction, operation);
}
}
function queueReactionsForOperation(operation) {
// iterate and queue every reaction, which is triggered by obj.key mutation
getReactionsForOperation(operation).forEach(queueReaction, operation);
}
function queueReaction(reaction) {
debugOperation(reaction, this);
// queue the reaction for later execution or run it immediately
if (typeof reaction.scheduler === 'function') {
reaction.scheduler(reaction);
} else if (_typeof(reaction.scheduler) === 'object') {
reaction.scheduler.add(reaction);
} else {
reaction();
}
}
function debugOperation(reaction, operation) {
if (reaction.debugger && !isDebugging) {
try {
isDebugging = true;
reaction.debugger(operation);
} finally {
isDebugging = false;
}
}
}
function hasRunningReaction() {
return runningReaction !== undefined;
}
var IS_REACTION = Symbol('is reaction');
function observe(fn, options) {
if (options === void 0) options = {};
// wrap the passed function in a reaction, if it is not already one
var reaction = fn[IS_REACTION] ? fn : function reaction() {
return runAsReaction(reaction, fn, this, arguments);
};
// save the scheduler and debugger on the reaction
reaction.scheduler = options.scheduler;
reaction.debugger = options.debugger;
// save the fact that this is a reaction
reaction[IS_REACTION] = true;
// run the reaction once if it is not a lazy one
if (!options.lazy) {
reaction();
}
return reaction;
}
function unobserve(reaction) {
// do nothing, if the reaction is already unobserved
if (!reaction.unobserved) {
// indicate that the reaction should not be triggered any more
reaction.unobserved = true;
// release (obj -> key -> reaction) connections
releaseReaction(reaction);
}
// unschedule the reaction, if it is scheduled
if (_typeof(reaction.scheduler) === 'object') {
reaction.scheduler.delete(reaction);
}
}
var proxyToRaw = new WeakMap();
var rawToProxy = new WeakMap();
var getPrototypeOf = Object.getPrototypeOf;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var instrumentations = {
has: function has(key) {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, key: key, type: 'has' });
return proto.has.apply(target, arguments);
},
get: function get(key) {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, key: key, type: 'get' });
return proto.get.apply(target, arguments);
},
add: function add(key) {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
var hadKey = proto.has.call(target, key);
// forward the operation before queueing reactions
var result = proto.add.apply(target, arguments);
if (!hadKey) {
queueReactionsForOperation({ target: target, key: key, value: key, type: 'add' });
}
return result;
},
set: function set(key, value) {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
var hadKey = proto.has.call(target, key);
var oldValue = proto.get.call(target, key);
// forward the operation before queueing reactions
var result = proto.set.apply(target, arguments);
if (!hadKey) {
queueReactionsForOperation({ target: target, key: key, value: value, type: 'add' });
} else if (value !== oldValue) {
queueReactionsForOperation({ target: target, key: key, value: value, oldValue: oldValue, type: 'set' });
}
return result;
},
delete: function delete$1(key) {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
var hadKey = proto.has.call(target, key);
var oldValue = proto.get ? proto.get.call(target, key) : undefined;
// forward the operation before queueing reactions
var result = proto.delete.apply(target, arguments);
if (hadKey) {
queueReactionsForOperation({ target: target, key: key, oldValue: oldValue, type: 'delete' });
}
return result;
},
clear: function clear() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
var hadItems = target.size !== 0;
var oldTarget = target instanceof Map ? new Map(target) : new Set(target);
// forward the operation before queueing reactions
var result = proto.clear.apply(target, arguments);
if (hadItems) {
queueReactionsForOperation({ target: target, oldTarget: oldTarget, type: 'clear' });
}
return result;
},
forEach: function forEach() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return proto.forEach.apply(target, arguments);
},
keys: function keys() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return proto.keys.apply(target, arguments);
},
values: function values() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return proto.values.apply(target, arguments);
},
entries: function entries() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return proto.entries.apply(target, arguments);
},
get size() {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return Reflect.get(proto, 'size', target);
}
};
instrumentations[Symbol.iterator] = function () {
var target = proxyToRaw.get(this);
var proto = getPrototypeOf(this);
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return proto[Symbol.iterator].apply(target, arguments);
};
var collectionHandlers = {
get: function get(target, key, receiver) {
// instrument methods and property accessors to be reactive
target = hasOwnProperty.call(instrumentations, key) ? instrumentations : target;
return Reflect.get(target, key, receiver);
}
};
// simple objects are not wrapped by Proxies, neither instrumented
var dontInstrument = new Set([Date, RegExp]);
// built-in object can not be wrapped by Proxies
// their methods expect the object instance as the 'this' instead of the Proxy wrapper
// complex objects are wrapped with a Proxy of instrumented methods
// which switch the proxy to the raw object and to add reactive wiring
var handlers = new Map([[Map, collectionHandlers], [Set, collectionHandlers], [WeakMap, collectionHandlers], [WeakSet, collectionHandlers]]);
function shouldInstrument(obj) {
if (typeof Node === 'function' && obj instanceof Node) {
return false;
}
return !dontInstrument.has(obj.constructor);
}
function getHandlers(obj) {
return handlers.get(obj.constructor);
}
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
// intercept get operations on observables to know which reaction uses their properties
function get(target, key, receiver) {
var result = Reflect.get(target, key, receiver);
// do not register (observable.prop -> reaction) pairs for these cases
if ((typeof key === "undefined" ? "undefined" : _typeof(key)) === 'symbol' || typeof result === 'function') {
return result;
}
// register and save (observable.prop -> runningReaction)
registerRunningReactionForOperation({ target: target, key: key, receiver: receiver, type: 'get' });
// if we are inside a reaction and observable.prop is an object wrap it in an observable too
// this is needed to intercept property access on that object too (dynamic observable tree)
if (hasRunningReaction() && (typeof result === "undefined" ? "undefined" : _typeof(result)) === 'object' && result !== null) {
return observable(result);
}
// otherwise return the observable wrapper if it is already created and cached or the raw object
return rawToProxy.get(result) || result;
}
function has(target, key) {
var result = Reflect.has(target, key);
// do not register (observable.prop -> reaction) pairs for these cases
if ((typeof key === "undefined" ? "undefined" : _typeof(key)) === 'symbol') {
return result;
}
// register and save (observable.prop -> runningReaction)
registerRunningReactionForOperation({ target: target, key: key, type: 'has' });
return result;
}
function ownKeys(target) {
registerRunningReactionForOperation({ target: target, type: 'iterate' });
return Reflect.ownKeys(target);
}
// intercept set operations on observables to know when to trigger reactions
function set(target, key, value, receiver) {
// make sure to do not pollute the raw object with observables
if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === 'object' && value !== null) {
value = proxyToRaw.get(value) || value;
}
// save if the object had a descriptor for this key
var hadKey = hasOwnProperty$1.call(target, key);
// save if the value changed because of this set operation
var oldValue = target[key];
// execute the set operation before running any reaction
var result = Reflect.set(target, key, value, receiver);
// emit a warning and do not queue anything when another reaction is queued
// from an already running reaction
if (hasRunningReaction()) {
console.error("Mutating observables in reactions is forbidden. You set " + key + " to " + value + ".");
return result;
}
// do not queue reactions if it is a symbol keyed property
// or the target of the operation is not the raw receiver
// (possible because of prototypal inheritance)
if ((typeof key === "undefined" ? "undefined" : _typeof(key)) === 'symbol' || target !== proxyToRaw.get(receiver)) {
return result;
}
// queue a reaction if it's a new property or its value changed
if (!hadKey) {
queueReactionsForOperation({ target: target, key: key, value: value, receiver: receiver, type: 'add' });
} else if (value !== oldValue) {
queueReactionsForOperation({
target: target,
key: key,
value: value,
oldValue: oldValue,
receiver: receiver,
type: 'set'
});
}
return result;
}
function deleteProperty(target, key) {
// save if the object had the key
var hadKey = hasOwnProperty$1.call(target, key);
var oldValue = target[key];
// execute the delete operation before running any reaction
var result = Reflect.deleteProperty(target, key);
// only queue reactions for non symbol keyed property delete which resulted in an actual change
if ((typeof key === "undefined" ? "undefined" : _typeof(key)) !== 'symbol' && hadKey) {
queueReactionsForOperation({ target: target, key: key, oldValue: oldValue, type: 'delete' });
}
return result;
}
var baseHandlers = { get: get, has: has, ownKeys: ownKeys, set: set, deleteProperty: deleteProperty };
function observable(obj) {
if (obj === void 0) obj = {};
// if it is already an observable or it should not be wrapped, return it
if (proxyToRaw.has(obj) || !shouldInstrument(obj)) {
return obj;
}
// if it already has a cached observable wrapper, return it
// otherwise create a new observable
return rawToProxy.get(obj) || createObservable(obj);
}
function createObservable(obj) {
// if it is a complex built-in object or a normal object, wrap it
var handlers = getHandlers(obj) || baseHandlers;
var observable = new Proxy(obj, handlers);
// save these to switch between the raw object and the wrapped object with ease later
rawToProxy.set(obj, observable);
proxyToRaw.set(observable, obj);
// init basic data structures to save and cleanup later (observable.prop -> reaction) connections
storeObservable(obj);
return observable;
}
function isObservable(obj) {
return proxyToRaw.has(obj);
}
function raw(obj) {
return proxyToRaw.get(obj) || obj;
}
exports.observe = observe;
exports.unobserve = unobserve;
exports.observable = observable;
exports.isObservable = isObservable;
exports.raw = raw;
}, {}], 6: [function (require, module, exports) {
(function (global) {
var topLevel = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
var minDoc = require('min-document');
var doccy;
if (typeof document !== 'undefined') {
doccy = document;
} else {
doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'];
if (!doccy) {
doccy = topLevel['__GLOBAL_DOCUMENT_CACHE@4'] = minDoc;
}
}
module.exports = doccy;
}).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
}, { "min-document": 1 }], 7: [function (require, module, exports) {
(function (global) {
var win;
if (typeof window !== "undefined") {
win = window;
} else if (typeof global !== "undefined") {
win = global;
} else if (typeof self !== "undefined") {
win = self;
} else {
win = {};
}
module.exports = win;
}).call(this, typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {});
}, {}], 8: [function (require, module, exports) {
assert.notEqual = notEqual;
assert.notOk = notOk;
assert.equal = equal;
assert.ok = assert;
module.exports = assert;
function equal(a, b, m) {
assert(a == b, m); // eslint-disable-line eqeqeq
}
function notEqual(a, b, m) {
assert(a != b, m); // eslint-disable-line eqeqeq
}
function notOk(t, m) {
assert(!t, m);
}
function assert(t, m) {
if (!t) throw new Error(m || 'AssertionError');
}
}, {}], 9: [function (require, module, exports) {
var assert = require('assert');
var morph = require('./lib/morph');
var TEXT_NODE = 3;
// var DEBUG = false
module.exports = nanomorph;
// Morph one tree into another tree
//
// no parent
// -> same: diff and walk children
// -> not same: replace and return
// old node doesn't exist
// -> insert new node
// new node doesn't exist
// -> delete old node
// nodes are not the same
// -> diff nodes and apply patch to old node
// nodes are the same
// -> walk all child nodes and append to old node
function nanomorph(oldTree, newTree) {
// if (DEBUG) {
// console.log(
// 'nanomorph\nold\n %s\nnew\n %s',
// oldTree && oldTree.outerHTML,
// newTree && newTree.outerHTML
// )
// }
assert.equal(typeof oldTree === "undefined" ? "undefined" : _typeof(oldTree), 'object', 'nanomorph: oldTree should be an object');
assert.equal(typeof newTree === "undefined" ? "undefined" : _typeof(newTree), 'object', 'nanomorph: newTree should be an object');
var tree = walk(newTree, oldTree);
// if (DEBUG) console.log('=> morphed\n %s', tree.outerHTML)
return tree;
}
// Walk and morph a dom tree
function walk(newNode, oldNode) {
// if (DEBUG) {
// console.log(
// 'walk\nold\n %s\nnew\n %s',
// oldNode && oldNode.outerHTML,
// newNode && newNode.outerHTML
// )
// }
if (!oldNode) {
return newNode;
} else if (!newNode) {
return null;
} else if (newNode.isSameNode && newNode.isSameNode(oldNode)) {
return oldNode;
} else if (newNode.tagName !== oldNode.tagName) {
return newNode;
} else {
morph(newNode, oldNode);
updateChildren(newNode, oldNode);
return oldNode;
}
}
// Update the children of elements
// (obj, obj) -> null
function updateChildren(newNode, oldNode) {
// if (DEBUG) {
// console.log(
// 'updateChildren\nold\n %s\nnew\n %s',
// oldNode && oldNode.outerHTML,
// newNode && newNode.outerHTML
// )
// }
var oldChild, newChild, morphed, oldMatch;
// The offset is only ever increased, and used for [i - offset] in the loop
var offset = 0;
for (var i = 0;; i++) {
oldChild = oldNode.childNodes[i];
newChild = newNode.childNodes[i - offset];
// if (DEBUG) {
// console.log(
// '===\n- old\n %s\n- new\n %s',
// oldChild && oldChild.outerHTML,
// newChild && newChild.outerHTML
// )
// }
// Both nodes are empty, do nothing
if (!oldChild && !newChild) {
break;
// There is no new child, remove old
} else if (!newChild) {
oldNode.removeChild(oldChild);
i--;
// There is no old child, add new
} else if (!oldChild) {
oldNode.appendChild(newChild);
offset++;
// Both nodes are the same, morph
} else if (same(newChild, oldChild)) {
morphed = walk(newChild, oldChild);
if (morphed !== oldChild) {
oldNode.replaceChild(morphed, oldChild);
offset++;
}
// Both nodes do not share an ID or a placeholder, try reorder
} else {
oldMatch = null;
// Try and find a similar node somewhere in the tree