@flexsurfer/reflex 0.1.8 → 0.1.10
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 +10 -15
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +9 -15
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(src_exports, {
|
|
|
42
42
|
dispatch: () => dispatch,
|
|
43
43
|
enableTracePrint: () => enableTracePrint,
|
|
44
44
|
enableTracing: () => enableTracing,
|
|
45
|
+
getAppDb: () => getAppDb,
|
|
45
46
|
getGlobalInterceptors: () => getGlobalInterceptors,
|
|
46
47
|
getHandler: () => getHandler,
|
|
47
48
|
getSubscriptionValue: () => getSubscriptionValue,
|
|
@@ -767,6 +768,7 @@ function eventHandlerInterceptor(handler) {
|
|
|
767
768
|
);
|
|
768
769
|
context.newDb = newDb;
|
|
769
770
|
context.patches = patches;
|
|
771
|
+
mergeTrace({ tags: { "patches": patches, "effects": effects } });
|
|
770
772
|
if (!Array.isArray(effects)) {
|
|
771
773
|
consoleLog("warn", `[reflex] effects expects a vector, but was given ${typeof effects}`);
|
|
772
774
|
} else {
|
|
@@ -801,9 +803,7 @@ function handle(eventV) {
|
|
|
801
803
|
withTrace(
|
|
802
804
|
{ operation: eventId, opType: KIND3, tags: { event: eventV } },
|
|
803
805
|
() => {
|
|
804
|
-
mergeTrace({ tags: { "app-db-before": getAppDb() } });
|
|
805
806
|
execute(eventV, interceptors);
|
|
806
|
-
mergeTrace({ tags: { "app-db-after": getAppDb() } });
|
|
807
807
|
}
|
|
808
808
|
);
|
|
809
809
|
}
|
|
@@ -834,7 +834,6 @@ var Reaction = class _Reaction {
|
|
|
834
834
|
version = 0;
|
|
835
835
|
depsVersions = [];
|
|
836
836
|
subVector;
|
|
837
|
-
componentName;
|
|
838
837
|
constructor(computeFn, deps) {
|
|
839
838
|
this.computeFn = computeFn;
|
|
840
839
|
this.deps = deps;
|
|
@@ -851,10 +850,10 @@ var Reaction = class _Reaction {
|
|
|
851
850
|
this.recomputeIfNeeded(notifyWatchers);
|
|
852
851
|
return [this.value, this.version];
|
|
853
852
|
}
|
|
854
|
-
watch(callback) {
|
|
855
|
-
const idx = this.watchers.
|
|
853
|
+
watch(callback, componentName = "react component") {
|
|
854
|
+
const idx = this.watchers.findIndex((w) => w.callback === callback);
|
|
856
855
|
if (idx === -1) {
|
|
857
|
-
this.watchers.push(callback);
|
|
856
|
+
this.watchers.push({ callback, componentName });
|
|
858
857
|
if (this.deps) {
|
|
859
858
|
for (const d of this.deps)
|
|
860
859
|
d.ensureAliveWith(this);
|
|
@@ -862,7 +861,7 @@ var Reaction = class _Reaction {
|
|
|
862
861
|
}
|
|
863
862
|
}
|
|
864
863
|
unwatch(fn) {
|
|
865
|
-
const idx = this.watchers.
|
|
864
|
+
const idx = this.watchers.findIndex((w) => w.callback === fn);
|
|
866
865
|
if (idx !== -1) {
|
|
867
866
|
this.watchers.splice(idx, 1);
|
|
868
867
|
if (this.watchers.length === 0) {
|
|
@@ -926,11 +925,10 @@ var Reaction = class _Reaction {
|
|
|
926
925
|
withTrace(
|
|
927
926
|
{
|
|
928
927
|
opType: "render",
|
|
929
|
-
operation:
|
|
930
|
-
tags: this.componentName ? { componentName: this.componentName } : {}
|
|
928
|
+
operation: w.componentName
|
|
931
929
|
},
|
|
932
930
|
() => {
|
|
933
|
-
w(this.value);
|
|
931
|
+
w.callback(this.value);
|
|
934
932
|
}
|
|
935
933
|
);
|
|
936
934
|
} catch (error) {
|
|
@@ -1014,9 +1012,6 @@ var Reaction = class _Reaction {
|
|
|
1014
1012
|
get isRoot() {
|
|
1015
1013
|
return this.deps === void 0 || this.deps.length === 0;
|
|
1016
1014
|
}
|
|
1017
|
-
setComponentName(componentName) {
|
|
1018
|
-
this.componentName = componentName;
|
|
1019
|
-
}
|
|
1020
1015
|
};
|
|
1021
1016
|
|
|
1022
1017
|
// src/subs.ts
|
|
@@ -1121,8 +1116,7 @@ function useSubscription(subVector, componentName = "react component") {
|
|
|
1121
1116
|
const reaction = getOrCreateReaction(subVector);
|
|
1122
1117
|
if (!reaction)
|
|
1123
1118
|
return;
|
|
1124
|
-
reaction.
|
|
1125
|
-
reaction.watch(setVal);
|
|
1119
|
+
reaction.watch(setVal, componentName);
|
|
1126
1120
|
return () => {
|
|
1127
1121
|
reaction.unwatch(setVal);
|
|
1128
1122
|
};
|
|
@@ -1218,6 +1212,7 @@ function HotReloadWrapper({ children }) {
|
|
|
1218
1212
|
dispatch,
|
|
1219
1213
|
enableTracePrint,
|
|
1220
1214
|
enableTracing,
|
|
1215
|
+
getAppDb,
|
|
1221
1216
|
getGlobalInterceptors,
|
|
1222
1217
|
getHandler,
|
|
1223
1218
|
getSubscriptionValue,
|
package/dist/index.d.cts
CHANGED
|
@@ -40,6 +40,7 @@ interface Interceptor<T = Record<string, any>> {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
declare function initAppDb<T = Record<string, any>>(value: Db<T>): void;
|
|
43
|
+
declare function getAppDb<T = Record<string, any>>(): Db<T>;
|
|
43
44
|
|
|
44
45
|
/** Register an event handler with only a handler function (db event) */
|
|
45
46
|
declare function regEvent<T = Record<string, any>>(id: Id, handler: EventHandler<T>): void;
|
|
@@ -201,4 +202,4 @@ declare function disableTracing(): void;
|
|
|
201
202
|
declare function registerTraceCb(key: string, cb: TraceCallback): void;
|
|
202
203
|
declare function enableTracePrint(): void;
|
|
203
204
|
|
|
204
|
-
export { CoEffectHandler, CoEffects, Context, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
|
205
|
+
export { CoEffectHandler, CoEffects, Context, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ interface Interceptor<T = Record<string, any>> {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
declare function initAppDb<T = Record<string, any>>(value: Db<T>): void;
|
|
43
|
+
declare function getAppDb<T = Record<string, any>>(): Db<T>;
|
|
43
44
|
|
|
44
45
|
/** Register an event handler with only a handler function (db event) */
|
|
45
46
|
declare function regEvent<T = Record<string, any>>(id: Id, handler: EventHandler<T>): void;
|
|
@@ -201,4 +202,4 @@ declare function disableTracing(): void;
|
|
|
201
202
|
declare function registerTraceCb(key: string, cb: TraceCallback): void;
|
|
202
203
|
declare function enableTracePrint(): void;
|
|
203
204
|
|
|
204
|
-
export { CoEffectHandler, CoEffects, Context, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
|
205
|
+
export { CoEffectHandler, CoEffects, Context, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
|
package/dist/index.mjs
CHANGED
|
@@ -700,6 +700,7 @@ function eventHandlerInterceptor(handler) {
|
|
|
700
700
|
);
|
|
701
701
|
context.newDb = newDb;
|
|
702
702
|
context.patches = patches;
|
|
703
|
+
mergeTrace({ tags: { "patches": patches, "effects": effects } });
|
|
703
704
|
if (!Array.isArray(effects)) {
|
|
704
705
|
consoleLog("warn", `[reflex] effects expects a vector, but was given ${typeof effects}`);
|
|
705
706
|
} else {
|
|
@@ -734,9 +735,7 @@ function handle(eventV) {
|
|
|
734
735
|
withTrace(
|
|
735
736
|
{ operation: eventId, opType: KIND3, tags: { event: eventV } },
|
|
736
737
|
() => {
|
|
737
|
-
mergeTrace({ tags: { "app-db-before": getAppDb() } });
|
|
738
738
|
execute(eventV, interceptors);
|
|
739
|
-
mergeTrace({ tags: { "app-db-after": getAppDb() } });
|
|
740
739
|
}
|
|
741
740
|
);
|
|
742
741
|
}
|
|
@@ -767,7 +766,6 @@ var Reaction = class _Reaction {
|
|
|
767
766
|
version = 0;
|
|
768
767
|
depsVersions = [];
|
|
769
768
|
subVector;
|
|
770
|
-
componentName;
|
|
771
769
|
constructor(computeFn, deps) {
|
|
772
770
|
this.computeFn = computeFn;
|
|
773
771
|
this.deps = deps;
|
|
@@ -784,10 +782,10 @@ var Reaction = class _Reaction {
|
|
|
784
782
|
this.recomputeIfNeeded(notifyWatchers);
|
|
785
783
|
return [this.value, this.version];
|
|
786
784
|
}
|
|
787
|
-
watch(callback) {
|
|
788
|
-
const idx = this.watchers.
|
|
785
|
+
watch(callback, componentName = "react component") {
|
|
786
|
+
const idx = this.watchers.findIndex((w) => w.callback === callback);
|
|
789
787
|
if (idx === -1) {
|
|
790
|
-
this.watchers.push(callback);
|
|
788
|
+
this.watchers.push({ callback, componentName });
|
|
791
789
|
if (this.deps) {
|
|
792
790
|
for (const d of this.deps)
|
|
793
791
|
d.ensureAliveWith(this);
|
|
@@ -795,7 +793,7 @@ var Reaction = class _Reaction {
|
|
|
795
793
|
}
|
|
796
794
|
}
|
|
797
795
|
unwatch(fn) {
|
|
798
|
-
const idx = this.watchers.
|
|
796
|
+
const idx = this.watchers.findIndex((w) => w.callback === fn);
|
|
799
797
|
if (idx !== -1) {
|
|
800
798
|
this.watchers.splice(idx, 1);
|
|
801
799
|
if (this.watchers.length === 0) {
|
|
@@ -859,11 +857,10 @@ var Reaction = class _Reaction {
|
|
|
859
857
|
withTrace(
|
|
860
858
|
{
|
|
861
859
|
opType: "render",
|
|
862
|
-
operation:
|
|
863
|
-
tags: this.componentName ? { componentName: this.componentName } : {}
|
|
860
|
+
operation: w.componentName
|
|
864
861
|
},
|
|
865
862
|
() => {
|
|
866
|
-
w(this.value);
|
|
863
|
+
w.callback(this.value);
|
|
867
864
|
}
|
|
868
865
|
);
|
|
869
866
|
} catch (error) {
|
|
@@ -947,9 +944,6 @@ var Reaction = class _Reaction {
|
|
|
947
944
|
get isRoot() {
|
|
948
945
|
return this.deps === void 0 || this.deps.length === 0;
|
|
949
946
|
}
|
|
950
|
-
setComponentName(componentName) {
|
|
951
|
-
this.componentName = componentName;
|
|
952
|
-
}
|
|
953
947
|
};
|
|
954
948
|
|
|
955
949
|
// src/subs.ts
|
|
@@ -1054,8 +1048,7 @@ function useSubscription(subVector, componentName = "react component") {
|
|
|
1054
1048
|
const reaction = getOrCreateReaction(subVector);
|
|
1055
1049
|
if (!reaction)
|
|
1056
1050
|
return;
|
|
1057
|
-
reaction.
|
|
1058
|
-
reaction.watch(setVal);
|
|
1051
|
+
reaction.watch(setVal, componentName);
|
|
1059
1052
|
return () => {
|
|
1060
1053
|
reaction.unwatch(setVal);
|
|
1061
1054
|
};
|
|
@@ -1150,6 +1143,7 @@ export {
|
|
|
1150
1143
|
dispatch,
|
|
1151
1144
|
enableTracePrint,
|
|
1152
1145
|
enableTracing,
|
|
1146
|
+
getAppDb,
|
|
1153
1147
|
getGlobalInterceptors,
|
|
1154
1148
|
getHandler,
|
|
1155
1149
|
getSubscriptionValue,
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexsurfer/reflex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/flexsurfer/reflex.git"
|
|
7
|
+
"url": "git+https://github.com/flexsurfer/reflex.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.cjs",
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"pubsub",
|
|
69
69
|
"handler"
|
|
70
70
|
]
|
|
71
|
-
}
|
|
71
|
+
}
|