@flexsurfer/reflex 0.1.3 → 0.1.5

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 CHANGED
@@ -43,6 +43,8 @@ __export(src_exports, {
43
43
  enableTracePrint: () => enableTracePrint,
44
44
  enableTracing: () => enableTracing,
45
45
  getGlobalInterceptors: () => getGlobalInterceptors,
46
+ getHandler: () => getHandler,
47
+ getSubscriptionValue: () => getSubscriptionValue,
46
48
  initAppDb: () => initAppDb,
47
49
  isDebugEnabled: () => isDebugEnabled,
48
50
  regCoeffect: () => regCoeffect,
@@ -440,6 +442,9 @@ var EventQueue = class {
440
442
  let n = this.queue.length;
441
443
  while (n > 0) {
442
444
  const nextEvent = this.queue[0];
445
+ if (!nextEvent || this.queue.length === 0) {
446
+ break;
447
+ }
443
448
  const metaKeys = nextEvent.meta ? Object.keys(nextEvent.meta) : [];
444
449
  const laterKey = metaKeys.find((k) => laterFns[k]);
445
450
  if (laterKey) {
@@ -1063,6 +1068,10 @@ function getOrCreateReaction(subVector) {
1063
1068
  setReaction(subVectorKey, reaction);
1064
1069
  return reaction;
1065
1070
  }
1071
+ function getSubscriptionValue(subVector) {
1072
+ const reaction = getOrCreateReaction(subVector);
1073
+ return reaction ? reaction.getValue() : void 0;
1074
+ }
1066
1075
 
1067
1076
  // src/debounce.ts
1068
1077
  var timeout = /* @__PURE__ */ new Map();
@@ -1098,8 +1107,7 @@ function throttleAndDispatch(event, durationMs) {
1098
1107
  var import_react = require("react");
1099
1108
  function useSubscription(subVector, componentName = "react component") {
1100
1109
  const [val, setVal] = (0, import_react.useState)(() => {
1101
- const reaction = getOrCreateReaction(subVector);
1102
- return reaction ? reaction.getValue() : void 0;
1110
+ return getSubscriptionValue(subVector);
1103
1111
  });
1104
1112
  (0, import_react.useEffect)(() => {
1105
1113
  const reaction = getOrCreateReaction(subVector);
@@ -1199,6 +1207,8 @@ function HotReloadWrapper({ children }) {
1199
1207
  enableTracePrint,
1200
1208
  enableTracing,
1201
1209
  getGlobalInterceptors,
1210
+ getHandler,
1211
+ getSubscriptionValue,
1202
1212
  initAppDb,
1203
1213
  isDebugEnabled,
1204
1214
  regCoeffect,
package/dist/index.d.cts CHANGED
@@ -11,6 +11,8 @@ type ErrorHandler = (originalError: Error, reFrameError: Error & {
11
11
  data: any;
12
12
  }) => void;
13
13
  type SubVector = [Id, ...any[]];
14
+ type SubHandler = (...values: any[]) => any;
15
+ type SubDepsHandler = (...params: any[]) => SubVector[];
14
16
  type Effects = [string, any][];
15
17
  interface DispatchLaterEffect {
16
18
  ms: number;
@@ -79,6 +81,7 @@ declare function defaultErrorHandler(originalError: Error, reFrameError: Error &
79
81
  }): void;
80
82
 
81
83
  declare function regSub<R>(id: Id, computeFn?: (...values: any[]) => R, depsFn?: (...params: any[]) => SubVector[]): void;
84
+ declare function getSubscriptionValue<T>(subVector: SubVector): T;
82
85
 
83
86
  declare function regEffect(id: string, handler: EffectHandler): void;
84
87
 
@@ -107,6 +110,8 @@ declare function setDebugEnabled(enabled: boolean): void;
107
110
  declare function isDebugEnabled(): boolean;
108
111
 
109
112
  type Kind = 'event' | 'fx' | 'cofx' | 'sub' | 'subDeps' | 'error';
113
+ type RegistryHandler = EventHandler | EffectHandler | CoEffectHandler | ErrorHandler | SubHandler | SubDepsHandler;
114
+ declare function getHandler<T extends RegistryHandler = RegistryHandler>(kind: Kind, id: Id): T | undefined;
110
115
  declare function clearHandlers(): void;
111
116
  declare function clearHandlers(kind: Kind): void;
112
117
  declare function clearHandlers(kind: Kind, id: string): void;
@@ -199,4 +204,4 @@ declare function disableTracing(): void;
199
204
  declare function registerTraceCb(key: string, cb: TraceCallback): void;
200
205
  declare function enableTracePrint(): void;
201
206
 
202
- 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, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
207
+ 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 };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,8 @@ type ErrorHandler = (originalError: Error, reFrameError: Error & {
11
11
  data: any;
12
12
  }) => void;
13
13
  type SubVector = [Id, ...any[]];
14
+ type SubHandler = (...values: any[]) => any;
15
+ type SubDepsHandler = (...params: any[]) => SubVector[];
14
16
  type Effects = [string, any][];
15
17
  interface DispatchLaterEffect {
16
18
  ms: number;
@@ -79,6 +81,7 @@ declare function defaultErrorHandler(originalError: Error, reFrameError: Error &
79
81
  }): void;
80
82
 
81
83
  declare function regSub<R>(id: Id, computeFn?: (...values: any[]) => R, depsFn?: (...params: any[]) => SubVector[]): void;
84
+ declare function getSubscriptionValue<T>(subVector: SubVector): T;
82
85
 
83
86
  declare function regEffect(id: string, handler: EffectHandler): void;
84
87
 
@@ -107,6 +110,8 @@ declare function setDebugEnabled(enabled: boolean): void;
107
110
  declare function isDebugEnabled(): boolean;
108
111
 
109
112
  type Kind = 'event' | 'fx' | 'cofx' | 'sub' | 'subDeps' | 'error';
113
+ type RegistryHandler = EventHandler | EffectHandler | CoEffectHandler | ErrorHandler | SubHandler | SubDepsHandler;
114
+ declare function getHandler<T extends RegistryHandler = RegistryHandler>(kind: Kind, id: Id): T | undefined;
110
115
  declare function clearHandlers(): void;
111
116
  declare function clearHandlers(kind: Kind): void;
112
117
  declare function clearHandlers(kind: Kind, id: string): void;
@@ -199,4 +204,4 @@ declare function disableTracing(): void;
199
204
  declare function registerTraceCb(key: string, cb: TraceCallback): void;
200
205
  declare function enableTracePrint(): void;
201
206
 
202
- 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, initAppDb, isDebugEnabled, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setDebugEnabled, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
207
+ 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 };
package/dist/index.mjs CHANGED
@@ -375,6 +375,9 @@ var EventQueue = class {
375
375
  let n = this.queue.length;
376
376
  while (n > 0) {
377
377
  const nextEvent = this.queue[0];
378
+ if (!nextEvent || this.queue.length === 0) {
379
+ break;
380
+ }
378
381
  const metaKeys = nextEvent.meta ? Object.keys(nextEvent.meta) : [];
379
382
  const laterKey = metaKeys.find((k) => laterFns[k]);
380
383
  if (laterKey) {
@@ -998,6 +1001,10 @@ function getOrCreateReaction(subVector) {
998
1001
  setReaction(subVectorKey, reaction);
999
1002
  return reaction;
1000
1003
  }
1004
+ function getSubscriptionValue(subVector) {
1005
+ const reaction = getOrCreateReaction(subVector);
1006
+ return reaction ? reaction.getValue() : void 0;
1007
+ }
1001
1008
 
1002
1009
  // src/debounce.ts
1003
1010
  var timeout = /* @__PURE__ */ new Map();
@@ -1033,8 +1040,7 @@ function throttleAndDispatch(event, durationMs) {
1033
1040
  import { useEffect, useState } from "react";
1034
1041
  function useSubscription(subVector, componentName = "react component") {
1035
1042
  const [val, setVal] = useState(() => {
1036
- const reaction = getOrCreateReaction(subVector);
1037
- return reaction ? reaction.getValue() : void 0;
1043
+ return getSubscriptionValue(subVector);
1038
1044
  });
1039
1045
  useEffect(() => {
1040
1046
  const reaction = getOrCreateReaction(subVector);
@@ -1133,6 +1139,8 @@ export {
1133
1139
  enableTracePrint,
1134
1140
  enableTracing,
1135
1141
  getGlobalInterceptors,
1142
+ getHandler,
1143
+ getSubscriptionValue,
1136
1144
  initAppDb,
1137
1145
  isDebugEnabled,
1138
1146
  regCoeffect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexsurfer/reflex",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",