@flexsurfer/reflex 0.1.14 → 0.1.16

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
@@ -50,6 +50,7 @@ __export(src_exports, {
50
50
  getAppDb: () => getAppDb,
51
51
  getGlobalInterceptors: () => getGlobalInterceptors,
52
52
  getHandler: () => getHandler,
53
+ getReactions: () => getReactions,
53
54
  getSubscriptionValue: () => getSubscriptionValue,
54
55
  initAppDb: () => initAppDb,
55
56
  original: () => original,
@@ -139,6 +140,9 @@ var reactionsRegistry = /* @__PURE__ */ new Map();
139
140
  function getReaction(key) {
140
141
  return reactionsRegistry.get(key);
141
142
  }
143
+ function getReactions() {
144
+ return reactionsRegistry;
145
+ }
142
146
  function setReaction(key, reaction) {
143
147
  reactionsRegistry.set(key, reaction);
144
148
  }
@@ -769,7 +773,7 @@ function eventHandlerInterceptor(handler) {
769
773
  const event = context.coeffects.event;
770
774
  const params = event.slice(1);
771
775
  let effects = [];
772
- const [newDb, patches] = (0, import_immer2.produceWithPatches)(
776
+ const [newDb, patches, reversePatches] = (0, import_immer2.produceWithPatches)(
773
777
  getAppDb(),
774
778
  (draftDb) => {
775
779
  const coeffectsWithDb = { ...context.coeffects, draftDb };
@@ -785,7 +789,7 @@ function eventHandlerInterceptor(handler) {
785
789
  }
786
790
  context.newDb = newDb;
787
791
  context.patches = patches;
788
- mergeTrace({ tags: { "patches": patches, "effects": effects } });
792
+ mergeTrace({ tags: { "patches": patches, "reversePatches": reversePatches, "effects": effects } });
789
793
  if (!Array.isArray(effects)) {
790
794
  consoleLog("warn", `[reflex] effects expects a vector, but was given ${typeof effects}`);
791
795
  } else {
@@ -858,11 +862,14 @@ var Reaction = class _Reaction {
858
862
  static create(fn, deps) {
859
863
  return new _Reaction(fn, deps);
860
864
  }
861
- getValue() {
865
+ computeValue() {
862
866
  this.ensureDirty();
863
867
  this.recomputeIfNeeded(false);
864
868
  return this.value;
865
869
  }
870
+ getValue() {
871
+ return this.value;
872
+ }
866
873
  getDepValue(notifyWatchers = true) {
867
874
  this.recomputeIfNeeded(notifyWatchers);
868
875
  return [this.value, this.version];
@@ -978,8 +985,6 @@ var Reaction = class _Reaction {
978
985
  disposeIfUnused() {
979
986
  if (this.isAlive)
980
987
  return;
981
- this.value = void 0;
982
- this.version = 0;
983
988
  this.depsVersions = [];
984
989
  this.dirty = false;
985
990
  this.scheduled = false;
@@ -1088,7 +1093,7 @@ function getOrCreateReaction(subVector) {
1088
1093
  }
1089
1094
  function getSubscriptionValue(subVector) {
1090
1095
  const reaction = getOrCreateReaction(subVector);
1091
- return reaction ? reaction.getValue() : void 0;
1096
+ return reaction ? reaction.computeValue() : void 0;
1092
1097
  }
1093
1098
 
1094
1099
  // src/debounce.ts
@@ -1231,6 +1236,7 @@ function HotReloadWrapper({ children }) {
1231
1236
  getAppDb,
1232
1237
  getGlobalInterceptors,
1233
1238
  getHandler,
1239
+ getReactions,
1234
1240
  getSubscriptionValue,
1235
1241
  initAppDb,
1236
1242
  original,
package/dist/index.d.cts CHANGED
@@ -98,6 +98,42 @@ declare function defaultErrorHandler(originalError: Error, reflexError: Error &
98
98
  data: any;
99
99
  }): void;
100
100
 
101
+ declare class Reaction<T> {
102
+ private id;
103
+ private computeFn;
104
+ private deps;
105
+ private dependents;
106
+ private watchers;
107
+ private dirty;
108
+ private scheduled;
109
+ private value;
110
+ private version;
111
+ private depsVersions;
112
+ private subVector;
113
+ constructor(computeFn: (...depValues: any[]) => T, deps?: Reaction<any>[]);
114
+ static create<R>(fn: (...values: any[]) => R, deps?: Reaction<any>[]): Reaction<R>;
115
+ computeValue(): T;
116
+ getValue(): T;
117
+ getDepValue(notifyWatchers?: boolean): [T, number];
118
+ watch(callback: (val: T) => void, componentName?: string): void;
119
+ unwatch(fn: (v: T) => void): void;
120
+ markDirty(): void;
121
+ private scheduleRecompute;
122
+ private recomputeIfNeeded;
123
+ private ensureDirty;
124
+ private ensureAliveWith;
125
+ private disposeIfUnused;
126
+ setId(id: Id): void;
127
+ getId(): Id;
128
+ getSubVector(): SubVector | undefined;
129
+ setSubVector(subVector: SubVector): void;
130
+ private get isAlive();
131
+ private get hasWatchers();
132
+ private get hasDependents();
133
+ get isDirty(): boolean;
134
+ get isRoot(): boolean;
135
+ }
136
+
101
137
  declare function regSub<R>(id: Id, computeFn?: (...values: any[]) => R, depsFn?: (...params: any[]) => SubVector[]): void;
102
138
  declare function getSubscriptionValue<T>(subVector: SubVector): T;
103
139
 
@@ -129,6 +165,7 @@ declare function getHandler<T extends RegistryHandler = RegistryHandler>(kind: K
129
165
  declare function clearHandlers(): void;
130
166
  declare function clearHandlers(kind: Kind): void;
131
167
  declare function clearHandlers(kind: Kind, id: string): void;
168
+ declare function getReactions(): Map<string, Reaction<any>> | undefined;
132
169
  declare function clearReactions(): void;
133
170
  declare function clearReactions(id: string): void;
134
171
  declare function clearSubs(): void;
@@ -215,4 +252,4 @@ declare function disableTracing(): void;
215
252
  declare function registerTraceCb(key: string, cb: TraceCallback): void;
216
253
  declare function enableTracePrint(): void;
217
254
 
218
- export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
255
+ export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
package/dist/index.d.ts CHANGED
@@ -98,6 +98,42 @@ declare function defaultErrorHandler(originalError: Error, reflexError: Error &
98
98
  data: any;
99
99
  }): void;
100
100
 
101
+ declare class Reaction<T> {
102
+ private id;
103
+ private computeFn;
104
+ private deps;
105
+ private dependents;
106
+ private watchers;
107
+ private dirty;
108
+ private scheduled;
109
+ private value;
110
+ private version;
111
+ private depsVersions;
112
+ private subVector;
113
+ constructor(computeFn: (...depValues: any[]) => T, deps?: Reaction<any>[]);
114
+ static create<R>(fn: (...values: any[]) => R, deps?: Reaction<any>[]): Reaction<R>;
115
+ computeValue(): T;
116
+ getValue(): T;
117
+ getDepValue(notifyWatchers?: boolean): [T, number];
118
+ watch(callback: (val: T) => void, componentName?: string): void;
119
+ unwatch(fn: (v: T) => void): void;
120
+ markDirty(): void;
121
+ private scheduleRecompute;
122
+ private recomputeIfNeeded;
123
+ private ensureDirty;
124
+ private ensureAliveWith;
125
+ private disposeIfUnused;
126
+ setId(id: Id): void;
127
+ getId(): Id;
128
+ getSubVector(): SubVector | undefined;
129
+ setSubVector(subVector: SubVector): void;
130
+ private get isAlive();
131
+ private get hasWatchers();
132
+ private get hasDependents();
133
+ get isDirty(): boolean;
134
+ get isRoot(): boolean;
135
+ }
136
+
101
137
  declare function regSub<R>(id: Id, computeFn?: (...values: any[]) => R, depsFn?: (...params: any[]) => SubVector[]): void;
102
138
  declare function getSubscriptionValue<T>(subVector: SubVector): T;
103
139
 
@@ -129,6 +165,7 @@ declare function getHandler<T extends RegistryHandler = RegistryHandler>(kind: K
129
165
  declare function clearHandlers(): void;
130
166
  declare function clearHandlers(kind: Kind): void;
131
167
  declare function clearHandlers(kind: Kind, id: string): void;
168
+ declare function getReactions(): Map<string, Reaction<any>> | undefined;
132
169
  declare function clearReactions(): void;
133
170
  declare function clearReactions(id: string): void;
134
171
  declare function clearSubs(): void;
@@ -215,4 +252,4 @@ declare function disableTracing(): void;
215
252
  declare function registerTraceCb(key: string, cb: TraceCallback): void;
216
253
  declare function enableTracePrint(): void;
217
254
 
218
- export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
255
+ export { CoEffectHandler, CoEffects, Context, DISPATCH, DISPATCH_LATER, Db, DispatchLaterEffect, EffectHandler, Effects, ErrorHandler, EventHandler, EventVector, HotReloadWrapper, Id, Interceptor, NOW, RANDOM, SubVector, clearGlobalInterceptors, clearHandlers, clearHotReloadCallbacks, clearReactions, clearSubs, current, debounceAndDispatch, defaultErrorHandler, disableTracing, dispatch, enableTracePrint, enableTracing, getAppDb, getGlobalInterceptors, getHandler, getReactions, getSubscriptionValue, initAppDb, original, regCoeffect, regEffect, regEvent, regEventErrorHandler, regGlobalInterceptor, regSub, registerHotReloadCallback, registerTraceCb, setupSubsHotReload, throttleAndDispatch, triggerHotReload, useHotReload, useHotReloadKey, useSubscription };
package/dist/index.mjs CHANGED
@@ -67,6 +67,9 @@ var reactionsRegistry = /* @__PURE__ */ new Map();
67
67
  function getReaction(key) {
68
68
  return reactionsRegistry.get(key);
69
69
  }
70
+ function getReactions() {
71
+ return reactionsRegistry;
72
+ }
70
73
  function setReaction(key, reaction) {
71
74
  reactionsRegistry.set(key, reaction);
72
75
  }
@@ -697,7 +700,7 @@ function eventHandlerInterceptor(handler) {
697
700
  const event = context.coeffects.event;
698
701
  const params = event.slice(1);
699
702
  let effects = [];
700
- const [newDb, patches] = produceWithPatches(
703
+ const [newDb, patches, reversePatches] = produceWithPatches(
701
704
  getAppDb(),
702
705
  (draftDb) => {
703
706
  const coeffectsWithDb = { ...context.coeffects, draftDb };
@@ -713,7 +716,7 @@ function eventHandlerInterceptor(handler) {
713
716
  }
714
717
  context.newDb = newDb;
715
718
  context.patches = patches;
716
- mergeTrace({ tags: { "patches": patches, "effects": effects } });
719
+ mergeTrace({ tags: { "patches": patches, "reversePatches": reversePatches, "effects": effects } });
717
720
  if (!Array.isArray(effects)) {
718
721
  consoleLog("warn", `[reflex] effects expects a vector, but was given ${typeof effects}`);
719
722
  } else {
@@ -786,11 +789,14 @@ var Reaction = class _Reaction {
786
789
  static create(fn, deps) {
787
790
  return new _Reaction(fn, deps);
788
791
  }
789
- getValue() {
792
+ computeValue() {
790
793
  this.ensureDirty();
791
794
  this.recomputeIfNeeded(false);
792
795
  return this.value;
793
796
  }
797
+ getValue() {
798
+ return this.value;
799
+ }
794
800
  getDepValue(notifyWatchers = true) {
795
801
  this.recomputeIfNeeded(notifyWatchers);
796
802
  return [this.value, this.version];
@@ -906,8 +912,6 @@ var Reaction = class _Reaction {
906
912
  disposeIfUnused() {
907
913
  if (this.isAlive)
908
914
  return;
909
- this.value = void 0;
910
- this.version = 0;
911
915
  this.depsVersions = [];
912
916
  this.dirty = false;
913
917
  this.scheduled = false;
@@ -1016,7 +1020,7 @@ function getOrCreateReaction(subVector) {
1016
1020
  }
1017
1021
  function getSubscriptionValue(subVector) {
1018
1022
  const reaction = getOrCreateReaction(subVector);
1019
- return reaction ? reaction.getValue() : void 0;
1023
+ return reaction ? reaction.computeValue() : void 0;
1020
1024
  }
1021
1025
 
1022
1026
  // src/debounce.ts
@@ -1158,6 +1162,7 @@ export {
1158
1162
  getAppDb,
1159
1163
  getGlobalInterceptors,
1160
1164
  getHandler,
1165
+ getReactions,
1161
1166
  getSubscriptionValue,
1162
1167
  initAppDb,
1163
1168
  original,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexsurfer/reflex",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",