mutts 1.0.14 → 1.0.15
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/browser.cjs +85 -85
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.dev.cjs +81 -81
- package/dist/browser.dev.esm.js +2 -2
- package/dist/browser.esm.js +3 -3
- package/dist/chunks/{proxy-C2lnvvbx.esm.js → effects-CPjf6gNA.esm.js} +2439 -2419
- package/dist/chunks/effects-CPjf6gNA.esm.js.map +1 -0
- package/dist/chunks/{proxy-HA_QQnd5.cjs → effects-oUauWxxl.cjs} +2440 -2420
- package/dist/chunks/effects-oUauWxxl.cjs.map +1 -0
- package/dist/chunks/{index-BnTNC9eC.cjs → index-Dtj2qZ0d.cjs} +291 -291
- package/dist/chunks/{index-BnTNC9eC.cjs.map → index-Dtj2qZ0d.cjs.map} +1 -1
- package/dist/chunks/{index-CAWVZL7P.esm.js → index-YGpb1te7.esm.js} +3 -3
- package/dist/chunks/{index-CAWVZL7P.esm.js.map → index-YGpb1te7.esm.js.map} +1 -1
- package/dist/chunks/{node-Df_5r_WA.cjs → node-CKuro-Uk.cjs} +6 -6
- package/dist/chunks/{node-Df_5r_WA.cjs.map → node-CKuro-Uk.cjs.map} +1 -1
- package/dist/chunks/{node-DuIduHw3.esm.js → node-sQtns7M-.esm.js} +2 -2
- package/dist/chunks/{node-DuIduHw3.esm.js.map → node-sQtns7M-.esm.js.map} +1 -1
- package/dist/debug.cjs +45 -45
- package/dist/debug.cjs.map +1 -1
- package/dist/debug.esm.js +1 -1
- package/dist/mutts.umd.js +3464 -3444
- package/dist/mutts.umd.js.map +1 -1
- package/dist/mutts.umd.min.js +1 -1
- package/dist/mutts.umd.min.js.map +1 -1
- package/dist/node.cjs +82 -82
- package/dist/node.dev.cjs +82 -82
- package/dist/node.dev.esm.js +3 -3
- package/dist/node.esm.js +3 -3
- package/package.json +1 -1
- package/dist/chunks/proxy-C2lnvvbx.esm.js.map +0 -1
- package/dist/chunks/proxy-HA_QQnd5.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var effects = require('./effects-oUauWxxl.cjs');
|
|
4
4
|
|
|
5
5
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
6
6
|
// Integrated with `using` statement via Symbol.dispose
|
|
@@ -83,7 +83,7 @@ function Destroyable(base, destructorObj) {
|
|
|
83
83
|
* Decorator that marks properties to be stored in the allocated object and passed to the destructor
|
|
84
84
|
* Use with accessor properties or explicit get/set pairs
|
|
85
85
|
*/
|
|
86
|
-
const allocated =
|
|
86
|
+
const allocated = effects.decorator({
|
|
87
87
|
setter(original, _target, propertyKey) {
|
|
88
88
|
return function (value) {
|
|
89
89
|
this[allocatedValues][propertyKey] = value;
|
|
@@ -758,7 +758,7 @@ function chainPromise(given) {
|
|
|
758
758
|
return chained;
|
|
759
759
|
}
|
|
760
760
|
|
|
761
|
-
const attend =
|
|
761
|
+
const attend = effects.captioned(function attend(source, callback) {
|
|
762
762
|
const enumerate = typeof source === 'function'
|
|
763
763
|
? source
|
|
764
764
|
: Array.isArray(source)
|
|
@@ -770,7 +770,7 @@ const attend = proxy.captioned(function attend(source, callback) {
|
|
|
770
770
|
: () => Object.keys(source);
|
|
771
771
|
const keyEffects = new Map();
|
|
772
772
|
const callbackLabel = callback.name ? callback.name : '';
|
|
773
|
-
const outer =
|
|
773
|
+
const outer = effects.effect `attend`(({ ascend }) => {
|
|
774
774
|
const keys = new Set();
|
|
775
775
|
for (const key of enumerate())
|
|
776
776
|
keys.add(key);
|
|
@@ -778,7 +778,7 @@ const attend = proxy.captioned(function attend(source, callback) {
|
|
|
778
778
|
if (keyEffects.has(key))
|
|
779
779
|
continue;
|
|
780
780
|
const indexRef = { value: key };
|
|
781
|
-
keyEffects.set(key, ascend(() =>
|
|
781
|
+
keyEffects.set(key, ascend(() => effects.effect `attend${callbackLabel ? `:${callbackLabel}` : ''}:${key}`((access) => callback(indexRef.value, access))));
|
|
782
782
|
}
|
|
783
783
|
for (const key of Array.from(keyEffects.keys())) {
|
|
784
784
|
if (!keys.has(key)) {
|
|
@@ -796,7 +796,7 @@ const attend = proxy.captioned(function attend(source, callback) {
|
|
|
796
796
|
}, {
|
|
797
797
|
name: 'attend',
|
|
798
798
|
callbackIndex: 1,
|
|
799
|
-
warn: (message) =>
|
|
799
|
+
warn: (message) => effects.options.warn(`[reactive] ${message}`),
|
|
800
800
|
});
|
|
801
801
|
/**
|
|
802
802
|
* Lifts a callback that returns an object into a reactive object that automatically
|
|
@@ -826,18 +826,18 @@ const attend = proxy.captioned(function attend(source, callback) {
|
|
|
826
826
|
* @param cb Callback function that returns an object
|
|
827
827
|
* @returns A reactive object synchronized with the callback's result, with a [cleanup] property to stop tracking
|
|
828
828
|
*/
|
|
829
|
-
const lift =
|
|
829
|
+
const lift = effects.captioned(function lift(cb) {
|
|
830
830
|
let result;
|
|
831
831
|
let rawResult;
|
|
832
832
|
const resultName = `lift:${cb.name || 'anonymous'}`;
|
|
833
|
-
const liftCleanup =
|
|
833
|
+
const liftCleanup = effects.effect `lift:${cb.name}`(effects.markWithRoot((access) => {
|
|
834
834
|
const source = cb(access);
|
|
835
835
|
if (!source || typeof source !== 'object')
|
|
836
836
|
throw new Error('lift callback must return an array or object');
|
|
837
837
|
const sourceProto = Object.getPrototypeOf(source);
|
|
838
838
|
if (!result) {
|
|
839
|
-
rawResult =
|
|
840
|
-
result =
|
|
839
|
+
rawResult = effects.tag(resultName, Array.isArray(source) ? [] : Object.create(sourceProto));
|
|
840
|
+
result = effects.reactive(rawResult);
|
|
841
841
|
}
|
|
842
842
|
if (sourceProto !== Object.getPrototypeOf(result))
|
|
843
843
|
throw new Error('lift callback must return the same type as the previous result');
|
|
@@ -858,24 +858,24 @@ const lift = proxy.captioned(function lift(cb) {
|
|
|
858
858
|
if (!sameAccessor &&
|
|
859
859
|
recordResult[key] !==
|
|
860
860
|
(oldDesc ? (oldDesc.get ? oldDesc.get() : oldDesc.value) : undefined))
|
|
861
|
-
|
|
861
|
+
effects.touched1(rawResult, { type: 'set', prop: key }, key);
|
|
862
862
|
}
|
|
863
863
|
else {
|
|
864
864
|
Object.defineProperty(rawResult, key, newDesc);
|
|
865
|
-
|
|
865
|
+
effects.touched1(rawResult, { type: 'add', prop: key }, key);
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
for (const key of Object.keys(rawResult))
|
|
869
869
|
if (!(key in source)) {
|
|
870
870
|
delete recordResult[key];
|
|
871
|
-
|
|
871
|
+
effects.touched1(rawResult, { type: 'del', prop: key }, key);
|
|
872
872
|
}
|
|
873
873
|
}
|
|
874
874
|
}, cb));
|
|
875
|
-
return
|
|
875
|
+
return effects.link(result, liftCleanup);
|
|
876
876
|
}, {
|
|
877
877
|
name: 'lift',
|
|
878
|
-
warn: (message) =>
|
|
878
|
+
warn: (message) => effects.options.warn(`[reactive] ${message}`),
|
|
879
879
|
});
|
|
880
880
|
/**
|
|
881
881
|
* Reactively maps an array source through `fn`, producing a lazy reactive output array.
|
|
@@ -895,22 +895,22 @@ const lift = proxy.captioned(function lift(cb) {
|
|
|
895
895
|
* @returns A readonly reactive array with a `[cleanup]` method to dispose all effects
|
|
896
896
|
*/
|
|
897
897
|
function morphArray(source, fn, options) {
|
|
898
|
-
if (typeof source !== 'function' && !
|
|
898
|
+
if (typeof source !== 'function' && !effects.isReactive(source) && options?.pure === true) {
|
|
899
899
|
return source.map((i) => fn(i, { index: 0 }));
|
|
900
900
|
}
|
|
901
901
|
let track;
|
|
902
902
|
const itemEffects = new Map();
|
|
903
|
-
const cache =
|
|
903
|
+
const cache = effects.tag(`morph:${fn.name || 'anonymous'}`, []);
|
|
904
904
|
let input = [];
|
|
905
905
|
function currentCleanupReason() {
|
|
906
|
-
const activeEffect =
|
|
906
|
+
const activeEffect = effects.getActiveEffect();
|
|
907
907
|
if (!activeEffect)
|
|
908
908
|
return undefined;
|
|
909
|
-
const node =
|
|
909
|
+
const node = effects.getEffectNode(activeEffect);
|
|
910
910
|
return node.currentReason;
|
|
911
911
|
}
|
|
912
912
|
function stopEntry(entry) {
|
|
913
|
-
entry.stop(
|
|
913
|
+
entry.stop(effects.chainExternalReason({ type: 'stopped', chain: currentCleanupReason() }));
|
|
914
914
|
}
|
|
915
915
|
function stopItem(key) {
|
|
916
916
|
const entry = itemEffects.get(key);
|
|
@@ -927,23 +927,23 @@ function morphArray(source, fn, options) {
|
|
|
927
927
|
});
|
|
928
928
|
}
|
|
929
929
|
else {
|
|
930
|
-
const position =
|
|
931
|
-
const stop = track(() =>
|
|
930
|
+
const position = effects.reactive({ index: key });
|
|
931
|
+
const stop = track(() => effects.effect.opaque `morph:${fn.name}:${key}`((access) => {
|
|
932
932
|
if (access.reaction) {
|
|
933
933
|
delete cache[position.index];
|
|
934
|
-
|
|
935
|
-
const activeEffect =
|
|
934
|
+
effects.touched1(cache, { type: 'invalidate', prop: 'morph' }, String(key));
|
|
935
|
+
const activeEffect = effects.getActiveEffect();
|
|
936
936
|
let chain;
|
|
937
937
|
if (activeEffect) {
|
|
938
|
-
const node =
|
|
938
|
+
const node = effects.getEffectNode(activeEffect);
|
|
939
939
|
chain = node.currentReason;
|
|
940
940
|
}
|
|
941
941
|
stop?.({
|
|
942
942
|
type: 'invalidate',
|
|
943
|
-
cause:
|
|
943
|
+
cause: effects.chainExternalReason(!access.reaction || access.reaction === true
|
|
944
944
|
? { type: 'stopped', chain }
|
|
945
945
|
: access.reaction),
|
|
946
|
-
chain:
|
|
946
|
+
chain: effects.chainExternalReason(chain),
|
|
947
947
|
});
|
|
948
948
|
}
|
|
949
949
|
else
|
|
@@ -952,7 +952,7 @@ function morphArray(source, fn, options) {
|
|
|
952
952
|
itemEffects.set(key, { stop, position });
|
|
953
953
|
}
|
|
954
954
|
}
|
|
955
|
-
const proxy
|
|
955
|
+
const proxy = effects.reactive(cache, {
|
|
956
956
|
get(cache, prop) {
|
|
957
957
|
const n = typeof prop === 'string' ? Number(prop) : NaN;
|
|
958
958
|
if (Number.isNaN(n))
|
|
@@ -965,7 +965,7 @@ function morphArray(source, fn, options) {
|
|
|
965
965
|
return Reflect.has(input, prop);
|
|
966
966
|
},
|
|
967
967
|
});
|
|
968
|
-
const stopMain =
|
|
968
|
+
const stopMain = effects.effect `morph:${fn.name}`(({ ascend }) => {
|
|
969
969
|
track = ascend;
|
|
970
970
|
const newInput = [...(typeof source === 'function' ? source() : source)];
|
|
971
971
|
const diffs = arrayDiff(input, newInput).toSorted((a, b) => b.indexA - a.indexA);
|
|
@@ -1024,7 +1024,7 @@ function morphArray(source, fn, options) {
|
|
|
1024
1024
|
stopItem(index);
|
|
1025
1025
|
computeItem(index, value);
|
|
1026
1026
|
}
|
|
1027
|
-
const invalidates = new Set([
|
|
1027
|
+
const invalidates = new Set([effects.keysOf]);
|
|
1028
1028
|
if (input.length !== newInput.length)
|
|
1029
1029
|
invalidates.add('length');
|
|
1030
1030
|
for (const diff of diffs) {
|
|
@@ -1032,11 +1032,11 @@ function morphArray(source, fn, options) {
|
|
|
1032
1032
|
for (let i = 0; i < max; i++)
|
|
1033
1033
|
invalidates.add(String(diff.indexA + i));
|
|
1034
1034
|
}
|
|
1035
|
-
|
|
1035
|
+
effects.touched(cache, { type: 'bunch', method: 'morph-input' }, invalidates);
|
|
1036
1036
|
}
|
|
1037
1037
|
input = newInput;
|
|
1038
1038
|
});
|
|
1039
|
-
return
|
|
1039
|
+
return effects.link(proxy, (reason) => {
|
|
1040
1040
|
stopMain(reason);
|
|
1041
1041
|
for (const entry of itemEffects.values())
|
|
1042
1042
|
entry.stop(reason);
|
|
@@ -1055,7 +1055,7 @@ function morphArray(source, fn, options) {
|
|
|
1055
1055
|
* @returns A reactive Map with a `[cleanup]` method to dispose all effects
|
|
1056
1056
|
*/
|
|
1057
1057
|
function morphMap(source, fn, options) {
|
|
1058
|
-
if (!
|
|
1058
|
+
if (!effects.isReactive(source) && options?.pure === true) {
|
|
1059
1059
|
const res = new Map();
|
|
1060
1060
|
for (const [k, v] of source)
|
|
1061
1061
|
res.set(k, fn(v, k));
|
|
@@ -1063,15 +1063,15 @@ function morphMap(source, fn, options) {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
let track;
|
|
1065
1065
|
const itemEffects = new Map();
|
|
1066
|
-
const cache =
|
|
1066
|
+
const cache = effects.tag(`morph:${fn.name || 'anonymous'}`, new Map());
|
|
1067
1067
|
Object.defineProperty(cache, 'constructor', { value: Object, enumerable: false });
|
|
1068
1068
|
function stopItem(key) {
|
|
1069
1069
|
const stop = itemEffects.get(key);
|
|
1070
1070
|
if (stop) {
|
|
1071
|
-
const activeEffect =
|
|
1071
|
+
const activeEffect = effects.getActiveEffect();
|
|
1072
1072
|
let chain;
|
|
1073
1073
|
if (activeEffect) {
|
|
1074
|
-
const node =
|
|
1074
|
+
const node = effects.getEffectNode(activeEffect);
|
|
1075
1075
|
chain = node.currentReason;
|
|
1076
1076
|
}
|
|
1077
1077
|
stop({ type: 'stopped', chain });
|
|
@@ -1084,31 +1084,31 @@ function morphMap(source, fn, options) {
|
|
|
1084
1084
|
cache.set(key, track(() => fn(val, key)));
|
|
1085
1085
|
}
|
|
1086
1086
|
else {
|
|
1087
|
-
const stop = track(() =>
|
|
1087
|
+
const stop = track(() => effects.effect.opaque `morph:${fn.name}:${key}`((access) => {
|
|
1088
1088
|
const next = source.get(key);
|
|
1089
1089
|
if (next === undefined && !source.has(key))
|
|
1090
1090
|
return;
|
|
1091
1091
|
cache.set(key, fn(next, key, access));
|
|
1092
1092
|
return (reason) => {
|
|
1093
1093
|
cache.delete(key);
|
|
1094
|
-
|
|
1095
|
-
const activeEffect =
|
|
1094
|
+
effects.touched1(cache, { type: 'invalidate', prop: 'morph' }, String(key));
|
|
1095
|
+
const activeEffect = effects.getActiveEffect();
|
|
1096
1096
|
let chain;
|
|
1097
1097
|
if (activeEffect) {
|
|
1098
|
-
const node =
|
|
1098
|
+
const node = effects.getEffectNode(activeEffect);
|
|
1099
1099
|
chain = node.currentReason;
|
|
1100
1100
|
}
|
|
1101
1101
|
stop?.({
|
|
1102
1102
|
type: 'invalidate',
|
|
1103
|
-
cause:
|
|
1104
|
-
chain:
|
|
1103
|
+
cause: effects.chainExternalReason(reason ?? { type: 'stopped', chain }),
|
|
1104
|
+
chain: effects.chainExternalReason(chain),
|
|
1105
1105
|
});
|
|
1106
1106
|
};
|
|
1107
1107
|
}));
|
|
1108
1108
|
itemEffects.set(key, stop);
|
|
1109
1109
|
}
|
|
1110
1110
|
}
|
|
1111
|
-
const proxy
|
|
1111
|
+
const proxy = effects.reactive(cache, {
|
|
1112
1112
|
get(cache, prop) {
|
|
1113
1113
|
if (prop === 'get')
|
|
1114
1114
|
return (key) => {
|
|
@@ -1127,42 +1127,42 @@ function morphMap(source, fn, options) {
|
|
|
1127
1127
|
if (prop === 'values')
|
|
1128
1128
|
return function* () {
|
|
1129
1129
|
for (const key of source.keys()) {
|
|
1130
|
-
yield proxy
|
|
1130
|
+
yield proxy.get(key);
|
|
1131
1131
|
}
|
|
1132
1132
|
};
|
|
1133
1133
|
if (prop === 'entries')
|
|
1134
1134
|
return function* () {
|
|
1135
1135
|
for (const key of source.keys()) {
|
|
1136
|
-
yield [key, proxy
|
|
1136
|
+
yield [key, proxy.get(key)];
|
|
1137
1137
|
}
|
|
1138
1138
|
};
|
|
1139
1139
|
if (prop === Symbol.iterator)
|
|
1140
1140
|
return function* () {
|
|
1141
1141
|
for (const key of source.keys()) {
|
|
1142
|
-
yield [key, proxy
|
|
1142
|
+
yield [key, proxy.get(key)];
|
|
1143
1143
|
}
|
|
1144
1144
|
};
|
|
1145
1145
|
return cache[prop];
|
|
1146
1146
|
},
|
|
1147
1147
|
});
|
|
1148
|
-
let stateSnapshot =
|
|
1149
|
-
const stopMain =
|
|
1148
|
+
let stateSnapshot = effects.getState(source);
|
|
1149
|
+
const stopMain = effects.effect `morph:${fn.name}`(({ ascend }) => {
|
|
1150
1150
|
track = ascend;
|
|
1151
|
-
|
|
1151
|
+
effects.dependant(source, effects.keysOf);
|
|
1152
1152
|
while ('evolution' in stateSnapshot) {
|
|
1153
1153
|
const { evolution } = stateSnapshot;
|
|
1154
1154
|
stateSnapshot = stateSnapshot.next;
|
|
1155
1155
|
if (evolution.type === 'add') {
|
|
1156
|
-
|
|
1156
|
+
effects.touched1(cache, evolution, evolution.prop);
|
|
1157
1157
|
}
|
|
1158
1158
|
else if (evolution.type === 'del') {
|
|
1159
1159
|
stopItem(evolution.prop);
|
|
1160
1160
|
cache.delete(evolution.prop);
|
|
1161
|
-
|
|
1161
|
+
effects.touched1(cache, evolution, evolution.prop);
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
});
|
|
1165
|
-
return
|
|
1165
|
+
return effects.link(proxy, (reason) => {
|
|
1166
1166
|
stopMain(reason);
|
|
1167
1167
|
for (const stop of itemEffects.values())
|
|
1168
1168
|
stop(reason);
|
|
@@ -1181,7 +1181,7 @@ function morphMap(source, fn, options) {
|
|
|
1181
1181
|
* @returns A reactive record with a `[cleanup]` method to dispose all effects
|
|
1182
1182
|
*/
|
|
1183
1183
|
function morphRecord(source, fn, options) {
|
|
1184
|
-
if (!
|
|
1184
|
+
if (!effects.isReactive(source) && options?.pure === true) {
|
|
1185
1185
|
const res = {};
|
|
1186
1186
|
for (const k of Object.keys(source))
|
|
1187
1187
|
res[k] = fn(source[k], k);
|
|
@@ -1193,10 +1193,10 @@ function morphRecord(source, fn, options) {
|
|
|
1193
1193
|
function stopItem(key) {
|
|
1194
1194
|
const stop = itemEffects.get(key);
|
|
1195
1195
|
if (stop) {
|
|
1196
|
-
const activeEffect =
|
|
1196
|
+
const activeEffect = effects.getActiveEffect();
|
|
1197
1197
|
let chain;
|
|
1198
1198
|
if (activeEffect) {
|
|
1199
|
-
const node =
|
|
1199
|
+
const node = effects.getEffectNode(activeEffect);
|
|
1200
1200
|
chain = node.currentReason;
|
|
1201
1201
|
}
|
|
1202
1202
|
stop({ type: 'stopped', chain });
|
|
@@ -1209,21 +1209,21 @@ function morphRecord(source, fn, options) {
|
|
|
1209
1209
|
cache[key] = track(() => fn(val, key));
|
|
1210
1210
|
}
|
|
1211
1211
|
else {
|
|
1212
|
-
const stop = track(() =>
|
|
1212
|
+
const stop = track(() => effects.effect.opaque `morph:${fn.name}:${key}`((access) => {
|
|
1213
1213
|
cache[key] = fn(source[key], key, access);
|
|
1214
1214
|
return (reason) => {
|
|
1215
1215
|
delete cache[key];
|
|
1216
|
-
|
|
1217
|
-
const activeEffect =
|
|
1216
|
+
effects.touched1(cache, { type: 'invalidate', prop: 'morph' }, String(key));
|
|
1217
|
+
const activeEffect = effects.getActiveEffect();
|
|
1218
1218
|
let chain;
|
|
1219
1219
|
if (activeEffect) {
|
|
1220
|
-
const node =
|
|
1220
|
+
const node = effects.getEffectNode(activeEffect);
|
|
1221
1221
|
chain = node.currentReason;
|
|
1222
1222
|
}
|
|
1223
1223
|
stop?.({
|
|
1224
1224
|
type: 'invalidate',
|
|
1225
|
-
cause:
|
|
1226
|
-
chain:
|
|
1225
|
+
cause: effects.chainExternalReason(reason ?? { type: 'stopped', chain }),
|
|
1226
|
+
chain: effects.chainExternalReason(chain),
|
|
1227
1227
|
});
|
|
1228
1228
|
};
|
|
1229
1229
|
}));
|
|
@@ -1235,7 +1235,7 @@ function morphRecord(source, fn, options) {
|
|
|
1235
1235
|
computeItem(prop, source[prop]);
|
|
1236
1236
|
return cache[prop];
|
|
1237
1237
|
}
|
|
1238
|
-
const proxy
|
|
1238
|
+
const proxy = effects.reactive(cache, {
|
|
1239
1239
|
get(_, prop) {
|
|
1240
1240
|
return get(prop);
|
|
1241
1241
|
},
|
|
@@ -1250,25 +1250,25 @@ function morphRecord(source, fn, options) {
|
|
|
1250
1250
|
return { configurable: true, enumerable: true, get: () => get(prop) };
|
|
1251
1251
|
},
|
|
1252
1252
|
});
|
|
1253
|
-
let stateSnapshot =
|
|
1254
|
-
const stopMain =
|
|
1253
|
+
let stateSnapshot = effects.getState(source);
|
|
1254
|
+
const stopMain = effects.effect `morph:${fn.name}`(({ ascend }) => {
|
|
1255
1255
|
track = ascend;
|
|
1256
1256
|
// Track only structural changes on source
|
|
1257
|
-
|
|
1257
|
+
effects.dependant(source, effects.keysOf);
|
|
1258
1258
|
while ('evolution' in stateSnapshot) {
|
|
1259
1259
|
const { evolution } = stateSnapshot;
|
|
1260
1260
|
stateSnapshot = stateSnapshot.next;
|
|
1261
1261
|
if (evolution.type === 'add') {
|
|
1262
|
-
|
|
1262
|
+
effects.touched1(cache, evolution, evolution.prop);
|
|
1263
1263
|
}
|
|
1264
1264
|
else if (evolution.type === 'del') {
|
|
1265
1265
|
stopItem(evolution.prop);
|
|
1266
1266
|
delete cache[evolution.prop];
|
|
1267
|
-
|
|
1267
|
+
effects.touched1(cache, evolution, evolution.prop);
|
|
1268
1268
|
}
|
|
1269
1269
|
}
|
|
1270
1270
|
});
|
|
1271
|
-
return
|
|
1271
|
+
return effects.link(proxy, (reason) => {
|
|
1272
1272
|
stopMain(reason);
|
|
1273
1273
|
for (const stop of itemEffects.values())
|
|
1274
1274
|
stop(reason);
|
|
@@ -1292,7 +1292,7 @@ function morphRecord(source, fn, options) {
|
|
|
1292
1292
|
* // Changing users[0].name only recomputes names[0]
|
|
1293
1293
|
* ```
|
|
1294
1294
|
*/
|
|
1295
|
-
const morph =
|
|
1295
|
+
const morph = effects.captioned(effects.flavored(function morph(source, fn, options) {
|
|
1296
1296
|
if (Array.isArray(source) || typeof source === 'function')
|
|
1297
1297
|
return morphArray(source, fn, options);
|
|
1298
1298
|
if (source instanceof Map)
|
|
@@ -1305,7 +1305,7 @@ const morph = proxy.captioned(proxy.flavored(function morph(source, fn, options)
|
|
|
1305
1305
|
}), {
|
|
1306
1306
|
name: 'morph',
|
|
1307
1307
|
callbackIndex: 1,
|
|
1308
|
-
warn: (message) =>
|
|
1308
|
+
warn: (message) => effects.options.warn(`[reactive] ${message}`),
|
|
1309
1309
|
});
|
|
1310
1310
|
|
|
1311
1311
|
/**
|
|
@@ -1328,17 +1328,17 @@ function deepWatch(target, callback, { immediate = false } = {}) {
|
|
|
1328
1328
|
if (typeof target !== 'object')
|
|
1329
1329
|
throw new Error('Target of deep watching must be an object');
|
|
1330
1330
|
// Create a wrapper callback that matches EffectTrigger signature
|
|
1331
|
-
const wrappedCallback =
|
|
1332
|
-
|
|
1331
|
+
const wrappedCallback = effects.markWithRoot((() => callback(target)), callback);
|
|
1332
|
+
effects.registerDeepWatcher();
|
|
1333
1333
|
// Use the existing effect system to register dependencies
|
|
1334
|
-
return
|
|
1334
|
+
return effects.effect `deepWatch`(() => {
|
|
1335
1335
|
// Mark the target object as having deep watchers
|
|
1336
|
-
|
|
1336
|
+
effects.objectsWithDeepWatchers.add(target);
|
|
1337
1337
|
// Track which objects this effect is watching for cleanup
|
|
1338
|
-
let effectObjects =
|
|
1338
|
+
let effectObjects = effects.effectToDeepWatchedObjects.get(wrappedCallback);
|
|
1339
1339
|
if (!effectObjects) {
|
|
1340
1340
|
effectObjects = new Set();
|
|
1341
|
-
|
|
1341
|
+
effects.effectToDeepWatchedObjects.set(wrappedCallback, effectObjects);
|
|
1342
1342
|
}
|
|
1343
1343
|
effectObjects.add(target);
|
|
1344
1344
|
// Traverse the object graph and register dependencies
|
|
@@ -1346,23 +1346,23 @@ function deepWatch(target, callback, { immediate = false } = {}) {
|
|
|
1346
1346
|
const visited = new WeakSet();
|
|
1347
1347
|
function traverseAndTrack(obj, depth = 0) {
|
|
1348
1348
|
// Prevent infinite recursion and excessive depth
|
|
1349
|
-
if (!obj || visited.has(obj) || typeof obj !== 'object' || depth >
|
|
1349
|
+
if (!obj || visited.has(obj) || typeof obj !== 'object' || depth > effects.options.maxDeepWatchDepth)
|
|
1350
1350
|
return;
|
|
1351
1351
|
// Do not traverse into unreactive objects
|
|
1352
|
-
if (
|
|
1352
|
+
if (effects.isNonReactive(obj))
|
|
1353
1353
|
return;
|
|
1354
1354
|
visited.add(obj);
|
|
1355
1355
|
// Mark this object as having deep watchers
|
|
1356
|
-
|
|
1356
|
+
effects.objectsWithDeepWatchers.add(obj);
|
|
1357
1357
|
effectObjects.add(obj);
|
|
1358
1358
|
// Traverse all properties to register dependencies
|
|
1359
1359
|
// unwrap to avoid kicking dependency
|
|
1360
|
-
for (const key in
|
|
1360
|
+
for (const key in effects.unwrap(obj)) {
|
|
1361
1361
|
if (Object.hasOwn(obj, key)) {
|
|
1362
1362
|
// Access the property to register dependency
|
|
1363
1363
|
const value = obj[key];
|
|
1364
1364
|
// Make the value reactive if it's an object
|
|
1365
|
-
const reactiveValue = typeof value === 'object' && value !== null ?
|
|
1365
|
+
const reactiveValue = typeof value === 'object' && value !== null ? effects.reactive(value) : value;
|
|
1366
1366
|
traverseAndTrack(reactiveValue, depth + 1);
|
|
1367
1367
|
}
|
|
1368
1368
|
}
|
|
@@ -1372,17 +1372,17 @@ function deepWatch(target, callback, { immediate = false } = {}) {
|
|
|
1372
1372
|
// Access the iterator to track additions/removals/collection changes
|
|
1373
1373
|
for (const value of obj) {
|
|
1374
1374
|
// Make the value reactive if it's an object
|
|
1375
|
-
const reactiveValue = typeof value === 'object' && value !== null ?
|
|
1375
|
+
const reactiveValue = typeof value === 'object' && value !== null ? effects.reactive(value) : value;
|
|
1376
1376
|
traverseAndTrack(reactiveValue, depth + 1);
|
|
1377
1377
|
}
|
|
1378
1378
|
// Explicitly depend on length so array mutations changing count trigger re-evaluation
|
|
1379
1379
|
if ('length' in obj) {
|
|
1380
|
-
|
|
1380
|
+
effects.dependant(obj, 'length');
|
|
1381
1381
|
}
|
|
1382
1382
|
// For Maps, also ensure we track values explicitly if the iterator yields entries
|
|
1383
1383
|
if (obj instanceof Map) {
|
|
1384
1384
|
for (const value of obj.values()) {
|
|
1385
|
-
const reactiveValue = typeof value === 'object' && value !== null ?
|
|
1385
|
+
const reactiveValue = typeof value === 'object' && value !== null ? effects.reactive(value) : value;
|
|
1386
1386
|
traverseAndTrack(reactiveValue, depth + 1);
|
|
1387
1387
|
}
|
|
1388
1388
|
}
|
|
@@ -1395,34 +1395,34 @@ function deepWatch(target, callback, { immediate = false } = {}) {
|
|
|
1395
1395
|
traverseAndTrack(target);
|
|
1396
1396
|
// Only call the callback if immediate is true or if it's not the first run
|
|
1397
1397
|
if (immediate) {
|
|
1398
|
-
|
|
1398
|
+
effects.untracked `deepWatch:callback`(() => callback(target));
|
|
1399
1399
|
}
|
|
1400
1400
|
immediate = true;
|
|
1401
1401
|
// Return a cleanup function that properly removes deep watcher tracking
|
|
1402
1402
|
return () => {
|
|
1403
1403
|
// Get the objects this effect was watching
|
|
1404
|
-
const effectObjects =
|
|
1404
|
+
const effectObjects = effects.effectToDeepWatchedObjects.get(wrappedCallback);
|
|
1405
1405
|
if (effectObjects) {
|
|
1406
1406
|
// Remove deep watcher tracking from all objects this effect was watching
|
|
1407
1407
|
for (const obj of effectObjects) {
|
|
1408
1408
|
// Check if this object still has other deep watchers
|
|
1409
|
-
const watchers =
|
|
1409
|
+
const watchers = effects.deepWatchers.get(obj);
|
|
1410
1410
|
if (watchers) {
|
|
1411
1411
|
// Remove this effect's callback from the watchers
|
|
1412
1412
|
watchers.delete(wrappedCallback);
|
|
1413
1413
|
// If no more watchers, remove the object from deep watchers tracking
|
|
1414
1414
|
if (watchers.size === 0) {
|
|
1415
|
-
|
|
1416
|
-
|
|
1415
|
+
effects.deepWatchers.delete(obj);
|
|
1416
|
+
effects.objectsWithDeepWatchers.delete(obj);
|
|
1417
1417
|
}
|
|
1418
1418
|
}
|
|
1419
1419
|
else {
|
|
1420
1420
|
// No watchers found, remove from deep watchers tracking
|
|
1421
|
-
|
|
1421
|
+
effects.objectsWithDeepWatchers.delete(obj);
|
|
1422
1422
|
}
|
|
1423
1423
|
}
|
|
1424
1424
|
// Clean up the tracking data
|
|
1425
|
-
|
|
1425
|
+
effects.effectToDeepWatchedObjects.delete(wrappedCallback);
|
|
1426
1426
|
}
|
|
1427
1427
|
};
|
|
1428
1428
|
});
|
|
@@ -1440,12 +1440,12 @@ function getBranch(tree, key) {
|
|
|
1440
1440
|
return branch;
|
|
1441
1441
|
}
|
|
1442
1442
|
function memoizeFunction(fn, opts) {
|
|
1443
|
-
const fnRoot =
|
|
1443
|
+
const fnRoot = effects.getRoot(fn);
|
|
1444
1444
|
const existing = memoizedRegistry.get(fnRoot);
|
|
1445
1445
|
if (existing)
|
|
1446
1446
|
return existing;
|
|
1447
1447
|
const cacheRoot = {};
|
|
1448
|
-
const memoized =
|
|
1448
|
+
const memoized = effects.markWithRoot(function memoized(...args) {
|
|
1449
1449
|
if (args.some((arg) => !(arg && ['object', 'symbol', 'function'].includes(typeof arg)))) {
|
|
1450
1450
|
if (opts?.lenient)
|
|
1451
1451
|
return fn.apply(this, args);
|
|
@@ -1456,65 +1456,65 @@ function memoizeFunction(fn, opts) {
|
|
|
1456
1456
|
for (const arg of args) {
|
|
1457
1457
|
node = getBranch(node, arg);
|
|
1458
1458
|
}
|
|
1459
|
-
if (
|
|
1459
|
+
if (effects.inertDepth > 0) {
|
|
1460
1460
|
return fn.apply(this, args);
|
|
1461
1461
|
}
|
|
1462
|
-
|
|
1462
|
+
effects.dependant(node, 'memoize');
|
|
1463
1463
|
if ('result' in node) {
|
|
1464
|
-
if (
|
|
1465
|
-
const wasVerification =
|
|
1466
|
-
|
|
1464
|
+
if (effects.options.onMemoizationDiscrepancy) {
|
|
1465
|
+
const wasVerification = effects.options.isVerificationRun;
|
|
1466
|
+
effects.options.isVerificationRun = true;
|
|
1467
1467
|
try {
|
|
1468
|
-
const fresh =
|
|
1469
|
-
if (!
|
|
1470
|
-
|
|
1468
|
+
const fresh = effects.untracked `memoize:verify-calculation`(() => fn.apply(this, args));
|
|
1469
|
+
if (!effects.deepCompare(node.result, fresh)) {
|
|
1470
|
+
effects.optionCall('onMemoizationDiscrepancy', node.result, fresh, fn, args, 'calculation');
|
|
1471
1471
|
}
|
|
1472
1472
|
}
|
|
1473
1473
|
finally {
|
|
1474
|
-
|
|
1474
|
+
effects.options.isVerificationRun = wasVerification;
|
|
1475
1475
|
}
|
|
1476
1476
|
}
|
|
1477
1477
|
return node.result;
|
|
1478
1478
|
}
|
|
1479
1479
|
// Create memoize internal effect to track dependencies and invalidate cache
|
|
1480
1480
|
// Use untracked to prevent the effect creation from being affected by parent effects
|
|
1481
|
-
node.cleanup =
|
|
1481
|
+
node.cleanup = effects.root `memoize:root`(() => effects.effect `memoize`(() => {
|
|
1482
1482
|
// Execute the function and track its dependencies
|
|
1483
1483
|
// The function execution will automatically track dependencies on reactive objects
|
|
1484
1484
|
node.result = fn.apply(this, args);
|
|
1485
1485
|
return (reason) => {
|
|
1486
1486
|
// When dependencies change, clear the cache and notify consumers
|
|
1487
1487
|
delete node.result;
|
|
1488
|
-
|
|
1488
|
+
effects.touched1(node, { type: 'invalidate', prop: args }, 'memoize');
|
|
1489
1489
|
// Lazy memoization: stop the effect so it doesn't re-run immediately.
|
|
1490
1490
|
// It will be re-created on next access.
|
|
1491
1491
|
if (node.cleanup) {
|
|
1492
|
-
const activeEffect =
|
|
1492
|
+
const activeEffect = effects.getActiveEffect();
|
|
1493
1493
|
let chain;
|
|
1494
1494
|
if (activeEffect) {
|
|
1495
|
-
const effectNode =
|
|
1495
|
+
const effectNode = effects.getEffectNode(activeEffect);
|
|
1496
1496
|
chain = effectNode.currentReason;
|
|
1497
1497
|
}
|
|
1498
1498
|
node.cleanup({
|
|
1499
1499
|
type: 'invalidate',
|
|
1500
|
-
cause:
|
|
1501
|
-
chain:
|
|
1500
|
+
cause: effects.chainExternalReason(reason ?? { type: 'stopped', chain }),
|
|
1501
|
+
chain: effects.chainExternalReason(chain),
|
|
1502
1502
|
});
|
|
1503
1503
|
node.cleanup = undefined;
|
|
1504
1504
|
}
|
|
1505
1505
|
};
|
|
1506
1506
|
}, { opaque: true }));
|
|
1507
|
-
if (
|
|
1508
|
-
const wasVerification =
|
|
1509
|
-
|
|
1507
|
+
if (effects.options.onMemoizationDiscrepancy) {
|
|
1508
|
+
const wasVerification = effects.options.isVerificationRun;
|
|
1509
|
+
effects.options.isVerificationRun = true;
|
|
1510
1510
|
try {
|
|
1511
|
-
const fresh =
|
|
1512
|
-
if (!
|
|
1513
|
-
|
|
1511
|
+
const fresh = effects.untracked `memoize:verify-comparison`(() => fn.apply(this, args));
|
|
1512
|
+
if (!effects.deepCompare(node.result, fresh)) {
|
|
1513
|
+
effects.optionCall('onMemoizationDiscrepancy', node.result, fresh, fn, args, 'comparison');
|
|
1514
1514
|
}
|
|
1515
1515
|
}
|
|
1516
1516
|
finally {
|
|
1517
|
-
|
|
1517
|
+
effects.options.isVerificationRun = wasVerification;
|
|
1518
1518
|
}
|
|
1519
1519
|
}
|
|
1520
1520
|
return node.result;
|
|
@@ -1527,7 +1527,7 @@ function memoizeObject(target, opts) {
|
|
|
1527
1527
|
const existing = memoizedRegistry.get(target);
|
|
1528
1528
|
if (existing)
|
|
1529
1529
|
return existing;
|
|
1530
|
-
const proxy
|
|
1530
|
+
const proxy = new Proxy(target, {
|
|
1531
1531
|
get(source, prop, receiver) {
|
|
1532
1532
|
// 1. Walk prototype chain to find descriptor
|
|
1533
1533
|
let current = source;
|
|
@@ -1545,14 +1545,14 @@ function memoizeObject(target, opts) {
|
|
|
1545
1545
|
const originalGetter = desc.get;
|
|
1546
1546
|
let wrapper = wrapperRegistry.get(originalGetter);
|
|
1547
1547
|
if (!wrapper) {
|
|
1548
|
-
wrapper =
|
|
1548
|
+
wrapper = effects.markWithRoot(effects.named(`${String(source?.constructor?.name ?? 'Object')}.${String(prop)}`, (that) => {
|
|
1549
1549
|
return originalGetter.call(that);
|
|
1550
1550
|
}), {
|
|
1551
1551
|
propertyKey: prop,
|
|
1552
1552
|
});
|
|
1553
|
-
const origRoot = originalGetter[
|
|
1553
|
+
const origRoot = originalGetter[effects.rootFunctionSymbol];
|
|
1554
1554
|
if (origRoot)
|
|
1555
|
-
wrapper[
|
|
1555
|
+
wrapper[effects.rootFunctionSymbol] = origRoot;
|
|
1556
1556
|
wrapperRegistry.set(originalGetter, wrapper);
|
|
1557
1557
|
}
|
|
1558
1558
|
const memoized = memoizeFunction(wrapper, opts);
|
|
@@ -1568,9 +1568,9 @@ function memoizeObject(target, opts) {
|
|
|
1568
1568
|
return Reflect.set(source, prop, value, source);
|
|
1569
1569
|
},
|
|
1570
1570
|
});
|
|
1571
|
-
|
|
1572
|
-
memoizedRegistry.set(target, proxy
|
|
1573
|
-
return proxy
|
|
1571
|
+
effects.proxyToObject.set(proxy, target);
|
|
1572
|
+
memoizedRegistry.set(target, proxy);
|
|
1573
|
+
return proxy;
|
|
1574
1574
|
}
|
|
1575
1575
|
/**
|
|
1576
1576
|
* Decorator and function wrapper for memoizing computed values based on reactive dependencies.
|
|
@@ -1596,20 +1596,20 @@ function memoizeObject(target, opts) {
|
|
|
1596
1596
|
* ```
|
|
1597
1597
|
*/
|
|
1598
1598
|
function makeMemoizeDecorator(memoizeOpts) {
|
|
1599
|
-
return
|
|
1599
|
+
return effects.decorator({
|
|
1600
1600
|
getter(original, target, propertyKey) {
|
|
1601
1601
|
return function () {
|
|
1602
1602
|
let wrapper = wrapperRegistry.get(original);
|
|
1603
1603
|
if (!wrapper) {
|
|
1604
|
-
wrapper =
|
|
1604
|
+
wrapper = effects.markWithRoot(effects.named(`${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(propertyKey)}`, (that) => {
|
|
1605
1605
|
return original.call(that);
|
|
1606
1606
|
}), {
|
|
1607
1607
|
method: original,
|
|
1608
1608
|
propertyKey,
|
|
1609
1609
|
});
|
|
1610
|
-
const origRoot = original[
|
|
1610
|
+
const origRoot = original[effects.rootFunctionSymbol];
|
|
1611
1611
|
if (origRoot)
|
|
1612
|
-
wrapper[
|
|
1612
|
+
wrapper[effects.rootFunctionSymbol] = origRoot;
|
|
1613
1613
|
wrapperRegistry.set(original, wrapper);
|
|
1614
1614
|
}
|
|
1615
1615
|
const memoized = memoizeFunction(wrapper, memoizeOpts);
|
|
@@ -1620,15 +1620,15 @@ function makeMemoizeDecorator(memoizeOpts) {
|
|
|
1620
1620
|
return function (...args) {
|
|
1621
1621
|
let wrapper = wrapperRegistry.get(original);
|
|
1622
1622
|
if (!wrapper) {
|
|
1623
|
-
wrapper =
|
|
1623
|
+
wrapper = effects.markWithRoot(effects.named(`${String(target?.constructor?.name ?? target?.name ?? 'Object')}.${String(name)}`, (that, ...args) => {
|
|
1624
1624
|
return original.call(that, ...args);
|
|
1625
1625
|
}), {
|
|
1626
1626
|
method: original,
|
|
1627
1627
|
propertyKey: name,
|
|
1628
1628
|
});
|
|
1629
|
-
const origRoot = original[
|
|
1629
|
+
const origRoot = original[effects.rootFunctionSymbol];
|
|
1630
1630
|
if (origRoot)
|
|
1631
|
-
wrapper[
|
|
1631
|
+
wrapper[effects.rootFunctionSymbol] = origRoot;
|
|
1632
1632
|
wrapperRegistry.set(original, wrapper);
|
|
1633
1633
|
}
|
|
1634
1634
|
const memoized = memoizeFunction(wrapper, memoizeOpts);
|
|
@@ -1640,7 +1640,7 @@ function makeMemoizeDecorator(memoizeOpts) {
|
|
|
1640
1640
|
: memoizeFunction(target, memoizeOpts),
|
|
1641
1641
|
});
|
|
1642
1642
|
}
|
|
1643
|
-
const memoize =
|
|
1643
|
+
const memoize = effects.flavored(makeMemoizeDecorator(), {
|
|
1644
1644
|
get lenient() {
|
|
1645
1645
|
return makeMemoizeDecorator({ lenient: true });
|
|
1646
1646
|
},
|
|
@@ -1698,8 +1698,8 @@ const memoize = proxy.flavored(makeMemoizeDecorator(), {
|
|
|
1698
1698
|
* });
|
|
1699
1699
|
*/
|
|
1700
1700
|
function organized(source, apply, baseTarget = {}) {
|
|
1701
|
-
const observedSource =
|
|
1702
|
-
const target =
|
|
1701
|
+
const observedSource = effects.reactive(source);
|
|
1702
|
+
const target = effects.reactive(baseTarget);
|
|
1703
1703
|
const stop = attend `organized:entries`(function enumerateObservedSourceKeys() {
|
|
1704
1704
|
const keys = [];
|
|
1705
1705
|
for (const key in observedSource)
|
|
@@ -1709,8 +1709,8 @@ function organized(source, apply, baseTarget = {}) {
|
|
|
1709
1709
|
const sourceKey = key;
|
|
1710
1710
|
const accessBase = {
|
|
1711
1711
|
key: sourceKey,
|
|
1712
|
-
get: () =>
|
|
1713
|
-
set: (value) =>
|
|
1712
|
+
get: () => effects.FoolProof.get(observedSource, sourceKey, observedSource),
|
|
1713
|
+
set: (value) => effects.FoolProof.set(observedSource, sourceKey, value, observedSource),
|
|
1714
1714
|
};
|
|
1715
1715
|
Object.defineProperty(accessBase, 'value', {
|
|
1716
1716
|
get: accessBase.get,
|
|
@@ -1720,7 +1720,7 @@ function organized(source, apply, baseTarget = {}) {
|
|
|
1720
1720
|
});
|
|
1721
1721
|
return apply(accessBase, target);
|
|
1722
1722
|
});
|
|
1723
|
-
return
|
|
1723
|
+
return effects.link(target, (reason) => stop(reason));
|
|
1724
1724
|
}
|
|
1725
1725
|
/**
|
|
1726
1726
|
* Organizes a property on a target object
|
|
@@ -1737,13 +1737,13 @@ function organize(target, property, access) {
|
|
|
1737
1737
|
configurable: true,
|
|
1738
1738
|
enumerable: true,
|
|
1739
1739
|
});
|
|
1740
|
-
|
|
1740
|
+
effects.touched1(target, { type: 'set', prop: property }, property);
|
|
1741
1741
|
return () => delete target[property];
|
|
1742
1742
|
}
|
|
1743
1743
|
|
|
1744
1744
|
//#region watch
|
|
1745
1745
|
const unsetYet = Symbol('unset-yet');
|
|
1746
|
-
const watch =
|
|
1746
|
+
const watch = effects.captioned(effects.flavored(function watch(value, //object | ((dep: DependencyAccess) => object),
|
|
1747
1747
|
changed, options = {}) {
|
|
1748
1748
|
return typeof value === 'function'
|
|
1749
1749
|
? watchCallBack(value, changed, options)
|
|
@@ -1754,20 +1754,20 @@ changed, options = {}) {
|
|
|
1754
1754
|
})();
|
|
1755
1755
|
}, {
|
|
1756
1756
|
get deep() {
|
|
1757
|
-
return
|
|
1757
|
+
return effects.flavorOptions(this, { deep: true });
|
|
1758
1758
|
},
|
|
1759
1759
|
get immediate() {
|
|
1760
|
-
return
|
|
1760
|
+
return effects.flavorOptions(this, { immediate: true });
|
|
1761
1761
|
},
|
|
1762
1762
|
}), {
|
|
1763
1763
|
name: 'watch',
|
|
1764
|
-
warn: (message) =>
|
|
1764
|
+
warn: (message) => effects.options.warn(`[reactive] ${message}`),
|
|
1765
1765
|
});
|
|
1766
1766
|
function watchObject(value, changed, { immediate = false, deep = false } = {}) {
|
|
1767
1767
|
if (deep)
|
|
1768
1768
|
return deepWatch(value, changed, { immediate });
|
|
1769
|
-
return
|
|
1770
|
-
|
|
1769
|
+
return effects.effect `watch:object`(() => {
|
|
1770
|
+
effects.dependant(value);
|
|
1771
1771
|
if (immediate)
|
|
1772
1772
|
changed(value);
|
|
1773
1773
|
immediate = true;
|
|
@@ -1776,16 +1776,16 @@ function watchObject(value, changed, { immediate = false, deep = false } = {}) {
|
|
|
1776
1776
|
function watchCallBack(value, changed, { immediate = false, deep = false } = {}) {
|
|
1777
1777
|
let oldValue = unsetYet;
|
|
1778
1778
|
let deepCleanup;
|
|
1779
|
-
const cbCleanup =
|
|
1779
|
+
const cbCleanup = effects.effect `watch:callback`(effects.markWithRoot((access) => {
|
|
1780
1780
|
const newValue = value(access);
|
|
1781
1781
|
if (oldValue !== newValue) {
|
|
1782
1782
|
const old = oldValue;
|
|
1783
1783
|
if (old === unsetYet) {
|
|
1784
1784
|
if (immediate)
|
|
1785
|
-
|
|
1785
|
+
effects.untracked `watch:changed`(() => changed(newValue));
|
|
1786
1786
|
}
|
|
1787
1787
|
else
|
|
1788
|
-
|
|
1788
|
+
effects.untracked `watch:changed`(() => changed(newValue, old));
|
|
1789
1789
|
}
|
|
1790
1790
|
oldValue = newValue;
|
|
1791
1791
|
if (deep) {
|
|
@@ -1812,7 +1812,7 @@ function watchCallBack(value, changed, { immediate = false, deep = false } = {})
|
|
|
1812
1812
|
function when(predicate, timeout) {
|
|
1813
1813
|
return new Promise((resolve, reject) => {
|
|
1814
1814
|
let timer;
|
|
1815
|
-
const stop =
|
|
1815
|
+
const stop = effects.effect `watch:when`((access) => {
|
|
1816
1816
|
try {
|
|
1817
1817
|
const value = predicate(access);
|
|
1818
1818
|
if (value) {
|
|
@@ -1846,10 +1846,10 @@ function when(predicate, timeout) {
|
|
|
1846
1846
|
* @param obj - The object to mark as non-reactive
|
|
1847
1847
|
*/
|
|
1848
1848
|
function shallowNonReactive(obj) {
|
|
1849
|
-
obj =
|
|
1850
|
-
if (
|
|
1849
|
+
obj = effects.unwrap(obj);
|
|
1850
|
+
if (effects.isNonReactive(obj))
|
|
1851
1851
|
return obj;
|
|
1852
|
-
obj[
|
|
1852
|
+
obj[effects.unreactiveProperties] = true;
|
|
1853
1853
|
return obj;
|
|
1854
1854
|
}
|
|
1855
1855
|
function unreactiveApplication(arg1, ...args) {
|
|
@@ -1857,10 +1857,10 @@ function unreactiveApplication(arg1, ...args) {
|
|
|
1857
1857
|
? shallowNonReactive(arg1)
|
|
1858
1858
|
: ((original) => {
|
|
1859
1859
|
// Copy the parent's unreactive properties if they exist
|
|
1860
|
-
const parentMarker = original.prototype[
|
|
1860
|
+
const parentMarker = original.prototype[effects.unreactiveProperties];
|
|
1861
1861
|
// If parent is fully unreactive, child is too
|
|
1862
1862
|
if (parentMarker === true) {
|
|
1863
|
-
original.prototype[
|
|
1863
|
+
original.prototype[effects.unreactiveProperties] = true;
|
|
1864
1864
|
}
|
|
1865
1865
|
else {
|
|
1866
1866
|
const set = new Set(parentMarker || []);
|
|
@@ -1868,7 +1868,7 @@ function unreactiveApplication(arg1, ...args) {
|
|
|
1868
1868
|
set.add(arg1);
|
|
1869
1869
|
for (const arg of args)
|
|
1870
1870
|
set.add(arg);
|
|
1871
|
-
|
|
1871
|
+
effects.addUnreactiveProps(original.prototype, set);
|
|
1872
1872
|
}
|
|
1873
1873
|
return original; // Return the class
|
|
1874
1874
|
});
|
|
@@ -1877,22 +1877,22 @@ function unreactiveApplication(arg1, ...args) {
|
|
|
1877
1877
|
* Decorator that marks classes or properties as non-reactive
|
|
1878
1878
|
* Prevents objects from being made reactive
|
|
1879
1879
|
*/
|
|
1880
|
-
const unreactive =
|
|
1880
|
+
const unreactive = effects.decorator({
|
|
1881
1881
|
class(original) {
|
|
1882
|
-
original.prototype[
|
|
1882
|
+
original.prototype[effects.unreactiveProperties] = true;
|
|
1883
1883
|
},
|
|
1884
1884
|
default: unreactiveApplication,
|
|
1885
1885
|
});
|
|
1886
1886
|
//#endregion
|
|
1887
1887
|
//#region resource
|
|
1888
1888
|
function lazyInit(resource, load) {
|
|
1889
|
-
const creation =
|
|
1889
|
+
const creation = effects.effectHistory.active;
|
|
1890
1890
|
let fresh = true;
|
|
1891
1891
|
return new Proxy(resource, {
|
|
1892
1892
|
[Symbol.toStringTag]: 'LazyInit',
|
|
1893
1893
|
get(target, prop) {
|
|
1894
1894
|
if (fresh) {
|
|
1895
|
-
|
|
1895
|
+
effects.captured(creation, load)();
|
|
1896
1896
|
fresh = false;
|
|
1897
1897
|
}
|
|
1898
1898
|
return target[prop];
|
|
@@ -1906,7 +1906,7 @@ function lazyInit(resource, load) {
|
|
|
1906
1906
|
* @returns Reactive Resource object with value, loading, error, latest properties
|
|
1907
1907
|
*/
|
|
1908
1908
|
function resource(fetcher, options = {}) {
|
|
1909
|
-
const resource =
|
|
1909
|
+
const resource = effects.reactive({
|
|
1910
1910
|
value: options.initialValue,
|
|
1911
1911
|
loading: true,
|
|
1912
1912
|
error: undefined,
|
|
@@ -1915,11 +1915,11 @@ function resource(fetcher, options = {}) {
|
|
|
1915
1915
|
reloadSignal.value++;
|
|
1916
1916
|
},
|
|
1917
1917
|
});
|
|
1918
|
-
const reloadSignal =
|
|
1918
|
+
const reloadSignal = effects.reactive({ value: 0 });
|
|
1919
1919
|
// Solve race conditions: make sure a new fast request is not overloaded by a slow old one
|
|
1920
1920
|
let counter = 0;
|
|
1921
1921
|
return lazyInit(resource, () => {
|
|
1922
|
-
|
|
1922
|
+
effects.link(resource, effects.effect `watch:resource`((access) => {
|
|
1923
1923
|
// Track reload signal to enable manual reloading
|
|
1924
1924
|
void reloadSignal.value;
|
|
1925
1925
|
const id = ++counter;
|
|
@@ -1966,7 +1966,7 @@ function resource(fetcher, options = {}) {
|
|
|
1966
1966
|
function* makeReactiveIterator(iterator) {
|
|
1967
1967
|
let result = iterator.next();
|
|
1968
1968
|
while (!result.done) {
|
|
1969
|
-
yield
|
|
1969
|
+
yield effects.reactive(result.value);
|
|
1970
1970
|
result = iterator.next();
|
|
1971
1971
|
}
|
|
1972
1972
|
}
|
|
@@ -1977,7 +1977,7 @@ function* makeReactiveEntriesIterator(iterator) {
|
|
|
1977
1977
|
let result = iterator.next();
|
|
1978
1978
|
while (!result.done) {
|
|
1979
1979
|
const [key, value] = result.value;
|
|
1980
|
-
yield [
|
|
1980
|
+
yield [effects.reactive(key), effects.reactive(value)];
|
|
1981
1981
|
result = iterator.next();
|
|
1982
1982
|
}
|
|
1983
1983
|
}
|
|
@@ -1989,18 +1989,18 @@ function* index(i, { length = true } = {}) {
|
|
|
1989
1989
|
}
|
|
1990
1990
|
class Indexer extends Array {
|
|
1991
1991
|
get(i) {
|
|
1992
|
-
|
|
1993
|
-
return
|
|
1992
|
+
effects.dependant(this, i);
|
|
1993
|
+
return effects.reactive(this[i]);
|
|
1994
1994
|
}
|
|
1995
1995
|
// Returns undefined intentionally: signals the proxy handler that notifications
|
|
1996
1996
|
// were already dispatched via touched(), preventing double notification
|
|
1997
1997
|
set(i, value) {
|
|
1998
1998
|
const added = i >= this.length;
|
|
1999
1999
|
this[i] = value;
|
|
2000
|
-
|
|
2000
|
+
effects.touched(this, { type: 'set', prop: i }, index(i, { length: added }));
|
|
2001
2001
|
}
|
|
2002
2002
|
}
|
|
2003
|
-
const indexLess = { get:
|
|
2003
|
+
const indexLess = { get: effects.FoolProof.get, set: effects.FoolProof.set };
|
|
2004
2004
|
// Fast numeric-string check: first char is a digit (0-9)
|
|
2005
2005
|
function asIndex(prop) {
|
|
2006
2006
|
const c = prop.charCodeAt(0);
|
|
@@ -2009,7 +2009,7 @@ function asIndex(prop) {
|
|
|
2009
2009
|
const n = +prop; // coerce — faster than parseInt, handles "0", "12", etc.
|
|
2010
2010
|
return n === (n | 0) && n >= 0 ? n : -1;
|
|
2011
2011
|
}
|
|
2012
|
-
Object.assign(
|
|
2012
|
+
Object.assign(effects.FoolProof, {
|
|
2013
2013
|
get(obj, prop, receiver) {
|
|
2014
2014
|
if (Array.isArray(obj) && typeof prop === 'string') {
|
|
2015
2015
|
const i = asIndex(prop);
|
|
@@ -2051,72 +2051,72 @@ let ReactiveArrayWrapper = (() => {
|
|
|
2051
2051
|
let _unshift_decorators;
|
|
2052
2052
|
return _a = class ReactiveArrayWrapper extends _classSuper {
|
|
2053
2053
|
at(index) {
|
|
2054
|
-
return
|
|
2054
|
+
return effects.reactive(super.at(index));
|
|
2055
2055
|
}
|
|
2056
2056
|
concat(...items) {
|
|
2057
|
-
return
|
|
2057
|
+
return effects.reactive(super.concat(...items.map(effects.unwrap)));
|
|
2058
2058
|
}
|
|
2059
2059
|
entries() {
|
|
2060
|
-
|
|
2060
|
+
effects.dependant(this, effects.keysOf);
|
|
2061
2061
|
return makeReactiveEntriesIterator(super.entries());
|
|
2062
2062
|
}
|
|
2063
2063
|
every(predicate, thisArg) {
|
|
2064
|
-
return super.every((v, i, a) => predicate.call(thisArg,
|
|
2064
|
+
return super.every((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg);
|
|
2065
2065
|
}
|
|
2066
2066
|
fill(value, start, end) {
|
|
2067
|
-
return super.fill(
|
|
2067
|
+
return super.fill(effects.unwrap(value), start, end);
|
|
2068
2068
|
}
|
|
2069
2069
|
copyWithin(target, start, end) {
|
|
2070
2070
|
return super.copyWithin(target, start, end);
|
|
2071
2071
|
}
|
|
2072
2072
|
filter(predicate, thisArg) {
|
|
2073
|
-
return
|
|
2073
|
+
return effects.reactive(super.filter((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg));
|
|
2074
2074
|
}
|
|
2075
2075
|
find(predicate, thisArg) {
|
|
2076
|
-
return
|
|
2076
|
+
return effects.reactive(super.find((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg));
|
|
2077
2077
|
}
|
|
2078
2078
|
findIndex(predicate, thisArg) {
|
|
2079
|
-
return super.findIndex((v, i, a) => predicate.call(thisArg,
|
|
2079
|
+
return super.findIndex((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg);
|
|
2080
2080
|
}
|
|
2081
2081
|
findLast(predicate, thisArg) {
|
|
2082
|
-
return
|
|
2082
|
+
return effects.reactive(super.findLast((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg));
|
|
2083
2083
|
}
|
|
2084
2084
|
findLastIndex(predicate, thisArg) {
|
|
2085
|
-
return super.findLastIndex((v, i, a) => predicate.call(thisArg,
|
|
2085
|
+
return super.findLastIndex((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg);
|
|
2086
2086
|
}
|
|
2087
2087
|
flat(depth) {
|
|
2088
|
-
|
|
2089
|
-
return
|
|
2088
|
+
effects.dependant(this, effects.keysOf);
|
|
2089
|
+
return effects.reactive(super.flat(depth));
|
|
2090
2090
|
}
|
|
2091
2091
|
flatMap(callbackfn, thisArg) {
|
|
2092
|
-
return
|
|
2092
|
+
return effects.reactive(super.flatMap((v, i, a) => effects.unwrap(callbackfn.call(thisArg, effects.reactive(v), i, a)), thisArg));
|
|
2093
2093
|
}
|
|
2094
2094
|
forEach(callbackfn, thisArg) {
|
|
2095
2095
|
super.forEach((v, i, a) => {
|
|
2096
|
-
callbackfn.call(thisArg,
|
|
2096
|
+
callbackfn.call(thisArg, effects.reactive(v), i, a);
|
|
2097
2097
|
}, thisArg);
|
|
2098
2098
|
}
|
|
2099
2099
|
includes(searchElement, fromIndex) {
|
|
2100
|
-
const target =
|
|
2100
|
+
const target = effects.unwrap(searchElement);
|
|
2101
2101
|
const length = this.length;
|
|
2102
2102
|
let start = fromIndex ?? 0;
|
|
2103
2103
|
if (start < 0)
|
|
2104
2104
|
start = Math.max(length + start, 0);
|
|
2105
2105
|
for (let i = start; i < length; i++) {
|
|
2106
|
-
const value =
|
|
2106
|
+
const value = effects.unwrap(this[i]);
|
|
2107
2107
|
if (value === target)
|
|
2108
2108
|
return true;
|
|
2109
2109
|
}
|
|
2110
2110
|
return false;
|
|
2111
2111
|
}
|
|
2112
2112
|
indexOf(searchElement, fromIndex) {
|
|
2113
|
-
const target =
|
|
2113
|
+
const target = effects.unwrap(searchElement);
|
|
2114
2114
|
const length = this.length;
|
|
2115
2115
|
let start = fromIndex ?? 0;
|
|
2116
2116
|
if (start < 0)
|
|
2117
2117
|
start = Math.max(length + start, 0);
|
|
2118
2118
|
for (let i = start; i < length; i++)
|
|
2119
|
-
if (
|
|
2119
|
+
if (effects.unwrap(this[i]) === target)
|
|
2120
2120
|
return i;
|
|
2121
2121
|
return -1;
|
|
2122
2122
|
}
|
|
@@ -2124,11 +2124,11 @@ let ReactiveArrayWrapper = (() => {
|
|
|
2124
2124
|
return super.join(separator);
|
|
2125
2125
|
}
|
|
2126
2126
|
keys() {
|
|
2127
|
-
|
|
2127
|
+
effects.dependant(this, 'length');
|
|
2128
2128
|
return super.keys();
|
|
2129
2129
|
}
|
|
2130
2130
|
lastIndexOf(searchElement, fromIndex) {
|
|
2131
|
-
const target =
|
|
2131
|
+
const target = effects.unwrap(searchElement);
|
|
2132
2132
|
const length = this.length;
|
|
2133
2133
|
let start = fromIndex ?? length - 1;
|
|
2134
2134
|
if (start < 0)
|
|
@@ -2136,44 +2136,44 @@ let ReactiveArrayWrapper = (() => {
|
|
|
2136
2136
|
if (start >= length)
|
|
2137
2137
|
start = length - 1;
|
|
2138
2138
|
for (let i = start; i >= 0; i--)
|
|
2139
|
-
if (
|
|
2139
|
+
if (effects.unwrap(this[i]) === target)
|
|
2140
2140
|
return i;
|
|
2141
2141
|
return -1;
|
|
2142
2142
|
}
|
|
2143
2143
|
map(callbackfn, thisArg) {
|
|
2144
|
-
return
|
|
2144
|
+
return effects.reactive(super.map((v, i, a) => effects.unwrap(callbackfn.call(thisArg, effects.reactive(v), i, a)), thisArg));
|
|
2145
2145
|
}
|
|
2146
2146
|
pop() {
|
|
2147
|
-
return
|
|
2147
|
+
return effects.reactive(super.pop());
|
|
2148
2148
|
}
|
|
2149
2149
|
push(...items) {
|
|
2150
|
-
return super.push(...items.map(
|
|
2150
|
+
return super.push(...items.map(effects.unwrap));
|
|
2151
2151
|
}
|
|
2152
2152
|
reduce(callbackfn, initialValue) {
|
|
2153
|
-
return
|
|
2154
|
-
? super.reduce((acc, v, i, a) =>
|
|
2155
|
-
: super.reduce((acc, v, i, a) =>
|
|
2153
|
+
return effects.reactive(arguments.length > 1
|
|
2154
|
+
? super.reduce((acc, v, i, a) => effects.unwrap(callbackfn(acc, effects.reactive(v), i, a)), initialValue)
|
|
2155
|
+
: super.reduce((acc, v, i, a) => effects.unwrap(callbackfn(acc, effects.reactive(v), i, a))));
|
|
2156
2156
|
}
|
|
2157
2157
|
reduceRight(callbackfn, initialValue) {
|
|
2158
|
-
return
|
|
2159
|
-
? super.reduceRight((acc, v, i, a) =>
|
|
2160
|
-
: super.reduceRight((acc, v, i, a) =>
|
|
2158
|
+
return effects.reactive(arguments.length > 1
|
|
2159
|
+
? super.reduceRight((acc, v, i, a) => effects.unwrap(callbackfn(acc, effects.reactive(v), i, a)), initialValue)
|
|
2160
|
+
: super.reduceRight((acc, v, i, a) => effects.unwrap(callbackfn(acc, effects.reactive(v), i, a))));
|
|
2161
2161
|
}
|
|
2162
2162
|
reverse() {
|
|
2163
|
-
return
|
|
2163
|
+
return effects.reactive(super.reverse());
|
|
2164
2164
|
}
|
|
2165
2165
|
shift() {
|
|
2166
|
-
return
|
|
2166
|
+
return effects.reactive(super.shift());
|
|
2167
2167
|
}
|
|
2168
2168
|
slice(start, end) {
|
|
2169
|
-
return
|
|
2169
|
+
return effects.reactive(super.slice(start, end));
|
|
2170
2170
|
}
|
|
2171
2171
|
some(predicate, thisArg) {
|
|
2172
|
-
return super.some((v, i, a) => predicate.call(thisArg,
|
|
2172
|
+
return super.some((v, i, a) => predicate.call(thisArg, effects.reactive(v), i, a), thisArg);
|
|
2173
2173
|
}
|
|
2174
2174
|
sort(compareFn) {
|
|
2175
2175
|
const wrappedCompare = compareFn
|
|
2176
|
-
? (a, b) => compareFn(
|
|
2176
|
+
? (a, b) => compareFn(effects.reactive(a), effects.reactive(b))
|
|
2177
2177
|
: undefined;
|
|
2178
2178
|
return super.sort(wrappedCompare);
|
|
2179
2179
|
}
|
|
@@ -2186,7 +2186,7 @@ let ReactiveArrayWrapper = (() => {
|
|
|
2186
2186
|
const structural = actualDeleteCount > 0 || items.length > 0;
|
|
2187
2187
|
let result;
|
|
2188
2188
|
if (arguments.length > 2)
|
|
2189
|
-
result = super.splice(start, deleteCount, ...items.map(
|
|
2189
|
+
result = super.splice(start, deleteCount, ...items.map(effects.unwrap));
|
|
2190
2190
|
else if (arguments.length === 2)
|
|
2191
2191
|
result = super.splice(start, deleteCount);
|
|
2192
2192
|
else if (arguments.length === 1)
|
|
@@ -2194,58 +2194,58 @@ let ReactiveArrayWrapper = (() => {
|
|
|
2194
2194
|
else
|
|
2195
2195
|
result = [];
|
|
2196
2196
|
if (structural && this.length === length) {
|
|
2197
|
-
|
|
2197
|
+
effects.touched(this, { type: 'set', prop: 'length' }, ['length']);
|
|
2198
2198
|
}
|
|
2199
|
-
return
|
|
2199
|
+
return effects.reactive(result);
|
|
2200
2200
|
}
|
|
2201
2201
|
unshift(...items) {
|
|
2202
|
-
return super.unshift(...items.map(
|
|
2202
|
+
return super.unshift(...items.map(effects.unwrap));
|
|
2203
2203
|
}
|
|
2204
2204
|
values() {
|
|
2205
|
-
|
|
2205
|
+
effects.dependant(this, effects.keysOf);
|
|
2206
2206
|
return makeReactiveIterator(super.values());
|
|
2207
2207
|
}
|
|
2208
|
-
[(_fill_decorators = [
|
|
2209
|
-
|
|
2208
|
+
[(_fill_decorators = [effects.atomic], _copyWithin_decorators = [effects.atomic], _pop_decorators = [effects.atomic], _push_decorators = [effects.atomic], _reverse_decorators = [effects.atomic], _shift_decorators = [effects.atomic], _sort_decorators = [effects.atomic], _splice_decorators = [effects.atomic], _unshift_decorators = [effects.atomic], Symbol.iterator)]() {
|
|
2209
|
+
effects.dependant(this, effects.keysOf);
|
|
2210
2210
|
return makeReactiveIterator(super[Symbol.iterator]());
|
|
2211
2211
|
}
|
|
2212
2212
|
toReversed() {
|
|
2213
|
-
return
|
|
2213
|
+
return effects.reactive(super.toReversed());
|
|
2214
2214
|
}
|
|
2215
2215
|
toSorted(compareFn) {
|
|
2216
2216
|
const wrappedCompare = compareFn
|
|
2217
|
-
? (a, b) => compareFn(
|
|
2217
|
+
? (a, b) => compareFn(effects.reactive(a), effects.reactive(b))
|
|
2218
2218
|
: undefined;
|
|
2219
|
-
return
|
|
2219
|
+
return effects.reactive(super.toSorted(wrappedCompare));
|
|
2220
2220
|
}
|
|
2221
2221
|
toSpliced(start, deleteCount, ...items) {
|
|
2222
2222
|
if (arguments.length > 2)
|
|
2223
|
-
return
|
|
2223
|
+
return effects.reactive(super.toSpliced(start, deleteCount, ...items.map(effects.unwrap)));
|
|
2224
2224
|
if (arguments.length === 2)
|
|
2225
|
-
return
|
|
2225
|
+
return effects.reactive(super.toSpliced(start, deleteCount));
|
|
2226
2226
|
if (arguments.length === 1)
|
|
2227
|
-
return
|
|
2228
|
-
return
|
|
2227
|
+
return effects.reactive(super.toSpliced(start));
|
|
2228
|
+
return effects.reactive([...this]);
|
|
2229
2229
|
}
|
|
2230
2230
|
with(index, value) {
|
|
2231
|
-
return
|
|
2231
|
+
return effects.reactive(super.with(index, effects.unwrap(value)));
|
|
2232
2232
|
}
|
|
2233
2233
|
constructor() {
|
|
2234
2234
|
super(...arguments);
|
|
2235
|
-
|
|
2235
|
+
effects.__runInitializers(this, _instanceExtraInitializers);
|
|
2236
2236
|
}
|
|
2237
2237
|
},
|
|
2238
2238
|
(() => {
|
|
2239
2239
|
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2240
|
+
effects.__esDecorate(_a, null, _fill_decorators, { kind: "method", name: "fill", static: false, private: false, access: { has: obj => "fill" in obj, get: obj => obj.fill }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2241
|
+
effects.__esDecorate(_a, null, _copyWithin_decorators, { kind: "method", name: "copyWithin", static: false, private: false, access: { has: obj => "copyWithin" in obj, get: obj => obj.copyWithin }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2242
|
+
effects.__esDecorate(_a, null, _pop_decorators, { kind: "method", name: "pop", static: false, private: false, access: { has: obj => "pop" in obj, get: obj => obj.pop }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2243
|
+
effects.__esDecorate(_a, null, _push_decorators, { kind: "method", name: "push", static: false, private: false, access: { has: obj => "push" in obj, get: obj => obj.push }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2244
|
+
effects.__esDecorate(_a, null, _reverse_decorators, { kind: "method", name: "reverse", static: false, private: false, access: { has: obj => "reverse" in obj, get: obj => obj.reverse }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2245
|
+
effects.__esDecorate(_a, null, _shift_decorators, { kind: "method", name: "shift", static: false, private: false, access: { has: obj => "shift" in obj, get: obj => obj.shift }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2246
|
+
effects.__esDecorate(_a, null, _sort_decorators, { kind: "method", name: "sort", static: false, private: false, access: { has: obj => "sort" in obj, get: obj => obj.sort }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2247
|
+
effects.__esDecorate(_a, null, _splice_decorators, { kind: "method", name: "splice", static: false, private: false, access: { has: obj => "splice" in obj, get: obj => obj.splice }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2248
|
+
effects.__esDecorate(_a, null, _unshift_decorators, { kind: "method", name: "unshift", static: false, private: false, access: { has: obj => "unshift" in obj, get: obj => obj.unshift }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
2249
2249
|
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
2250
2250
|
})(),
|
|
2251
2251
|
_a;
|
|
@@ -2267,24 +2267,24 @@ class ReactiveWeakMap extends WeakMap {
|
|
|
2267
2267
|
const hadKey = this.has(key);
|
|
2268
2268
|
const result = super.delete(key);
|
|
2269
2269
|
if (hadKey)
|
|
2270
|
-
|
|
2270
|
+
effects.touched1(effects.contentRef(this), { type: 'del', prop: key }, key);
|
|
2271
2271
|
return result;
|
|
2272
2272
|
}
|
|
2273
2273
|
get(key) {
|
|
2274
|
-
|
|
2275
|
-
return
|
|
2274
|
+
effects.dependant(effects.contentRef(this), key);
|
|
2275
|
+
return effects.reactive(super.get(key));
|
|
2276
2276
|
}
|
|
2277
2277
|
has(key) {
|
|
2278
|
-
|
|
2278
|
+
effects.dependant(effects.contentRef(this), key);
|
|
2279
2279
|
return super.has(key);
|
|
2280
2280
|
}
|
|
2281
2281
|
set(key, value) {
|
|
2282
2282
|
const hadKey = this.has(key);
|
|
2283
2283
|
const oldValue = this.get(key);
|
|
2284
|
-
const reactiveValue =
|
|
2284
|
+
const reactiveValue = effects.reactive(value);
|
|
2285
2285
|
this.set(key, reactiveValue);
|
|
2286
2286
|
if (!hadKey || oldValue !== reactiveValue) {
|
|
2287
|
-
|
|
2287
|
+
effects.notifyPropertyChange(effects.contentRef(this), key, oldValue, reactiveValue, hadKey);
|
|
2288
2288
|
}
|
|
2289
2289
|
return this;
|
|
2290
2290
|
}
|
|
@@ -2296,7 +2296,7 @@ class ReactiveWeakMap extends WeakMap {
|
|
|
2296
2296
|
class ReactiveMap extends Map {
|
|
2297
2297
|
// Implement Map interface methods with reactivity
|
|
2298
2298
|
get size() {
|
|
2299
|
-
|
|
2299
|
+
effects.dependant(this, 'size'); // The ReactiveMap instance still goes through proxy
|
|
2300
2300
|
return super.size;
|
|
2301
2301
|
}
|
|
2302
2302
|
clear() {
|
|
@@ -2305,28 +2305,28 @@ class ReactiveMap extends Map {
|
|
|
2305
2305
|
if (hadEntries) {
|
|
2306
2306
|
const evolution = { type: 'bunch', method: 'clear' };
|
|
2307
2307
|
// Clear triggers all effects since all keys are affected
|
|
2308
|
-
|
|
2309
|
-
|
|
2308
|
+
effects.touched1(this, evolution, 'size');
|
|
2309
|
+
effects.touched(effects.contentRef(this), evolution);
|
|
2310
2310
|
}
|
|
2311
2311
|
}
|
|
2312
2312
|
entries() {
|
|
2313
|
-
|
|
2313
|
+
effects.dependant(effects.contentRef(this));
|
|
2314
2314
|
return makeReactiveEntriesIterator(this.entries());
|
|
2315
2315
|
}
|
|
2316
2316
|
forEach(callbackfn, thisArg) {
|
|
2317
|
-
|
|
2317
|
+
effects.dependant(effects.contentRef(this));
|
|
2318
2318
|
this.forEach(callbackfn, thisArg);
|
|
2319
2319
|
}
|
|
2320
2320
|
keys() {
|
|
2321
|
-
|
|
2321
|
+
effects.dependant(effects.contentRef(this), effects.keysOf);
|
|
2322
2322
|
return this.keys();
|
|
2323
2323
|
}
|
|
2324
2324
|
values() {
|
|
2325
|
-
|
|
2325
|
+
effects.dependant(effects.contentRef(this));
|
|
2326
2326
|
return makeReactiveIterator(this.values());
|
|
2327
2327
|
}
|
|
2328
2328
|
[Symbol.iterator]() {
|
|
2329
|
-
|
|
2329
|
+
effects.dependant(effects.contentRef(this));
|
|
2330
2330
|
const it = Map.prototype[Symbol.iterator].call(this);
|
|
2331
2331
|
const nativeNext = it.next.bind(it);
|
|
2332
2332
|
it.next = () => {
|
|
@@ -2334,7 +2334,7 @@ class ReactiveMap extends Map {
|
|
|
2334
2334
|
if (result.done)
|
|
2335
2335
|
return result;
|
|
2336
2336
|
const [key, value] = result.value;
|
|
2337
|
-
return { value: [
|
|
2337
|
+
return { value: [effects.reactive(key), effects.reactive(value)], done: false };
|
|
2338
2338
|
};
|
|
2339
2339
|
return it;
|
|
2340
2340
|
}
|
|
@@ -2344,29 +2344,29 @@ class ReactiveMap extends Map {
|
|
|
2344
2344
|
const result = super.delete(key);
|
|
2345
2345
|
if (hadKey) {
|
|
2346
2346
|
const evolution = { type: 'del', prop: key };
|
|
2347
|
-
|
|
2348
|
-
|
|
2347
|
+
effects.touched1(effects.contentRef(this), evolution, key);
|
|
2348
|
+
effects.touched1(this, evolution, 'size');
|
|
2349
2349
|
}
|
|
2350
2350
|
return result;
|
|
2351
2351
|
}
|
|
2352
2352
|
get(key) {
|
|
2353
|
-
|
|
2354
|
-
return
|
|
2353
|
+
effects.dependant(effects.contentRef(this), key);
|
|
2354
|
+
return effects.reactive(super.get(key));
|
|
2355
2355
|
}
|
|
2356
2356
|
has(key) {
|
|
2357
|
-
|
|
2357
|
+
effects.dependant(effects.contentRef(this), key);
|
|
2358
2358
|
return super.has(key);
|
|
2359
2359
|
}
|
|
2360
2360
|
set(key, value) {
|
|
2361
2361
|
const hadKey = this.has(key);
|
|
2362
2362
|
const oldValue = this.get(key);
|
|
2363
|
-
const reactiveValue =
|
|
2363
|
+
const reactiveValue = effects.reactive(value);
|
|
2364
2364
|
super.set(key, reactiveValue);
|
|
2365
2365
|
if (!hadKey || oldValue !== reactiveValue) {
|
|
2366
|
-
|
|
2366
|
+
effects.notifyPropertyChange(effects.contentRef(this), key, oldValue, reactiveValue, hadKey);
|
|
2367
2367
|
// Also notify size change for Map (WeakMap doesn't track size)
|
|
2368
2368
|
const evolution = { type: hadKey ? 'set' : 'add', prop: key };
|
|
2369
|
-
|
|
2369
|
+
effects.touched1(this, evolution, 'size');
|
|
2370
2370
|
}
|
|
2371
2371
|
return this;
|
|
2372
2372
|
}
|
|
@@ -2388,7 +2388,7 @@ class ReactiveWeakSet extends WeakSet {
|
|
|
2388
2388
|
super.add(value);
|
|
2389
2389
|
if (!had) {
|
|
2390
2390
|
// touch the specific value and the collection view
|
|
2391
|
-
|
|
2391
|
+
effects.touched1(effects.contentRef(this), { type: 'add', prop: value }, value);
|
|
2392
2392
|
// no size/allProps for WeakSet
|
|
2393
2393
|
}
|
|
2394
2394
|
return this;
|
|
@@ -2397,11 +2397,11 @@ class ReactiveWeakSet extends WeakSet {
|
|
|
2397
2397
|
const had = this.has(value);
|
|
2398
2398
|
const res = super.delete(value);
|
|
2399
2399
|
if (had)
|
|
2400
|
-
|
|
2400
|
+
effects.touched1(effects.contentRef(this), { type: 'del', prop: value }, value);
|
|
2401
2401
|
return res;
|
|
2402
2402
|
}
|
|
2403
2403
|
has(value) {
|
|
2404
|
-
|
|
2404
|
+
effects.dependant(effects.contentRef(this), value);
|
|
2405
2405
|
return super.has(value);
|
|
2406
2406
|
}
|
|
2407
2407
|
}
|
|
@@ -2412,18 +2412,18 @@ class ReactiveWeakSet extends WeakSet {
|
|
|
2412
2412
|
class ReactiveSet extends Set {
|
|
2413
2413
|
get size() {
|
|
2414
2414
|
// size depends on the wrapper instance, like Map counterpart
|
|
2415
|
-
|
|
2415
|
+
effects.dependant(this, 'size');
|
|
2416
2416
|
return this.size;
|
|
2417
2417
|
}
|
|
2418
2418
|
add(value) {
|
|
2419
2419
|
const had = this.has(value);
|
|
2420
|
-
const reactiveValue =
|
|
2420
|
+
const reactiveValue = effects.reactive(value);
|
|
2421
2421
|
super.add(reactiveValue);
|
|
2422
2422
|
if (!had) {
|
|
2423
2423
|
const evolution = { type: 'add', prop: reactiveValue };
|
|
2424
2424
|
// touch for value-specific and aggregate dependencies
|
|
2425
|
-
|
|
2426
|
-
|
|
2425
|
+
effects.touched1(effects.contentRef(this), evolution, reactiveValue);
|
|
2426
|
+
effects.touched1(this, evolution, 'size');
|
|
2427
2427
|
}
|
|
2428
2428
|
return this;
|
|
2429
2429
|
}
|
|
@@ -2432,8 +2432,8 @@ class ReactiveSet extends Set {
|
|
|
2432
2432
|
super.clear();
|
|
2433
2433
|
if (hadEntries) {
|
|
2434
2434
|
const evolution = { type: 'bunch', method: 'clear' };
|
|
2435
|
-
|
|
2436
|
-
|
|
2435
|
+
effects.touched1(this, evolution, 'size');
|
|
2436
|
+
effects.touched(effects.contentRef(this), evolution);
|
|
2437
2437
|
}
|
|
2438
2438
|
}
|
|
2439
2439
|
delete(value) {
|
|
@@ -2441,64 +2441,64 @@ class ReactiveSet extends Set {
|
|
|
2441
2441
|
const res = super.delete(value);
|
|
2442
2442
|
if (had) {
|
|
2443
2443
|
const evolution = { type: 'del', prop: value };
|
|
2444
|
-
|
|
2445
|
-
|
|
2444
|
+
effects.touched1(effects.contentRef(this), evolution, value);
|
|
2445
|
+
effects.touched1(this, evolution, 'size');
|
|
2446
2446
|
}
|
|
2447
2447
|
return res;
|
|
2448
2448
|
}
|
|
2449
2449
|
has(value) {
|
|
2450
|
-
|
|
2450
|
+
effects.dependant(effects.contentRef(this), value);
|
|
2451
2451
|
return this.has(value);
|
|
2452
2452
|
}
|
|
2453
2453
|
entries() {
|
|
2454
|
-
|
|
2454
|
+
effects.dependant(effects.contentRef(this));
|
|
2455
2455
|
return makeReactiveEntriesIterator(this.entries());
|
|
2456
2456
|
}
|
|
2457
2457
|
forEach(callbackfn, thisArg) {
|
|
2458
|
-
|
|
2458
|
+
effects.dependant(effects.contentRef(this));
|
|
2459
2459
|
this.forEach(callbackfn, thisArg);
|
|
2460
2460
|
}
|
|
2461
2461
|
keys() {
|
|
2462
|
-
|
|
2462
|
+
effects.dependant(effects.contentRef(this));
|
|
2463
2463
|
return makeReactiveIterator(this.keys());
|
|
2464
2464
|
}
|
|
2465
2465
|
values() {
|
|
2466
|
-
|
|
2466
|
+
effects.dependant(effects.contentRef(this));
|
|
2467
2467
|
return makeReactiveIterator(this.values());
|
|
2468
2468
|
}
|
|
2469
2469
|
[Symbol.iterator]() {
|
|
2470
|
-
|
|
2470
|
+
effects.dependant(effects.contentRef(this));
|
|
2471
2471
|
const it = Set.prototype[Symbol.iterator].call(this);
|
|
2472
2472
|
const nativeNext = it.next.bind(it);
|
|
2473
2473
|
it.next = () => {
|
|
2474
2474
|
const result = nativeNext();
|
|
2475
2475
|
if (result.done)
|
|
2476
2476
|
return result;
|
|
2477
|
-
return { value:
|
|
2477
|
+
return { value: effects.reactive(result.value), done: false };
|
|
2478
2478
|
};
|
|
2479
2479
|
return it;
|
|
2480
2480
|
}
|
|
2481
2481
|
}
|
|
2482
2482
|
|
|
2483
2483
|
// Register native collection types to use specialized reactive wrappers
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2484
|
+
effects.metaProtos.set(Array, ReactiveArray.prototype);
|
|
2485
|
+
effects.metaProtos.set(Set, ReactiveSet.prototype);
|
|
2486
|
+
effects.metaProtos.set(WeakSet, ReactiveWeakSet.prototype);
|
|
2487
|
+
effects.metaProtos.set(Map, ReactiveMap.prototype);
|
|
2488
|
+
effects.metaProtos.set(WeakMap, ReactiveWeakMap.prototype);
|
|
2489
|
+
effects.wrapProtos.set(Array, ReactiveArrayWrapper.prototype);
|
|
2490
2490
|
/**
|
|
2491
2491
|
* Object containing internal reactive system state for debugging and profiling
|
|
2492
2492
|
*/
|
|
2493
2493
|
const profileInfo = {
|
|
2494
|
-
objectToProxy:
|
|
2495
|
-
proxyToObject:
|
|
2496
|
-
effectToReactiveObjects:
|
|
2497
|
-
watchers:
|
|
2498
|
-
objectParents:
|
|
2499
|
-
objectsWithDeepWatchers:
|
|
2500
|
-
deepWatchers:
|
|
2501
|
-
effectToDeepWatchedObjects:
|
|
2494
|
+
objectToProxy: effects.objectToProxy,
|
|
2495
|
+
proxyToObject: effects.proxyToObject,
|
|
2496
|
+
effectToReactiveObjects: effects.effectToReactiveObjects,
|
|
2497
|
+
watchers: effects.watchers,
|
|
2498
|
+
objectParents: effects.objectParents,
|
|
2499
|
+
objectsWithDeepWatchers: effects.objectsWithDeepWatchers,
|
|
2500
|
+
deepWatchers: effects.deepWatchers,
|
|
2501
|
+
effectToDeepWatchedObjects: effects.effectToDeepWatchedObjects,
|
|
2502
2502
|
};
|
|
2503
2503
|
|
|
2504
2504
|
// In order to avoid async re-entrance, we could use zone.js or something like that.
|
|
@@ -2507,7 +2507,7 @@ const syncCalculating = [];
|
|
|
2507
2507
|
* Decorator that caches the result of a getter method and only recomputes when dependencies change
|
|
2508
2508
|
* Prevents circular dependencies and provides automatic cache invalidation
|
|
2509
2509
|
*/
|
|
2510
|
-
const cached =
|
|
2510
|
+
const cached = effects.decorator({
|
|
2511
2511
|
getter(original, _target, propertyKey) {
|
|
2512
2512
|
return function () {
|
|
2513
2513
|
const alreadyCalculating = syncCalculating.findIndex((c) => c.object === this && c.prop === propertyKey);
|
|
@@ -2608,7 +2608,7 @@ const descriptor = Object.assign(descriptorBase, {
|
|
|
2608
2608
|
* Decorator that marks methods, properties, or classes as deprecated
|
|
2609
2609
|
* Provides warning messages when deprecated items are used
|
|
2610
2610
|
*/
|
|
2611
|
-
const deprecated = Object.assign(
|
|
2611
|
+
const deprecated = Object.assign(effects.decorator({
|
|
2612
2612
|
method(original, _target, propertyKey) {
|
|
2613
2613
|
return function (...args) {
|
|
2614
2614
|
deprecated.warn(this, propertyKey);
|
|
@@ -2636,7 +2636,7 @@ const deprecated = Object.assign(proxy.decorator({
|
|
|
2636
2636
|
};
|
|
2637
2637
|
},
|
|
2638
2638
|
default(message) {
|
|
2639
|
-
return
|
|
2639
|
+
return effects.decorator({
|
|
2640
2640
|
method(original, _target, propertyKey) {
|
|
2641
2641
|
return function (...args) {
|
|
2642
2642
|
deprecated.warn(this, propertyKey, message);
|
|
@@ -2667,7 +2667,7 @@ const deprecated = Object.assign(proxy.decorator({
|
|
|
2667
2667
|
},
|
|
2668
2668
|
}), {
|
|
2669
2669
|
warn: (target, propertyKey, message) => {
|
|
2670
|
-
|
|
2670
|
+
effects.options.warn(`${target.constructor.name}.${String(propertyKey)} is deprecated${message ? `: ${message}` : ''}`);
|
|
2671
2671
|
},
|
|
2672
2672
|
});
|
|
2673
2673
|
/**
|
|
@@ -2676,7 +2676,7 @@ const deprecated = Object.assign(proxy.decorator({
|
|
|
2676
2676
|
* @returns A method decorator that debounces method calls
|
|
2677
2677
|
*/
|
|
2678
2678
|
function debounce(delay) {
|
|
2679
|
-
return
|
|
2679
|
+
return effects.decorator({
|
|
2680
2680
|
method(original, _target, _propertyKey) {
|
|
2681
2681
|
let timeoutId = null;
|
|
2682
2682
|
return function (...args) {
|
|
@@ -2699,7 +2699,7 @@ function debounce(delay) {
|
|
|
2699
2699
|
* @returns A method decorator that throttles method calls
|
|
2700
2700
|
*/
|
|
2701
2701
|
function throttle(delay) {
|
|
2702
|
-
return
|
|
2702
|
+
return effects.decorator({
|
|
2703
2703
|
method(original, _target, _propertyKey) {
|
|
2704
2704
|
let lastCallTime = 0;
|
|
2705
2705
|
let timeoutId = null;
|
|
@@ -2730,7 +2730,7 @@ function throttle(delay) {
|
|
|
2730
2730
|
});
|
|
2731
2731
|
}
|
|
2732
2732
|
|
|
2733
|
-
var version$1 = "1.0.
|
|
2733
|
+
var version$1 = "1.0.15";
|
|
2734
2734
|
var pkg = {
|
|
2735
2735
|
version: version$1};
|
|
2736
2736
|
|
|
@@ -2749,8 +2749,8 @@ if (globalScope) {
|
|
|
2749
2749
|
try {
|
|
2750
2750
|
if (runtimeGlobals.__filename)
|
|
2751
2751
|
source = runtimeGlobals.__filename;
|
|
2752
|
-
else if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index-
|
|
2753
|
-
source = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index-
|
|
2752
|
+
else if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index-Dtj2qZ0d.cjs', document.baseURI).href)) }) !== 'undefined' && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index-Dtj2qZ0d.cjs', document.baseURI).href))) {
|
|
2753
|
+
source = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunks/index-Dtj2qZ0d.cjs', document.baseURI).href));
|
|
2754
2754
|
}
|
|
2755
2755
|
}
|
|
2756
2756
|
catch (_e) { }
|
|
@@ -2800,4 +2800,4 @@ exports.throttle = throttle;
|
|
|
2800
2800
|
exports.unreactive = unreactive;
|
|
2801
2801
|
exports.watch = watch;
|
|
2802
2802
|
exports.when = when;
|
|
2803
|
-
//# sourceMappingURL=index-
|
|
2803
|
+
//# sourceMappingURL=index-Dtj2qZ0d.cjs.map
|