@flexsurfer/reflex 0.1.21 → 0.1.23
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/index.cjs +56 -44
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +56 -45
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(src_exports, {
|
|
|
45
45
|
defaultErrorHandler: () => defaultErrorHandler,
|
|
46
46
|
disableTracing: () => disableTracing,
|
|
47
47
|
dispatch: () => dispatch,
|
|
48
|
+
enableMapSet: () => enableMapSet,
|
|
48
49
|
enableTracePrint: () => enableTracePrint,
|
|
49
50
|
enableTracing: () => enableTracing,
|
|
50
51
|
getAppDb: () => getAppDb,
|
|
@@ -258,12 +259,63 @@ function updateAppDbWithPatches(newDb, patches) {
|
|
|
258
259
|
|
|
259
260
|
// src/immer-utils.ts
|
|
260
261
|
var import_immer = require("immer");
|
|
262
|
+
|
|
263
|
+
// src/settings.ts
|
|
264
|
+
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
265
|
+
var store = {
|
|
266
|
+
globalInterceptors: [],
|
|
267
|
+
globalEqualityCheck: import_fast_deep_equal.default
|
|
268
|
+
};
|
|
269
|
+
function replaceGlobalInterceptor(globalInterceptors, interceptor) {
|
|
270
|
+
return globalInterceptors.reduce((ret, existingInterceptor) => {
|
|
271
|
+
if (interceptor.id === existingInterceptor.id) {
|
|
272
|
+
return [...ret, interceptor];
|
|
273
|
+
} else {
|
|
274
|
+
return [...ret, existingInterceptor];
|
|
275
|
+
}
|
|
276
|
+
}, []);
|
|
277
|
+
}
|
|
278
|
+
function regGlobalInterceptor(interceptor) {
|
|
279
|
+
const { id } = interceptor;
|
|
280
|
+
const ids = store.globalInterceptors.map((i) => i.id);
|
|
281
|
+
if (ids.includes(id)) {
|
|
282
|
+
store.globalInterceptors = replaceGlobalInterceptor(store.globalInterceptors, interceptor);
|
|
283
|
+
} else {
|
|
284
|
+
store.globalInterceptors = [...store.globalInterceptors, interceptor];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function getGlobalInterceptors() {
|
|
288
|
+
return [...store.globalInterceptors];
|
|
289
|
+
}
|
|
290
|
+
function clearGlobalInterceptors(id) {
|
|
291
|
+
if (id === void 0) {
|
|
292
|
+
store.globalInterceptors = [];
|
|
293
|
+
} else {
|
|
294
|
+
store.globalInterceptors = store.globalInterceptors.filter((interceptor) => interceptor.id !== id);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function setGlobalEqualityCheck(equalityCheck) {
|
|
298
|
+
store.globalEqualityCheck = equalityCheck;
|
|
299
|
+
}
|
|
300
|
+
function getGlobalEqualityCheck() {
|
|
301
|
+
return store.globalEqualityCheck;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// src/immer-utils.ts
|
|
305
|
+
var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"), 1);
|
|
306
|
+
var import_es6 = __toESM(require("fast-deep-equal/es6/index.js"), 1);
|
|
261
307
|
function original(value) {
|
|
262
308
|
return (0, import_immer.isDraft)(value) ? (0, import_immer.original)(value) : value;
|
|
263
309
|
}
|
|
264
310
|
function current(value) {
|
|
265
311
|
return (0, import_immer.isDraft)(value) ? (0, import_immer.current)(value) : value;
|
|
266
312
|
}
|
|
313
|
+
function enableMapSet() {
|
|
314
|
+
(0, import_immer.enableMapSet)();
|
|
315
|
+
if (getGlobalEqualityCheck() === import_fast_deep_equal2.default) {
|
|
316
|
+
setGlobalEqualityCheck(import_es6.default);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
267
319
|
|
|
268
320
|
// src/interceptor.ts
|
|
269
321
|
function isInterceptor(m) {
|
|
@@ -600,47 +652,6 @@ regEffect(DISPATCH, (value) => {
|
|
|
600
652
|
// src/events.ts
|
|
601
653
|
var import_immer2 = require("immer");
|
|
602
654
|
|
|
603
|
-
// src/settings.ts
|
|
604
|
-
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
605
|
-
var store = {
|
|
606
|
-
globalInterceptors: [],
|
|
607
|
-
globalEqualityCheck: import_fast_deep_equal.default
|
|
608
|
-
};
|
|
609
|
-
function replaceGlobalInterceptor(globalInterceptors, interceptor) {
|
|
610
|
-
return globalInterceptors.reduce((ret, existingInterceptor) => {
|
|
611
|
-
if (interceptor.id === existingInterceptor.id) {
|
|
612
|
-
return [...ret, interceptor];
|
|
613
|
-
} else {
|
|
614
|
-
return [...ret, existingInterceptor];
|
|
615
|
-
}
|
|
616
|
-
}, []);
|
|
617
|
-
}
|
|
618
|
-
function regGlobalInterceptor(interceptor) {
|
|
619
|
-
const { id } = interceptor;
|
|
620
|
-
const ids = store.globalInterceptors.map((i) => i.id);
|
|
621
|
-
if (ids.includes(id)) {
|
|
622
|
-
store.globalInterceptors = replaceGlobalInterceptor(store.globalInterceptors, interceptor);
|
|
623
|
-
} else {
|
|
624
|
-
store.globalInterceptors = [...store.globalInterceptors, interceptor];
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
function getGlobalInterceptors() {
|
|
628
|
-
return [...store.globalInterceptors];
|
|
629
|
-
}
|
|
630
|
-
function clearGlobalInterceptors(id) {
|
|
631
|
-
if (id === void 0) {
|
|
632
|
-
store.globalInterceptors = [];
|
|
633
|
-
} else {
|
|
634
|
-
store.globalInterceptors = store.globalInterceptors.filter((interceptor) => interceptor.id !== id);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
function setGlobalEqualityCheck(equalityCheck) {
|
|
638
|
-
store.globalEqualityCheck = equalityCheck;
|
|
639
|
-
}
|
|
640
|
-
function getGlobalEqualityCheck() {
|
|
641
|
-
return store.globalEqualityCheck;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
655
|
// src/trace.ts
|
|
645
656
|
var nextId = 1;
|
|
646
657
|
var traces = [];
|
|
@@ -875,7 +886,7 @@ function defaultErrorHandler(originalError, reflexError) {
|
|
|
875
886
|
regEventErrorHandler(defaultErrorHandler);
|
|
876
887
|
|
|
877
888
|
// src/reaction.ts
|
|
878
|
-
var
|
|
889
|
+
var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"), 1);
|
|
879
890
|
var Reaction = class _Reaction {
|
|
880
891
|
id = "";
|
|
881
892
|
computeFn;
|
|
@@ -892,7 +903,7 @@ var Reaction = class _Reaction {
|
|
|
892
903
|
constructor(computeFn, deps, equalityCheck) {
|
|
893
904
|
this.computeFn = computeFn;
|
|
894
905
|
this.deps = deps;
|
|
895
|
-
this.equalityCheck = equalityCheck ||
|
|
906
|
+
this.equalityCheck = equalityCheck || import_fast_deep_equal3.default;
|
|
896
907
|
}
|
|
897
908
|
static create(fn, deps, equalityCheck) {
|
|
898
909
|
return new _Reaction(fn, deps, equalityCheck);
|
|
@@ -961,7 +972,7 @@ var Reaction = class _Reaction {
|
|
|
961
972
|
const depValues = this.deps?.map((d) => d.getDepValue(notifyWatchers)) ?? [];
|
|
962
973
|
const values = depValues.map(([value]) => value);
|
|
963
974
|
const currentVersions = depValues.map(([, version]) => version);
|
|
964
|
-
const versionsChanged = !(0,
|
|
975
|
+
const versionsChanged = !(0, import_fast_deep_equal3.default)(currentVersions, this.depsVersions);
|
|
965
976
|
if (this.value === void 0 || versionsChanged) {
|
|
966
977
|
let newVal = this.computeFn(...values);
|
|
967
978
|
changed = !this.equalityCheck(newVal, this.value);
|
|
@@ -1279,6 +1290,7 @@ function HotReloadWrapper({ children }) {
|
|
|
1279
1290
|
defaultErrorHandler,
|
|
1280
1291
|
disableTracing,
|
|
1281
1292
|
dispatch,
|
|
1293
|
+
enableMapSet,
|
|
1282
1294
|
enableTracePrint,
|
|
1283
1295
|
enableTracing,
|
|
1284
1296
|
getAppDb,
|
package/dist/index.d.cts
CHANGED
|
@@ -62,6 +62,13 @@ declare function original<T>(value: T): T;
|
|
|
62
62
|
* otherwise returns the value as-is
|
|
63
63
|
*/
|
|
64
64
|
declare function current<T>(value: T): T;
|
|
65
|
+
/**
|
|
66
|
+
* Enable Map and Set support in Immer
|
|
67
|
+
* This allows Immer to handle Map and Set objects properly in drafts
|
|
68
|
+
* Also updates the global equality check to use fast-deep-equal/es6 for proper Map/Set comparison,
|
|
69
|
+
* but only if the current equality check is still the default isEqual
|
|
70
|
+
*/
|
|
71
|
+
declare function enableMapSet(): void;
|
|
65
72
|
|
|
66
73
|
/** Register an event handler with only a handler function (db event) */
|
|
67
74
|
declare function regEvent<T = Record<string, any>>(id: Id, handler: EventHandler<T>): void;
|
|
@@ -268,4 +275,4 @@ declare function registerTraceCb(key: string, cb: TraceCallback): void;
|
|
|
268
275
|
declare function removeTraceCb(key: string): void;
|
|
269
276
|
declare function enableTracePrint(): void;
|
|
270
277
|
|
|
271
|
-
export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, EqualityCheckFn, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubConfig, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalEqualityCheck, getGlobalInterceptors, getHandler, getHandlers, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, removeTraceCb, setGlobalEqualityCheck, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
|
278
|
+
export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, EqualityCheckFn, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubConfig, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableMapSet, enableTracePrint, enableTracing, getAppDb, getGlobalEqualityCheck, getGlobalInterceptors, getHandler, getHandlers, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, removeTraceCb, setGlobalEqualityCheck, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,13 @@ declare function original<T>(value: T): T;
|
|
|
62
62
|
* otherwise returns the value as-is
|
|
63
63
|
*/
|
|
64
64
|
declare function current<T>(value: T): T;
|
|
65
|
+
/**
|
|
66
|
+
* Enable Map and Set support in Immer
|
|
67
|
+
* This allows Immer to handle Map and Set objects properly in drafts
|
|
68
|
+
* Also updates the global equality check to use fast-deep-equal/es6 for proper Map/Set comparison,
|
|
69
|
+
* but only if the current equality check is still the default isEqual
|
|
70
|
+
*/
|
|
71
|
+
declare function enableMapSet(): void;
|
|
65
72
|
|
|
66
73
|
/** Register an event handler with only a handler function (db event) */
|
|
67
74
|
declare function regEvent<T = Record<string, any>>(id: Id, handler: EventHandler<T>): void;
|
|
@@ -268,4 +275,4 @@ declare function registerTraceCb(key: string, cb: TraceCallback): void;
|
|
|
268
275
|
declare function removeTraceCb(key: string): void;
|
|
269
276
|
declare function enableTracePrint(): void;
|
|
270
277
|
|
|
271
|
-
export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, EqualityCheckFn, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubConfig, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalEqualityCheck, getGlobalInterceptors, getHandler, getHandlers, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, removeTraceCb, setGlobalEqualityCheck, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
|
278
|
+
export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, EqualityCheckFn, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubConfig, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableMapSet, enableTracePrint, enableTracing, getAppDb, getGlobalEqualityCheck, getGlobalInterceptors, getHandler, getHandlers, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, removeTraceCb, setGlobalEqualityCheck, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
package/dist/index.mjs
CHANGED
|
@@ -180,13 +180,64 @@ function updateAppDbWithPatches(newDb, patches) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
// src/immer-utils.ts
|
|
183
|
-
import { isDraft, original as immerOriginal, current as immerCurrent } from "immer";
|
|
183
|
+
import { isDraft, original as immerOriginal, current as immerCurrent, enableMapSet as immerEnableMapSet } from "immer";
|
|
184
|
+
|
|
185
|
+
// src/settings.ts
|
|
186
|
+
import isEqual from "fast-deep-equal";
|
|
187
|
+
var store = {
|
|
188
|
+
globalInterceptors: [],
|
|
189
|
+
globalEqualityCheck: isEqual
|
|
190
|
+
};
|
|
191
|
+
function replaceGlobalInterceptor(globalInterceptors, interceptor) {
|
|
192
|
+
return globalInterceptors.reduce((ret, existingInterceptor) => {
|
|
193
|
+
if (interceptor.id === existingInterceptor.id) {
|
|
194
|
+
return [...ret, interceptor];
|
|
195
|
+
} else {
|
|
196
|
+
return [...ret, existingInterceptor];
|
|
197
|
+
}
|
|
198
|
+
}, []);
|
|
199
|
+
}
|
|
200
|
+
function regGlobalInterceptor(interceptor) {
|
|
201
|
+
const { id } = interceptor;
|
|
202
|
+
const ids = store.globalInterceptors.map((i) => i.id);
|
|
203
|
+
if (ids.includes(id)) {
|
|
204
|
+
store.globalInterceptors = replaceGlobalInterceptor(store.globalInterceptors, interceptor);
|
|
205
|
+
} else {
|
|
206
|
+
store.globalInterceptors = [...store.globalInterceptors, interceptor];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function getGlobalInterceptors() {
|
|
210
|
+
return [...store.globalInterceptors];
|
|
211
|
+
}
|
|
212
|
+
function clearGlobalInterceptors(id) {
|
|
213
|
+
if (id === void 0) {
|
|
214
|
+
store.globalInterceptors = [];
|
|
215
|
+
} else {
|
|
216
|
+
store.globalInterceptors = store.globalInterceptors.filter((interceptor) => interceptor.id !== id);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function setGlobalEqualityCheck(equalityCheck) {
|
|
220
|
+
store.globalEqualityCheck = equalityCheck;
|
|
221
|
+
}
|
|
222
|
+
function getGlobalEqualityCheck() {
|
|
223
|
+
return store.globalEqualityCheck;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/immer-utils.ts
|
|
227
|
+
import isEqual2 from "fast-deep-equal";
|
|
228
|
+
import isEqualEs6 from "fast-deep-equal/es6/index.js";
|
|
184
229
|
function original(value) {
|
|
185
230
|
return isDraft(value) ? immerOriginal(value) : value;
|
|
186
231
|
}
|
|
187
232
|
function current(value) {
|
|
188
233
|
return isDraft(value) ? immerCurrent(value) : value;
|
|
189
234
|
}
|
|
235
|
+
function enableMapSet() {
|
|
236
|
+
immerEnableMapSet();
|
|
237
|
+
if (getGlobalEqualityCheck() === isEqual2) {
|
|
238
|
+
setGlobalEqualityCheck(isEqualEs6);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
190
241
|
|
|
191
242
|
// src/interceptor.ts
|
|
192
243
|
function isInterceptor(m) {
|
|
@@ -523,47 +574,6 @@ regEffect(DISPATCH, (value) => {
|
|
|
523
574
|
// src/events.ts
|
|
524
575
|
import { enablePatches, produceWithPatches } from "immer";
|
|
525
576
|
|
|
526
|
-
// src/settings.ts
|
|
527
|
-
import isEqual from "fast-deep-equal";
|
|
528
|
-
var store = {
|
|
529
|
-
globalInterceptors: [],
|
|
530
|
-
globalEqualityCheck: isEqual
|
|
531
|
-
};
|
|
532
|
-
function replaceGlobalInterceptor(globalInterceptors, interceptor) {
|
|
533
|
-
return globalInterceptors.reduce((ret, existingInterceptor) => {
|
|
534
|
-
if (interceptor.id === existingInterceptor.id) {
|
|
535
|
-
return [...ret, interceptor];
|
|
536
|
-
} else {
|
|
537
|
-
return [...ret, existingInterceptor];
|
|
538
|
-
}
|
|
539
|
-
}, []);
|
|
540
|
-
}
|
|
541
|
-
function regGlobalInterceptor(interceptor) {
|
|
542
|
-
const { id } = interceptor;
|
|
543
|
-
const ids = store.globalInterceptors.map((i) => i.id);
|
|
544
|
-
if (ids.includes(id)) {
|
|
545
|
-
store.globalInterceptors = replaceGlobalInterceptor(store.globalInterceptors, interceptor);
|
|
546
|
-
} else {
|
|
547
|
-
store.globalInterceptors = [...store.globalInterceptors, interceptor];
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
function getGlobalInterceptors() {
|
|
551
|
-
return [...store.globalInterceptors];
|
|
552
|
-
}
|
|
553
|
-
function clearGlobalInterceptors(id) {
|
|
554
|
-
if (id === void 0) {
|
|
555
|
-
store.globalInterceptors = [];
|
|
556
|
-
} else {
|
|
557
|
-
store.globalInterceptors = store.globalInterceptors.filter((interceptor) => interceptor.id !== id);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
function setGlobalEqualityCheck(equalityCheck) {
|
|
561
|
-
store.globalEqualityCheck = equalityCheck;
|
|
562
|
-
}
|
|
563
|
-
function getGlobalEqualityCheck() {
|
|
564
|
-
return store.globalEqualityCheck;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
577
|
// src/trace.ts
|
|
568
578
|
var nextId = 1;
|
|
569
579
|
var traces = [];
|
|
@@ -798,7 +808,7 @@ function defaultErrorHandler(originalError, reflexError) {
|
|
|
798
808
|
regEventErrorHandler(defaultErrorHandler);
|
|
799
809
|
|
|
800
810
|
// src/reaction.ts
|
|
801
|
-
import
|
|
811
|
+
import isEqual3 from "fast-deep-equal";
|
|
802
812
|
var Reaction = class _Reaction {
|
|
803
813
|
id = "";
|
|
804
814
|
computeFn;
|
|
@@ -815,7 +825,7 @@ var Reaction = class _Reaction {
|
|
|
815
825
|
constructor(computeFn, deps, equalityCheck) {
|
|
816
826
|
this.computeFn = computeFn;
|
|
817
827
|
this.deps = deps;
|
|
818
|
-
this.equalityCheck = equalityCheck ||
|
|
828
|
+
this.equalityCheck = equalityCheck || isEqual3;
|
|
819
829
|
}
|
|
820
830
|
static create(fn, deps, equalityCheck) {
|
|
821
831
|
return new _Reaction(fn, deps, equalityCheck);
|
|
@@ -884,7 +894,7 @@ var Reaction = class _Reaction {
|
|
|
884
894
|
const depValues = this.deps?.map((d) => d.getDepValue(notifyWatchers)) ?? [];
|
|
885
895
|
const values = depValues.map(([value]) => value);
|
|
886
896
|
const currentVersions = depValues.map(([, version]) => version);
|
|
887
|
-
const versionsChanged = !
|
|
897
|
+
const versionsChanged = !isEqual3(currentVersions, this.depsVersions);
|
|
888
898
|
if (this.value === void 0 || versionsChanged) {
|
|
889
899
|
let newVal = this.computeFn(...values);
|
|
890
900
|
changed = !this.equalityCheck(newVal, this.value);
|
|
@@ -1201,6 +1211,7 @@ export {
|
|
|
1201
1211
|
defaultErrorHandler,
|
|
1202
1212
|
disableTracing,
|
|
1203
1213
|
dispatch,
|
|
1214
|
+
enableMapSet,
|
|
1204
1215
|
enableTracePrint,
|
|
1205
1216
|
enableTracing,
|
|
1206
1217
|
getAppDb,
|