aberdeen 1.0.13 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -5
- package/dist/aberdeen.d.ts +58 -100
- package/dist/aberdeen.js +201 -184
- package/dist/aberdeen.js.map +3 -3
- package/dist/dispatcher.d.ts +54 -0
- package/dist/dispatcher.js +65 -0
- package/dist/dispatcher.js.map +10 -0
- package/dist/route.d.ts +79 -30
- package/dist/route.js +162 -135
- package/dist/route.js.map +3 -3
- package/dist-min/aberdeen.js +5 -5
- package/dist-min/aberdeen.js.map +3 -3
- package/dist-min/dispatcher.js +4 -0
- package/dist-min/dispatcher.js.map +10 -0
- package/dist-min/route.js +2 -2
- package/dist-min/route.js.map +3 -3
- package/package.json +6 -1
- package/src/aberdeen.ts +303 -349
- package/src/dispatcher.ts +130 -0
- package/src/route.ts +272 -181
package/dist/aberdeen.js
CHANGED
|
@@ -194,7 +194,7 @@ class ContentScope extends Scope {
|
|
|
194
194
|
getInsertAfterNode() {
|
|
195
195
|
return this.getLastNode() || this.getPrecedingNode();
|
|
196
196
|
}
|
|
197
|
-
onChange(
|
|
197
|
+
onChange() {
|
|
198
198
|
queue(this);
|
|
199
199
|
}
|
|
200
200
|
getChildPrevSibling() {
|
|
@@ -336,32 +336,6 @@ class SetArgScope extends ChainedScope {
|
|
|
336
336
|
currentScope = savedScope;
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
var immediateQueue = new ReverseSortedSet("prio");
|
|
340
|
-
|
|
341
|
-
class ImmediateScope extends RegularScope {
|
|
342
|
-
onChange(index, newData, oldData) {
|
|
343
|
-
immediateQueue.add(this);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
var immediateQueueRunning = false;
|
|
347
|
-
function runImmediateQueue() {
|
|
348
|
-
for (let count = 0;!immediateQueue.isEmpty() && !immediateQueueRunning; count++) {
|
|
349
|
-
if (count > 42) {
|
|
350
|
-
immediateQueue.clear();
|
|
351
|
-
throw new Error("Too many immediate-mode recursive updates");
|
|
352
|
-
}
|
|
353
|
-
immediateQueueRunning = true;
|
|
354
|
-
const copy = immediateQueue;
|
|
355
|
-
immediateQueue = new ReverseSortedSet("prio");
|
|
356
|
-
try {
|
|
357
|
-
for (const scope of copy) {
|
|
358
|
-
scope.queueRun();
|
|
359
|
-
}
|
|
360
|
-
} finally {
|
|
361
|
-
immediateQueueRunning = false;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
339
|
|
|
366
340
|
class OnEachScope extends Scope {
|
|
367
341
|
renderer;
|
|
@@ -383,22 +357,18 @@ class OnEachScope extends Scope {
|
|
|
383
357
|
currentScope.cleaners.push(this);
|
|
384
358
|
if (target instanceof Array) {
|
|
385
359
|
for (let i = 0;i < target.length; i++) {
|
|
386
|
-
|
|
387
|
-
new OnEachItemScope(this, i, false);
|
|
388
|
-
}
|
|
360
|
+
new OnEachItemScope(this, i, false);
|
|
389
361
|
}
|
|
390
362
|
} else {
|
|
391
|
-
for (const
|
|
392
|
-
|
|
393
|
-
new OnEachItemScope(this, key, false);
|
|
394
|
-
}
|
|
363
|
+
for (const key of target instanceof Map ? target.keys() : Object.keys(target)) {
|
|
364
|
+
new OnEachItemScope(this, key, false);
|
|
395
365
|
}
|
|
396
366
|
}
|
|
397
367
|
}
|
|
398
368
|
getPrecedingNode() {
|
|
399
369
|
return findLastNodeInPrevSiblings(this.prevSibling);
|
|
400
370
|
}
|
|
401
|
-
onChange(index
|
|
371
|
+
onChange(index) {
|
|
402
372
|
if (!(this.target instanceof Array) || typeof index === "number")
|
|
403
373
|
this.changedIndexes.add(index);
|
|
404
374
|
queue(this);
|
|
@@ -410,16 +380,10 @@ class OnEachScope extends Scope {
|
|
|
410
380
|
const oldScope = this.byIndex.get(index);
|
|
411
381
|
if (oldScope)
|
|
412
382
|
oldScope.remove();
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
hasValue = this.target.has(index);
|
|
383
|
+
if (this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
|
|
384
|
+
new OnEachItemScope(this, index, true);
|
|
416
385
|
} else {
|
|
417
|
-
hasValue = this.target[index] !== undefined;
|
|
418
|
-
}
|
|
419
|
-
if (!hasValue) {
|
|
420
386
|
this.byIndex.delete(index);
|
|
421
|
-
} else {
|
|
422
|
-
new OnEachItemScope(this, index, true);
|
|
423
387
|
}
|
|
424
388
|
}
|
|
425
389
|
topRedrawScope = undefined;
|
|
@@ -553,6 +517,15 @@ function addNode(node) {
|
|
|
553
517
|
}
|
|
554
518
|
var ROOT_SCOPE = new RootScope;
|
|
555
519
|
var currentScope = ROOT_SCOPE;
|
|
520
|
+
function leakScope(func) {
|
|
521
|
+
const savedScope = currentScope;
|
|
522
|
+
currentScope = new RootScope;
|
|
523
|
+
try {
|
|
524
|
+
return func();
|
|
525
|
+
} finally {
|
|
526
|
+
currentScope = savedScope;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
556
529
|
var ANY_SYMBOL = Symbol("any");
|
|
557
530
|
var TARGET_SYMBOL = Symbol("target");
|
|
558
531
|
var MAP_SIZE_SYMBOL = Symbol("mapSize");
|
|
@@ -587,10 +560,11 @@ function onEach(target, render, makeKey) {
|
|
|
587
560
|
new OnEachScope(target, render, makeKey);
|
|
588
561
|
}
|
|
589
562
|
function isObjEmpty(obj) {
|
|
590
|
-
for (const k
|
|
563
|
+
for (const k of Object.keys(obj))
|
|
591
564
|
return false;
|
|
592
565
|
return true;
|
|
593
566
|
}
|
|
567
|
+
var EMPTY = Symbol("empty");
|
|
594
568
|
function isEmpty(proxied) {
|
|
595
569
|
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
596
570
|
const scope = currentScope;
|
|
@@ -610,7 +584,7 @@ function isEmpty(proxied) {
|
|
|
610
584
|
}
|
|
611
585
|
const result = isObjEmpty(target);
|
|
612
586
|
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
613
|
-
if (result ? oldData ===
|
|
587
|
+
if (result ? oldData === EMPTY : newData === EMPTY)
|
|
614
588
|
queue(scope);
|
|
615
589
|
});
|
|
616
590
|
return result;
|
|
@@ -622,14 +596,14 @@ function count(proxied) {
|
|
|
622
596
|
return ref(proxied, "size");
|
|
623
597
|
const target = proxied[TARGET_SYMBOL] || proxied;
|
|
624
598
|
let cnt = 0;
|
|
625
|
-
for (const k
|
|
599
|
+
for (const k of Object.keys(target))
|
|
626
600
|
if (target[k] !== undefined)
|
|
627
601
|
cnt++;
|
|
628
602
|
const result = proxy(cnt);
|
|
629
603
|
subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
|
|
630
|
-
if (oldData === newData) {} else if (oldData ===
|
|
604
|
+
if (oldData === newData) {} else if (oldData === EMPTY)
|
|
631
605
|
result.value = ++cnt;
|
|
632
|
-
else if (newData ===
|
|
606
|
+
else if (newData === EMPTY)
|
|
633
607
|
result.value = --cnt;
|
|
634
608
|
});
|
|
635
609
|
return result;
|
|
@@ -647,7 +621,7 @@ function defaultEmitHandler(target, index, newData, oldData) {
|
|
|
647
621
|
if (typeof observer === "function")
|
|
648
622
|
observer(index, newData, oldData);
|
|
649
623
|
else
|
|
650
|
-
observer.onChange(index
|
|
624
|
+
observer.onChange(index);
|
|
651
625
|
}
|
|
652
626
|
}
|
|
653
627
|
}
|
|
@@ -663,25 +637,22 @@ var objectHandler = {
|
|
|
663
637
|
set(target, prop, newData) {
|
|
664
638
|
if (typeof newData === "object" && newData)
|
|
665
639
|
newData = newData[TARGET_SYMBOL] || newData;
|
|
666
|
-
const oldData = target[prop];
|
|
640
|
+
const oldData = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
|
|
667
641
|
if (newData !== oldData) {
|
|
668
642
|
target[prop] = newData;
|
|
669
643
|
emit(target, prop, newData, oldData);
|
|
670
|
-
runImmediateQueue();
|
|
671
644
|
}
|
|
672
645
|
return true;
|
|
673
646
|
},
|
|
674
647
|
deleteProperty(target, prop) {
|
|
675
|
-
const old = target[prop];
|
|
648
|
+
const old = target.hasOwnProperty(prop) ? target[prop] : undefined;
|
|
676
649
|
delete target[prop];
|
|
677
|
-
emit(target, prop,
|
|
678
|
-
runImmediateQueue();
|
|
650
|
+
emit(target, prop, EMPTY, old);
|
|
679
651
|
return true;
|
|
680
652
|
},
|
|
681
653
|
has(target, prop) {
|
|
682
|
-
const result = prop in target;
|
|
683
654
|
subscribe(target, prop);
|
|
684
|
-
return
|
|
655
|
+
return target.hasOwnProperty(prop);
|
|
685
656
|
},
|
|
686
657
|
ownKeys(target) {
|
|
687
658
|
subscribe(target, ANY_SYMBOL);
|
|
@@ -689,27 +660,31 @@ var objectHandler = {
|
|
|
689
660
|
}
|
|
690
661
|
};
|
|
691
662
|
function arraySet(target, prop, newData) {
|
|
692
|
-
if (typeof newData === "object" && newData)
|
|
663
|
+
if (typeof newData === "object" && newData) {
|
|
693
664
|
newData = newData[TARGET_SYMBOL] || newData;
|
|
694
|
-
|
|
665
|
+
}
|
|
666
|
+
let oldData = target[prop];
|
|
667
|
+
if (oldData === undefined && !target.hasOwnProperty(prop))
|
|
668
|
+
oldData = EMPTY;
|
|
695
669
|
if (newData !== oldData) {
|
|
696
670
|
const oldLength = target.length;
|
|
697
671
|
if (prop === "length") {
|
|
698
672
|
target.length = newData;
|
|
699
673
|
for (let i = newData;i < oldLength; i++) {
|
|
700
|
-
emit(target, i,
|
|
674
|
+
emit(target, i, EMPTY, target[i]);
|
|
701
675
|
}
|
|
702
676
|
} else {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
prop
|
|
677
|
+
if (typeof prop === "string") {
|
|
678
|
+
const n = 0 | prop;
|
|
679
|
+
if (String(n) === prop && n >= 0)
|
|
680
|
+
prop = n;
|
|
681
|
+
}
|
|
706
682
|
target[prop] = newData;
|
|
707
683
|
emit(target, prop, newData, oldData);
|
|
708
684
|
}
|
|
709
685
|
if (target.length !== oldLength) {
|
|
710
686
|
emit(target, "length", target.length, oldLength);
|
|
711
687
|
}
|
|
712
|
-
runImmediateQueue();
|
|
713
688
|
}
|
|
714
689
|
return true;
|
|
715
690
|
}
|
|
@@ -717,18 +692,27 @@ var arrayHandler = {
|
|
|
717
692
|
get(target, prop) {
|
|
718
693
|
if (prop === TARGET_SYMBOL)
|
|
719
694
|
return target;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
subProp = intProp;
|
|
695
|
+
if (typeof prop === "string") {
|
|
696
|
+
const n = 0 | prop;
|
|
697
|
+
if (String(n) === prop && n >= 0)
|
|
698
|
+
prop = n;
|
|
725
699
|
}
|
|
726
|
-
subscribe(target,
|
|
700
|
+
subscribe(target, prop);
|
|
727
701
|
return optProxy(target[prop]);
|
|
728
702
|
},
|
|
729
703
|
set: arraySet,
|
|
730
704
|
deleteProperty(target, prop) {
|
|
731
|
-
|
|
705
|
+
if (typeof prop === "string") {
|
|
706
|
+
const n = 0 | prop;
|
|
707
|
+
if (String(n) === prop && n >= 0)
|
|
708
|
+
prop = n;
|
|
709
|
+
}
|
|
710
|
+
let oldData = target[prop];
|
|
711
|
+
if (oldData === undefined && !target.hasOwnProperty(prop))
|
|
712
|
+
oldData = EMPTY;
|
|
713
|
+
delete target[prop];
|
|
714
|
+
emit(target, prop, EMPTY, oldData);
|
|
715
|
+
return true;
|
|
732
716
|
}
|
|
733
717
|
};
|
|
734
718
|
function wrapIteratorSingle(iterator) {
|
|
@@ -773,30 +757,35 @@ var mapMethodHandlers = {
|
|
|
773
757
|
},
|
|
774
758
|
set(key, newData) {
|
|
775
759
|
const target = this[TARGET_SYMBOL];
|
|
776
|
-
if (typeof key === "object" && key)
|
|
760
|
+
if (typeof key === "object" && key) {
|
|
777
761
|
key = key[TARGET_SYMBOL] || key;
|
|
778
|
-
|
|
762
|
+
}
|
|
763
|
+
if (typeof newData === "object" && newData) {
|
|
779
764
|
newData = newData[TARGET_SYMBOL] || newData;
|
|
780
|
-
|
|
765
|
+
}
|
|
766
|
+
let oldData = target.get(key);
|
|
767
|
+
if (oldData === undefined && !target.has(key))
|
|
768
|
+
oldData = EMPTY;
|
|
781
769
|
if (newData !== oldData) {
|
|
782
770
|
const oldSize = target.size;
|
|
783
771
|
target.set(key, newData);
|
|
784
772
|
emit(target, key, newData, oldData);
|
|
785
773
|
emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
|
|
786
|
-
runImmediateQueue();
|
|
787
774
|
}
|
|
788
775
|
return this;
|
|
789
776
|
},
|
|
790
777
|
delete(key) {
|
|
791
778
|
const target = this[TARGET_SYMBOL];
|
|
792
|
-
if (typeof key === "object" && key)
|
|
779
|
+
if (typeof key === "object" && key) {
|
|
793
780
|
key = key[TARGET_SYMBOL] || key;
|
|
794
|
-
|
|
781
|
+
}
|
|
782
|
+
let oldData = target.get(key);
|
|
783
|
+
if (oldData === undefined && !target.has(key))
|
|
784
|
+
oldData = EMPTY;
|
|
795
785
|
const result = target.delete(key);
|
|
796
786
|
if (result) {
|
|
797
|
-
emit(target, key,
|
|
787
|
+
emit(target, key, EMPTY, oldData);
|
|
798
788
|
emit(target, MAP_SIZE_SYMBOL, target.size, target.size + 1);
|
|
799
|
-
runImmediateQueue();
|
|
800
789
|
}
|
|
801
790
|
return result;
|
|
802
791
|
},
|
|
@@ -804,17 +793,16 @@ var mapMethodHandlers = {
|
|
|
804
793
|
const target = this[TARGET_SYMBOL];
|
|
805
794
|
const oldSize = target.size;
|
|
806
795
|
for (const key of target.keys()) {
|
|
807
|
-
|
|
808
|
-
emit(target, key, undefined, oldData);
|
|
796
|
+
emit(target, key, undefined, target.get(key));
|
|
809
797
|
}
|
|
810
798
|
target.clear();
|
|
811
799
|
emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
|
|
812
|
-
runImmediateQueue();
|
|
813
800
|
},
|
|
814
801
|
has(key) {
|
|
815
802
|
const target = this[TARGET_SYMBOL];
|
|
816
|
-
if (typeof key === "object" && key)
|
|
803
|
+
if (typeof key === "object" && key) {
|
|
817
804
|
key = key[TARGET_SYMBOL] || key;
|
|
805
|
+
}
|
|
818
806
|
subscribe(target, key);
|
|
819
807
|
return target.has(key);
|
|
820
808
|
},
|
|
@@ -843,15 +831,14 @@ var mapHandler = {
|
|
|
843
831
|
get(target, prop) {
|
|
844
832
|
if (prop === TARGET_SYMBOL)
|
|
845
833
|
return target;
|
|
846
|
-
if (prop
|
|
834
|
+
if (mapMethodHandlers.hasOwnProperty(prop)) {
|
|
847
835
|
return mapMethodHandlers[prop];
|
|
848
836
|
}
|
|
849
837
|
if (prop === "size") {
|
|
850
838
|
subscribe(target, MAP_SIZE_SYMBOL);
|
|
851
839
|
return target.size;
|
|
852
840
|
}
|
|
853
|
-
|
|
854
|
-
return optProxy(target[prop]);
|
|
841
|
+
return target[prop];
|
|
855
842
|
}
|
|
856
843
|
};
|
|
857
844
|
var proxyMap = new WeakMap;
|
|
@@ -886,31 +873,31 @@ function destroyWithClass(element, cls) {
|
|
|
886
873
|
element.classList.add(...classes);
|
|
887
874
|
setTimeout(() => element.remove(), 2000);
|
|
888
875
|
}
|
|
889
|
-
function copy(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
var MERGE = 1;
|
|
894
|
-
var SHALLOW = 2;
|
|
895
|
-
var COPY_SUBSCRIBE = 32;
|
|
896
|
-
var COPY_EMIT = 64;
|
|
897
|
-
function clone(src, flags = 0) {
|
|
898
|
-
let dst;
|
|
899
|
-
if (src instanceof Map) {
|
|
900
|
-
dst = new Map;
|
|
901
|
-
} else {
|
|
902
|
-
dst = Object.create(Object.getPrototypeOf(src));
|
|
903
|
-
}
|
|
904
|
-
copyRecurse(dst, src, flags);
|
|
905
|
-
return dst;
|
|
876
|
+
function copy(a, b, c) {
|
|
877
|
+
if (arguments.length > 2)
|
|
878
|
+
return copySet(a, b, c, 0);
|
|
879
|
+
return copyRecursive(a, b, 0);
|
|
906
880
|
}
|
|
907
|
-
function
|
|
908
|
-
|
|
881
|
+
function copySet(dst, dstKey, src, flags) {
|
|
882
|
+
let dstVal = peek(dst, dstKey);
|
|
883
|
+
if (src === dstVal)
|
|
884
|
+
return false;
|
|
885
|
+
if (typeof dstVal === "object" && dstVal && typeof src === "object" && src && dstVal.constructor === src.constructor) {
|
|
886
|
+
return copyRecursive(dstVal, src, flags);
|
|
887
|
+
}
|
|
888
|
+
src = clone(src);
|
|
889
|
+
if (dst instanceof Map)
|
|
890
|
+
dst.set(dstKey, src);
|
|
891
|
+
else
|
|
892
|
+
dst[dstKey] = clone(src);
|
|
893
|
+
return true;
|
|
909
894
|
}
|
|
910
|
-
function
|
|
911
|
-
|
|
895
|
+
function merge(a, b, c) {
|
|
896
|
+
if (arguments.length > 2)
|
|
897
|
+
return copySet(a, b, c, MERGE);
|
|
898
|
+
return copyRecursive(a, b, MERGE);
|
|
912
899
|
}
|
|
913
|
-
function
|
|
900
|
+
function copyRecursive(dst, src, flags) {
|
|
914
901
|
let unproxied = dst[TARGET_SYMBOL];
|
|
915
902
|
if (unproxied) {
|
|
916
903
|
dst = unproxied;
|
|
@@ -924,87 +911,122 @@ function copyRecurse(dst, src, flags) {
|
|
|
924
911
|
}
|
|
925
912
|
if (flags & COPY_SUBSCRIBE)
|
|
926
913
|
subscribe(src, ANY_SYMBOL);
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
throw new Error("Cannot copy array into object");
|
|
914
|
+
let changed = false;
|
|
915
|
+
if (src instanceof Array && dst instanceof Array) {
|
|
930
916
|
const dstLen = dst.length;
|
|
931
917
|
const srcLen = src.length;
|
|
932
|
-
for (let
|
|
933
|
-
|
|
918
|
+
for (let index = 0;index < srcLen; index++) {
|
|
919
|
+
let dstValue = dst[index];
|
|
920
|
+
if (dstValue === undefined && !dst.hasOwnProperty(index))
|
|
921
|
+
dstValue = EMPTY;
|
|
922
|
+
let srcValue = src[index];
|
|
923
|
+
if (srcValue === undefined && !src.hasOwnProperty(index)) {
|
|
924
|
+
delete dst[index];
|
|
925
|
+
if (flags & COPY_EMIT)
|
|
926
|
+
emit(dst, index, EMPTY, dstValue);
|
|
927
|
+
changed = true;
|
|
928
|
+
} else if (dstValue !== srcValue) {
|
|
929
|
+
if (srcValue && typeof srcValue === "object") {
|
|
930
|
+
if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
|
|
931
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
932
|
+
continue;
|
|
933
|
+
}
|
|
934
|
+
srcValue = clone(srcValue);
|
|
935
|
+
}
|
|
936
|
+
dst[index] = srcValue;
|
|
937
|
+
if (flags & COPY_EMIT)
|
|
938
|
+
emit(dst, index, srcValue, dstValue);
|
|
939
|
+
changed = true;
|
|
940
|
+
}
|
|
934
941
|
}
|
|
935
942
|
if (srcLen !== dstLen) {
|
|
936
943
|
if (flags & COPY_EMIT) {
|
|
937
944
|
for (let i = srcLen;i < dstLen; i++) {
|
|
938
945
|
const old = dst[i];
|
|
939
|
-
dst[i]
|
|
940
|
-
emit(dst, i,
|
|
946
|
+
delete dst[i];
|
|
947
|
+
emit(dst, i, EMPTY, old);
|
|
941
948
|
}
|
|
942
949
|
dst.length = srcLen;
|
|
943
950
|
emit(dst, "length", srcLen, dstLen);
|
|
944
951
|
} else {
|
|
945
952
|
dst.length = srcLen;
|
|
946
953
|
}
|
|
954
|
+
changed = true;
|
|
947
955
|
}
|
|
948
|
-
} else {
|
|
949
|
-
for (const
|
|
950
|
-
|
|
956
|
+
} else if (src instanceof Map && dst instanceof Map) {
|
|
957
|
+
for (const key of src.keys()) {
|
|
958
|
+
let srcValue = src.get(key);
|
|
959
|
+
let dstValue = dst.get(key);
|
|
960
|
+
if (dstValue === undefined && !dst.has(key))
|
|
961
|
+
dstValue = EMPTY;
|
|
962
|
+
if (dstValue !== srcValue) {
|
|
963
|
+
if (srcValue && typeof srcValue === "object") {
|
|
964
|
+
if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
|
|
965
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
srcValue = clone(srcValue);
|
|
969
|
+
}
|
|
970
|
+
dst.set(key, srcValue);
|
|
971
|
+
if (flags & COPY_EMIT)
|
|
972
|
+
emit(dst, key, srcValue, dstValue);
|
|
973
|
+
changed = true;
|
|
974
|
+
}
|
|
951
975
|
}
|
|
952
976
|
if (!(flags & MERGE)) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
977
|
+
for (const k of dst.keys()) {
|
|
978
|
+
if (!src.has(k)) {
|
|
979
|
+
const old = dst.get(k);
|
|
980
|
+
dst.delete(k);
|
|
981
|
+
if (flags & COPY_EMIT) {
|
|
982
|
+
emit(dst, k, undefined, old);
|
|
957
983
|
}
|
|
984
|
+
changed = true;
|
|
958
985
|
}
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
} else if (src.constructor === dst.constructor) {
|
|
989
|
+
for (const key of Object.keys(src)) {
|
|
990
|
+
let srcValue = src[key];
|
|
991
|
+
const dstValue = dst.hasOwnProperty(key) ? dst[key] : EMPTY;
|
|
992
|
+
if (dstValue !== srcValue) {
|
|
993
|
+
if (srcValue && typeof srcValue === "object") {
|
|
994
|
+
if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
|
|
995
|
+
changed = copyRecursive(dstValue, srcValue, flags) || changed;
|
|
996
|
+
continue;
|
|
963
997
|
}
|
|
998
|
+
srcValue = clone(srcValue);
|
|
999
|
+
}
|
|
1000
|
+
dst[key] = srcValue;
|
|
1001
|
+
if (flags & COPY_EMIT)
|
|
1002
|
+
emit(dst, key, srcValue, dstValue);
|
|
1003
|
+
changed = true;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
if (!(flags & MERGE)) {
|
|
1007
|
+
for (const k of Object.keys(dst)) {
|
|
1008
|
+
if (!src.hasOwnProperty(k)) {
|
|
1009
|
+
const old = dst[k];
|
|
1010
|
+
delete dst[k];
|
|
1011
|
+
if (flags & COPY_EMIT && old !== undefined) {
|
|
1012
|
+
emit(dst, k, undefined, old);
|
|
1013
|
+
}
|
|
1014
|
+
changed = true;
|
|
964
1015
|
}
|
|
965
1016
|
}
|
|
966
1017
|
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
function deleteKey(dst, key, flags) {
|
|
970
|
-
let old;
|
|
971
|
-
if (dst instanceof Map) {
|
|
972
|
-
old = dst.get(key);
|
|
973
|
-
dst.delete(key);
|
|
974
1018
|
} else {
|
|
975
|
-
|
|
976
|
-
delete dst[key];
|
|
977
|
-
}
|
|
978
|
-
if (flags & COPY_EMIT && old !== undefined) {
|
|
979
|
-
emit(dst, key, undefined, old);
|
|
1019
|
+
throw new Error(`Incompatible or non-object types: ${src?.constructor?.name || typeof src} vs ${dst?.constructor?.name || typeof dst}`);
|
|
980
1020
|
}
|
|
1021
|
+
return changed;
|
|
981
1022
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
if (!(flags & SHALLOW) && srcValue && typeof srcValue === "object") {
|
|
990
|
-
const copy2 = Object.create(Object.getPrototypeOf(srcValue));
|
|
991
|
-
copyRecurse(copy2, srcValue, 0);
|
|
992
|
-
srcValue = copy2;
|
|
993
|
-
}
|
|
994
|
-
if (dst instanceof Map) {
|
|
995
|
-
if (flags & MERGE && srcValue == null)
|
|
996
|
-
dst.delete(index);
|
|
997
|
-
else
|
|
998
|
-
dst.set(index, srcValue);
|
|
999
|
-
} else {
|
|
1000
|
-
if (flags & MERGE && srcValue == null)
|
|
1001
|
-
delete dst[index];
|
|
1002
|
-
else
|
|
1003
|
-
dst[index] = srcValue;
|
|
1004
|
-
}
|
|
1005
|
-
if (flags & COPY_EMIT)
|
|
1006
|
-
emit(dst, index, srcValue, dstValue);
|
|
1007
|
-
}
|
|
1023
|
+
var MERGE = 1;
|
|
1024
|
+
var COPY_SUBSCRIBE = 32;
|
|
1025
|
+
var COPY_EMIT = 64;
|
|
1026
|
+
function clone(src) {
|
|
1027
|
+
const copied = Array.isArray(src) ? [] : src instanceof Map ? new Map : Object.create(Object.getPrototypeOf(src));
|
|
1028
|
+
copyRecursive(copied, src, MERGE);
|
|
1029
|
+
return copied;
|
|
1008
1030
|
}
|
|
1009
1031
|
var refHandler = {
|
|
1010
1032
|
get(target, prop) {
|
|
@@ -1062,7 +1084,7 @@ function applyBind(el, target) {
|
|
|
1062
1084
|
throw new Error(`SELECT has no '${target.value}' OPTION (yet)`);
|
|
1063
1085
|
};
|
|
1064
1086
|
}
|
|
1065
|
-
|
|
1087
|
+
derive(onProxyChange);
|
|
1066
1088
|
el.addEventListener("input", onInputChange);
|
|
1067
1089
|
clean(() => {
|
|
1068
1090
|
el.removeEventListener("input", onInputChange);
|
|
@@ -1096,11 +1118,6 @@ var SPECIAL_PROPS = {
|
|
|
1096
1118
|
},
|
|
1097
1119
|
text: (value) => {
|
|
1098
1120
|
addNode(document.createTextNode(value));
|
|
1099
|
-
},
|
|
1100
|
-
element: (value) => {
|
|
1101
|
-
console.log("Aberdeen: $({element: myElement}) is deprecated, use $(myElement) instead");
|
|
1102
|
-
addNode(value);
|
|
1103
|
-
SPECIAL_PROPS.element = addNode;
|
|
1104
1121
|
}
|
|
1105
1122
|
};
|
|
1106
1123
|
function $(...args) {
|
|
@@ -1175,7 +1192,7 @@ function $(...args) {
|
|
|
1175
1192
|
break;
|
|
1176
1193
|
}
|
|
1177
1194
|
} else {
|
|
1178
|
-
for (const key
|
|
1195
|
+
for (const key of Object.keys(arg)) {
|
|
1179
1196
|
const val = arg[key];
|
|
1180
1197
|
applyArg(key, val);
|
|
1181
1198
|
}
|
|
@@ -1205,7 +1222,7 @@ function insertCss(style, global = false) {
|
|
|
1205
1222
|
function styleToCss(style, prefix) {
|
|
1206
1223
|
let props = "";
|
|
1207
1224
|
let rules = "";
|
|
1208
|
-
for (const kOr
|
|
1225
|
+
for (const kOr of Object.keys(style)) {
|
|
1209
1226
|
const v = style[kOr];
|
|
1210
1227
|
for (const k of kOr.split(/, ?/g)) {
|
|
1211
1228
|
if (v && typeof v === "object") {
|
|
@@ -1271,12 +1288,9 @@ function getParentElement() {
|
|
|
1271
1288
|
function clean(cleaner) {
|
|
1272
1289
|
currentScope.cleaners.push(cleaner);
|
|
1273
1290
|
}
|
|
1274
|
-
function
|
|
1291
|
+
function derive(func) {
|
|
1275
1292
|
return new ResultScope(currentScope.parentElement, func).result;
|
|
1276
1293
|
}
|
|
1277
|
-
function immediateObserve(func) {
|
|
1278
|
-
new ImmediateScope(currentScope.parentElement, func);
|
|
1279
|
-
}
|
|
1280
1294
|
function mount(parentElement, func) {
|
|
1281
1295
|
new MountScope(parentElement, func);
|
|
1282
1296
|
}
|
|
@@ -1284,10 +1298,14 @@ function unmountAll() {
|
|
|
1284
1298
|
ROOT_SCOPE.remove();
|
|
1285
1299
|
cssCount = 0;
|
|
1286
1300
|
}
|
|
1287
|
-
function peek(
|
|
1301
|
+
function peek(target, key) {
|
|
1288
1302
|
peeking++;
|
|
1289
1303
|
try {
|
|
1290
|
-
|
|
1304
|
+
if (arguments.length === 1) {
|
|
1305
|
+
return target();
|
|
1306
|
+
} else {
|
|
1307
|
+
return target instanceof Map ? target.get(key) : target[key];
|
|
1308
|
+
}
|
|
1291
1309
|
} finally {
|
|
1292
1310
|
peeking--;
|
|
1293
1311
|
}
|
|
@@ -1324,10 +1342,10 @@ function multiMap(source, func) {
|
|
|
1324
1342
|
onEach(source, (item, key) => {
|
|
1325
1343
|
const pairs = func(item, key);
|
|
1326
1344
|
if (pairs) {
|
|
1327
|
-
for (const key2
|
|
1345
|
+
for (const key2 of Object.keys(pairs))
|
|
1328
1346
|
out[key2] = pairs[key2];
|
|
1329
1347
|
clean(() => {
|
|
1330
|
-
for (const key2
|
|
1348
|
+
for (const key2 of Object.keys(pairs))
|
|
1331
1349
|
delete out[key2];
|
|
1332
1350
|
});
|
|
1333
1351
|
}
|
|
@@ -1418,25 +1436,24 @@ export {
|
|
|
1418
1436
|
peek,
|
|
1419
1437
|
partition,
|
|
1420
1438
|
onEach,
|
|
1421
|
-
observe,
|
|
1422
1439
|
multiMap,
|
|
1423
1440
|
mount,
|
|
1441
|
+
merge,
|
|
1424
1442
|
map,
|
|
1443
|
+
leakScope,
|
|
1425
1444
|
isEmpty,
|
|
1426
1445
|
invertString,
|
|
1427
1446
|
insertCss,
|
|
1428
|
-
immediateObserve,
|
|
1429
1447
|
getParentElement,
|
|
1430
1448
|
dump,
|
|
1449
|
+
derive,
|
|
1431
1450
|
defaultEmitHandler,
|
|
1432
1451
|
count,
|
|
1433
1452
|
copy,
|
|
1434
1453
|
clone,
|
|
1435
1454
|
clean,
|
|
1436
|
-
SHALLOW,
|
|
1437
|
-
MERGE,
|
|
1438
1455
|
$
|
|
1439
1456
|
};
|
|
1440
1457
|
|
|
1441
|
-
//# debugId=
|
|
1458
|
+
//# debugId=37C620855881B81F64756E2164756E21
|
|
1442
1459
|
//# sourceMappingURL=aberdeen.js.map
|