aoye 0.0.52 → 0.0.53
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/dist/aoye.cjs.js +204 -7
- package/dist/aoye.cjs.js.map +1 -1
- package/dist/aoye.esm.js +204 -8
- package/dist/aoye.esm.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.umd.js +204 -7
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/aoye.cjs.js
CHANGED
|
@@ -484,7 +484,11 @@ function link(up = null, down = null) {
|
|
|
484
484
|
}
|
|
485
485
|
up.emitTail = line;
|
|
486
486
|
if (recHead) {
|
|
487
|
-
recTail
|
|
487
|
+
if (recTail) {
|
|
488
|
+
recTail.nextRecLine = line;
|
|
489
|
+
} else {
|
|
490
|
+
down.recHead = line;
|
|
491
|
+
}
|
|
488
492
|
} else {
|
|
489
493
|
down.recHead = line;
|
|
490
494
|
}
|
|
@@ -547,7 +551,11 @@ function outLink(up = null, down = null) {
|
|
|
547
551
|
}
|
|
548
552
|
up.emitTail = line;
|
|
549
553
|
if (recHead) {
|
|
550
|
-
recTail
|
|
554
|
+
if (recTail) {
|
|
555
|
+
recTail.nextRecLine = line;
|
|
556
|
+
} else {
|
|
557
|
+
down.recHead = line;
|
|
558
|
+
}
|
|
551
559
|
} else {
|
|
552
560
|
down.recHead = line;
|
|
553
561
|
}
|
|
@@ -750,11 +758,195 @@ State.Unknown | State.Dirty;
|
|
|
750
758
|
State.ScopeReady | State.ScopeAbort;
|
|
751
759
|
State.ScopeAbort;
|
|
752
760
|
|
|
761
|
+
const trackIterator = (cells, scope) => {
|
|
762
|
+
let iter = cells.get(Keys.Iterator);
|
|
763
|
+
if (!iter) {
|
|
764
|
+
iter = new Signal(0);
|
|
765
|
+
iter.scope = scope;
|
|
766
|
+
cells.set(Keys.Iterator, iter);
|
|
767
|
+
}
|
|
768
|
+
iter.get();
|
|
769
|
+
};
|
|
770
|
+
const triggerIterator = (cells, raw) => {
|
|
771
|
+
const iter = cells.get(Keys.Iterator);
|
|
772
|
+
if (iter) {
|
|
773
|
+
iter.set((raw[Keys.Iterator] || 0) + 1);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
const trackKey = (cells, scope, key) => {
|
|
777
|
+
let cell = cells.get(key);
|
|
778
|
+
if (!cell) {
|
|
779
|
+
cell = new Signal(undefined);
|
|
780
|
+
cell.scope = scope;
|
|
781
|
+
cells.set(key, cell);
|
|
782
|
+
}
|
|
783
|
+
cell.get();
|
|
784
|
+
};
|
|
785
|
+
const triggerKey = (cells, key) => {
|
|
786
|
+
const cell = cells.get(key);
|
|
787
|
+
if (cell) {
|
|
788
|
+
cell.set((cell.value === undefined ? 0 : cell.value) + 1);
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
const createSharedHandler = (cells, scope, deep, targetIsMap) => {
|
|
792
|
+
const iterate = (rawTarget, iteratorFn) => {
|
|
793
|
+
trackIterator(cells, scope);
|
|
794
|
+
const rawIter = rawTarget[iteratorFn]();
|
|
795
|
+
if (!deep) return rawIter;
|
|
796
|
+
const rawNext = rawIter.next.bind(rawIter);
|
|
797
|
+
rawIter.next = () => {
|
|
798
|
+
const result = rawNext();
|
|
799
|
+
if (!result.done) {
|
|
800
|
+
if (iteratorFn === 'entries') {
|
|
801
|
+
result.value[0] = deepSignal(result.value[0], scope);
|
|
802
|
+
result.value[1] = deepSignal(result.value[1], scope);
|
|
803
|
+
} else {
|
|
804
|
+
result.value = deepSignal(result.value, scope);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return result;
|
|
808
|
+
};
|
|
809
|
+
return rawIter;
|
|
810
|
+
};
|
|
811
|
+
return {
|
|
812
|
+
has(key) {
|
|
813
|
+
const target = this[Keys.Raw];
|
|
814
|
+
trackKey(cells, scope, key);
|
|
815
|
+
return target.has(key);
|
|
816
|
+
},
|
|
817
|
+
delete(key) {
|
|
818
|
+
const target = this[Keys.Raw];
|
|
819
|
+
batchStart();
|
|
820
|
+
const had = target.has(key);
|
|
821
|
+
const result = target.delete(key);
|
|
822
|
+
if (had) {
|
|
823
|
+
triggerKey(cells, key);
|
|
824
|
+
cells.delete(key);
|
|
825
|
+
triggerIterator(cells, target);
|
|
826
|
+
}
|
|
827
|
+
batchEnd();
|
|
828
|
+
return result;
|
|
829
|
+
},
|
|
830
|
+
clear() {
|
|
831
|
+
const target = this[Keys.Raw];
|
|
832
|
+
batchStart();
|
|
833
|
+
const hadItems = target.size > 0;
|
|
834
|
+
target.clear();
|
|
835
|
+
const iterCell = cells.get(Keys.Iterator);
|
|
836
|
+
cells.clear();
|
|
837
|
+
if (iterCell) cells.set(Keys.Iterator, iterCell);
|
|
838
|
+
if (hadItems) {
|
|
839
|
+
triggerIterator(cells, target);
|
|
840
|
+
}
|
|
841
|
+
batchEnd();
|
|
842
|
+
},
|
|
843
|
+
forEach(callback, thisArg) {
|
|
844
|
+
const target = this[Keys.Raw];
|
|
845
|
+
trackIterator(cells, scope);
|
|
846
|
+
const wrap = val => deep ? deepSignal(val, scope) : val;
|
|
847
|
+
target.forEach((v, k) => {
|
|
848
|
+
callback.call(thisArg, wrap(v), wrap(k), this);
|
|
849
|
+
});
|
|
850
|
+
},
|
|
851
|
+
keys() {
|
|
852
|
+
return iterate(this[Keys.Raw], 'keys');
|
|
853
|
+
},
|
|
854
|
+
values() {
|
|
855
|
+
return iterate(this[Keys.Raw], 'values');
|
|
856
|
+
},
|
|
857
|
+
entries() {
|
|
858
|
+
return iterate(this[Keys.Raw], 'entries');
|
|
859
|
+
},
|
|
860
|
+
[Symbol.iterator]() {
|
|
861
|
+
return iterate(this[Keys.Raw], targetIsMap ? 'entries' : 'values');
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
};
|
|
865
|
+
const createMapHandler = (cells, scope, deep) => ({
|
|
866
|
+
get(key) {
|
|
867
|
+
const target = this[Keys.Raw];
|
|
868
|
+
trackKey(cells, scope, key);
|
|
869
|
+
const value = target.get(key);
|
|
870
|
+
return deep ? deepSignal(value, scope) : value;
|
|
871
|
+
},
|
|
872
|
+
set(key, value) {
|
|
873
|
+
const target = this[Keys.Raw];
|
|
874
|
+
batchStart();
|
|
875
|
+
target.set(key, value);
|
|
876
|
+
let cell = cells.get(key);
|
|
877
|
+
if (!cell) {
|
|
878
|
+
cell = new Signal(value);
|
|
879
|
+
cell.scope = scope;
|
|
880
|
+
cells.set(key, cell);
|
|
881
|
+
} else {
|
|
882
|
+
cell.set(value);
|
|
883
|
+
}
|
|
884
|
+
triggerIterator(cells, target);
|
|
885
|
+
batchEnd();
|
|
886
|
+
return this;
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
const createSetHandler = (cells, scope, _deep) => ({
|
|
890
|
+
add(value) {
|
|
891
|
+
const target = this[Keys.Raw];
|
|
892
|
+
batchStart();
|
|
893
|
+
const had = target.has(value);
|
|
894
|
+
target.add(value);
|
|
895
|
+
let cell = cells.get(value);
|
|
896
|
+
if (!cell) {
|
|
897
|
+
cell = new Signal(value);
|
|
898
|
+
cell.scope = scope;
|
|
899
|
+
cells.set(value, cell);
|
|
900
|
+
} else {
|
|
901
|
+
cell.set(value);
|
|
902
|
+
}
|
|
903
|
+
if (!had) {
|
|
904
|
+
triggerIterator(cells, target);
|
|
905
|
+
}
|
|
906
|
+
batchEnd();
|
|
907
|
+
return this;
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
const mergeHandlers = (...handlers) => Object.assign({}, ...handlers);
|
|
911
|
+
|
|
753
912
|
const deepSignal = (target, scope, deep = true) => {
|
|
754
913
|
const isObj = typeof target === 'object' && target !== null;
|
|
755
914
|
if (!isObj || target[Keys.Raw] || target[Keys.ProxyFreeObject]) return target;
|
|
756
915
|
const p = rawToProxy.get(target);
|
|
757
916
|
if (p) return p;
|
|
917
|
+
const targetIsMap = target instanceof Map;
|
|
918
|
+
const targetIsSet = target instanceof Set;
|
|
919
|
+
if (targetIsMap || targetIsSet) {
|
|
920
|
+
const cells = new Map();
|
|
921
|
+
const meta = {
|
|
922
|
+
deep,
|
|
923
|
+
scope,
|
|
924
|
+
cells
|
|
925
|
+
};
|
|
926
|
+
const shared = createSharedHandler(cells, scope, deep, targetIsMap);
|
|
927
|
+
const specific = targetIsMap ? createMapHandler(cells, scope, deep) : createSetHandler(cells, scope);
|
|
928
|
+
const instrumentations = mergeHandlers(shared, specific);
|
|
929
|
+
const proxy = new Proxy(target, {
|
|
930
|
+
get(_obj, prop, receiver) {
|
|
931
|
+
if (prop === Keys.Raw) return target;
|
|
932
|
+
if (prop === Keys.Meta) return meta;
|
|
933
|
+
if (prop === Symbol.toStringTag) return targetIsMap ? 'Map' : 'Set';
|
|
934
|
+
if (prop === 'size') {
|
|
935
|
+
trackIterator(cells, scope);
|
|
936
|
+
return Reflect.get(target, 'size', target);
|
|
937
|
+
}
|
|
938
|
+
if (prop in instrumentations) {
|
|
939
|
+
const fn = instrumentations[prop];
|
|
940
|
+
return typeof fn === 'function' ? fn.bind(receiver) : fn;
|
|
941
|
+
}
|
|
942
|
+
const value = Reflect.get(target, prop, receiver);
|
|
943
|
+
if (typeof value === 'function') return value;
|
|
944
|
+
return deep ? deepSignal(value, scope) : value;
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
rawToProxy.set(target, proxy);
|
|
948
|
+
return proxy;
|
|
949
|
+
}
|
|
758
950
|
const cells = new Map();
|
|
759
951
|
const targetIsArray = Array.isArray(target);
|
|
760
952
|
const targetIsStore = Boolean(target.constructor?.[IsStore]);
|
|
@@ -803,6 +995,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
803
995
|
if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop) || typeof value === 'function') {
|
|
804
996
|
return Reflect.set(obj, prop, value, receiver);
|
|
805
997
|
}
|
|
998
|
+
const isNewKey = !Reflect.has(obj, prop);
|
|
806
999
|
batchStart();
|
|
807
1000
|
const success = Reflect.set(obj, prop, value, receiver);
|
|
808
1001
|
const cell = cells.get(prop);
|
|
@@ -811,8 +1004,8 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
811
1004
|
}
|
|
812
1005
|
if (targetIsArray) {
|
|
813
1006
|
handleArraySet(obj, prop, value, receiver);
|
|
814
|
-
} else {
|
|
815
|
-
|
|
1007
|
+
} else if (isNewKey) {
|
|
1008
|
+
receiver[Keys.Iterator] = (receiver[Keys.Raw][Keys.Iterator] || 0) + 1;
|
|
816
1009
|
}
|
|
817
1010
|
batchEnd();
|
|
818
1011
|
return success;
|
|
@@ -822,8 +1015,11 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
822
1015
|
return Reflect.deleteProperty(obj, prop);
|
|
823
1016
|
}
|
|
824
1017
|
cells.delete(prop);
|
|
825
|
-
|
|
826
|
-
|
|
1018
|
+
const result = Reflect.deleteProperty(obj, prop);
|
|
1019
|
+
if (!targetIsArray) {
|
|
1020
|
+
proxy[Keys.Iterator] = (obj[Keys.Iterator] || 0) + 1;
|
|
1021
|
+
}
|
|
1022
|
+
return result;
|
|
827
1023
|
},
|
|
828
1024
|
ownKeys(obj) {
|
|
829
1025
|
if (targetIsArray) {
|
|
@@ -831,7 +1027,7 @@ const deepSignal = (target, scope, deep = true) => {
|
|
|
831
1027
|
} else {
|
|
832
1028
|
proxy[Keys.Iterator];
|
|
833
1029
|
}
|
|
834
|
-
return Reflect.ownKeys(obj);
|
|
1030
|
+
return Reflect.ownKeys(obj).filter(key => key !== Keys.Iterator);
|
|
835
1031
|
}
|
|
836
1032
|
});
|
|
837
1033
|
rawToProxy.set(target, proxy);
|
|
@@ -1376,6 +1572,7 @@ exports.Scope = Scope;
|
|
|
1376
1572
|
exports.Signal = Signal;
|
|
1377
1573
|
exports.Store = Store;
|
|
1378
1574
|
exports.StoreIgnoreKeys = StoreIgnoreKeys;
|
|
1575
|
+
exports.batchDeep = batchDeep;
|
|
1379
1576
|
exports.batchEnd = batchEnd;
|
|
1380
1577
|
exports.batchStart = batchStart;
|
|
1381
1578
|
exports.clean = clean;
|