@kuindji/reactive 1.0.6 → 1.0.8

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.
@@ -8,7 +8,8 @@ function useListenToEventBus(eventBus, eventName, listener, options, errorListen
8
8
  const errorListenerRef = (0, react_1.useRef)(errorListener);
9
9
  listenerRef.current = listener;
10
10
  const genericHandler = (0, react_1.useCallback)((...args) => {
11
- return listenerRef.current(...args);
11
+ var _a;
12
+ return (_a = listenerRef.current) === null || _a === void 0 ? void 0 : _a.call(listenerRef, ...args);
12
13
  }, []);
13
14
  (0, react_1.useEffect)(() => {
14
15
  return () => {
@@ -10,46 +10,46 @@ export declare function useStore<PropMap extends BasePropMap, Store extends Stor
10
10
  control?: Partial<Store["controlEvents"]>;
11
11
  }>(initialData?: Partial<PropMap>, config?: Config): import("..").ApiType<StoreDefinitionHelper<PropMap>, {
12
12
  readonly set: {
13
- <K extends import("..").KeyOf<PropMap>>(key: K, value: PropMap[K]): void;
13
+ <K extends import("..").KeyOf<PropMap>>(key: K, value: PropMap[K] | undefined): void;
14
14
  (key: Partial<PropMap>): void;
15
15
  };
16
16
  readonly get: <K extends import("..").KeyOf<PropMap> | import("..").KeyOf<PropMap>[]>(key: K) => K extends import("..").KeyOf<PropMap> ? PropMap[K] : K extends import("..").KeyOf<PropMap>[] ? { [AK in K[number]]: PropMap[AK]; } : never;
17
17
  readonly getData: () => PropMap;
18
18
  readonly batch: (fn: () => void) => void;
19
19
  readonly asyncSet: {
20
- <K extends import("..").KeyOf<PropMap>>(key: K, value: PropMap[K]): void;
20
+ <K extends import("..").KeyOf<PropMap>>(key: K, value: PropMap[K] | undefined): void;
21
21
  (key: Partial<PropMap>): void;
22
22
  };
23
23
  readonly isEmpty: () => boolean;
24
24
  readonly reset: () => void;
25
- readonly onChange: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1], previousValue?: PropMap[K_1] | undefined) => void; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1], previousValue?: PropMap[K_1] | undefined) => void; }>[K]["signature"]>(name: K, handler: H, options?: import("..").ListenerOptions) => void;
26
- readonly removeOnChange: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1], previousValue?: PropMap[K_1] | undefined) => void; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1], previousValue?: PropMap[K_1] | undefined) => void; }>[K]["signature"]>(name: K, handler: H, context?: object | null, tag?: string | null) => void;
25
+ readonly onChange: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined, previousValue?: PropMap[K_1] | undefined) => void; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined, previousValue?: PropMap[K_1] | undefined) => void; }>[K]["signature"]>(name: K, handler: H, options?: import("..").ListenerOptions) => void;
26
+ readonly removeOnChange: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined, previousValue?: PropMap[K_1] | undefined) => void; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined, previousValue?: PropMap[K_1] | undefined) => void; }>[K]["signature"]>(name: K, handler: H, context?: object | null, tag?: string | null) => void;
27
27
  readonly control: <K extends import("..").KeyOf<import("..").GetEventsMap<{
28
- before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V) => boolean;
28
+ before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V | undefined) => boolean;
29
29
  change: (names: import("..").KeyOf<PropMap>[]) => void;
30
30
  reset: () => void;
31
31
  error: import("..").ErrorListenerSignature<any[]>;
32
- effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1) => void;
32
+ effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1 | undefined) => void;
33
33
  }>>, H extends import("..").GetEventsMap<{
34
- before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V) => boolean;
34
+ before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V | undefined) => boolean;
35
35
  change: (names: import("..").KeyOf<PropMap>[]) => void;
36
36
  reset: () => void;
37
37
  error: import("..").ErrorListenerSignature<any[]>;
38
- effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1) => void;
38
+ effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1 | undefined) => void;
39
39
  }>[K]["signature"]>(name: K, handler: H, options?: import("..").ListenerOptions) => void;
40
40
  readonly removeControl: <K extends import("..").KeyOf<import("..").GetEventsMap<{
41
- before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V) => boolean;
41
+ before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V | undefined) => boolean;
42
42
  change: (names: import("..").KeyOf<PropMap>[]) => void;
43
43
  reset: () => void;
44
44
  error: import("..").ErrorListenerSignature<any[]>;
45
- effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1) => void;
45
+ effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1 | undefined) => void;
46
46
  }>>, H extends import("..").GetEventsMap<{
47
- before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V) => boolean;
47
+ before: <K_1 extends import("..").KeyOf<PropMap>, V extends PropMap[K_1]>(name: K_1, value: V | undefined) => boolean;
48
48
  change: (names: import("..").KeyOf<PropMap>[]) => void;
49
49
  reset: () => void;
50
50
  error: import("..").ErrorListenerSignature<any[]>;
51
- effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1) => void;
51
+ effect: <K_1 extends import("..").KeyOf<PropMap>, V_1 extends PropMap[K_1]>(name: K_1, value: V_1 | undefined) => void;
52
52
  }>[K]["signature"]>(name: K, handler: H, context?: object | null, tag?: string | null) => void;
53
- readonly pipe: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1]) => PropMap[K_1]; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1]) => PropMap[K_1]; }>[K]["signature"]>(name: K, handler: H, options?: import("..").ListenerOptions) => void;
54
- readonly removePipe: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1]) => PropMap[K_1]; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1]) => PropMap[K_1]; }>[K]["signature"]>(name: K, handler: H, context?: object | null, tag?: string | null) => void;
53
+ readonly pipe: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined) => PropMap[K_1]; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined) => PropMap[K_1]; }>[K]["signature"]>(name: K, handler: H, options?: import("..").ListenerOptions) => void;
54
+ readonly removePipe: <K extends import("..").KeyOf<import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined) => PropMap[K_1]; }>>, H extends import("..").GetEventsMap<{ [K_1 in import("..").KeyOf<PropMap>]: (value: PropMap[K_1] | undefined) => PropMap[K_1]; }>[K]["signature"]>(name: K, handler: H, context?: object | null, tag?: string | null) => void;
55
55
  }>;
package/dist/store.d.ts CHANGED
@@ -9,17 +9,17 @@ export declare const ResetEventName = "reset";
9
9
  export declare const ErrorEventName = "error";
10
10
  export declare const EffectEventName = "effect";
11
11
  type StoreControlEvents<PropMap extends BasePropMap> = {
12
- [BeforeChangeEventName]: <K extends KeyOf<PropMap>, V extends PropMap[K]>(name: K, value: V) => boolean;
12
+ [BeforeChangeEventName]: <K extends KeyOf<PropMap>, V extends PropMap[K]>(name: K, value: V | undefined) => boolean;
13
13
  [ChangeEventName]: (names: KeyOf<PropMap>[]) => void;
14
14
  [ResetEventName]: () => void;
15
15
  [ErrorEventName]: ErrorListenerSignature<any[]>;
16
- [EffectEventName]: <K extends KeyOf<PropMap>, V extends PropMap[K]>(name: K, value: V) => void;
16
+ [EffectEventName]: <K extends KeyOf<PropMap>, V extends PropMap[K]>(name: K, value: V | undefined) => void;
17
17
  };
18
18
  type StoreChangeEvents<PropMap extends BasePropMap> = {
19
- [K in KeyOf<PropMap>]: (value: PropMap[K], previousValue?: PropMap[K] | undefined) => void;
19
+ [K in KeyOf<PropMap>]: (value: PropMap[K] | undefined, previousValue?: PropMap[K] | undefined) => void;
20
20
  };
21
21
  type StorePipeEvents<PropMap extends BasePropMap> = {
22
- [K in KeyOf<PropMap>]: (value: PropMap[K]) => PropMap[K];
22
+ [K in KeyOf<PropMap>]: (value: PropMap[K] | undefined) => PropMap[K];
23
23
  };
24
24
  export type StoreDefinitionHelper<PropMap extends BasePropMap> = {
25
25
  propTypes: PropMap;
@@ -32,14 +32,14 @@ export type StoreDefinitionHelper<PropMap extends BasePropMap> = {
32
32
  };
33
33
  export declare function createStore<PropMap extends BasePropMap = BasePropMap>(initialData?: Partial<PropMap>): ApiType<StoreDefinitionHelper<PropMap>, {
34
34
  readonly set: {
35
- <K extends KeyOf<PropMap>>(key: K, value: PropMap[K]): void;
35
+ <K extends KeyOf<PropMap>>(key: K, value: PropMap[K] | undefined): void;
36
36
  (key: Partial<PropMap>): void;
37
37
  };
38
38
  readonly get: <K extends (KeyOf<PropMap>) | Array<KeyOf<PropMap>>>(key: K) => K extends KeyOf<PropMap> ? PropMap[K] : K extends KeyOf<PropMap>[] ? { [AK in K[number]]: PropMap[AK]; } : never;
39
39
  readonly getData: () => PropMap;
40
40
  readonly batch: (fn: () => void) => void;
41
41
  readonly asyncSet: {
42
- <K extends KeyOf<PropMap>>(key: K, value: PropMap[K]): void;
42
+ <K extends KeyOf<PropMap>>(key: K, value: PropMap[K] | undefined): void;
43
43
  (key: Partial<PropMap>): void;
44
44
  };
45
45
  readonly isEmpty: () => boolean;
package/dist/store.js CHANGED
@@ -14,6 +14,13 @@ function createStore(initialData = {}) {
14
14
  const pipe = (0, eventBus_1.createEventBus)();
15
15
  const control = (0, eventBus_1.createEventBus)();
16
16
  let effectKeys = [];
17
+ const effectInterceptor = (name, args) => {
18
+ if (name === exports.ChangeEventName) {
19
+ effectKeys.push(...args[0]);
20
+ return false;
21
+ }
22
+ return true;
23
+ };
17
24
  const _set = (name, value, triggerChange = true) => {
18
25
  var _a, _b, _c, _d, _e;
19
26
  const prev = data.get(name);
@@ -70,14 +77,7 @@ function createStore(initialData = {}) {
70
77
  try {
71
78
  const isIntercepting = control.isIntercepting();
72
79
  if (!isIntercepting) {
73
- const interceptor = (name, args) => {
74
- if (name === exports.ChangeEventName) {
75
- effectKeys.push(...args[0]);
76
- return false;
77
- }
78
- return true;
79
- };
80
- control.intercept(interceptor);
80
+ control.intercept(effectInterceptor);
81
81
  }
82
82
  control.trigger(exports.EffectEventName, name, value);
83
83
  if (!isIntercepting) {
@@ -127,8 +127,7 @@ function createStore(initialData = {}) {
127
127
  };
128
128
  function asyncSet(name, value) {
129
129
  setTimeout(() => {
130
- if ((typeof name === "string")
131
- && value !== undefined) {
130
+ if (typeof name === "string") {
132
131
  set(name, value);
133
132
  }
134
133
  else if (typeof name === "object") {
@@ -137,13 +136,17 @@ function createStore(initialData = {}) {
137
136
  }, 0);
138
137
  }
139
138
  function set(name, value) {
140
- var _a;
141
- if ((typeof name === "string")
142
- && value !== undefined) {
139
+ var _a, _b;
140
+ if (typeof name === "string") {
143
141
  _set(name, value);
144
142
  }
145
143
  else if (typeof name === "object") {
146
144
  const changedKeys = [];
145
+ const isIntercepting = control.isIntercepting();
146
+ const hasEffectListener = (_a = control.get(exports.EffectEventName)) === null || _a === void 0 ? void 0 : _a.hasListener();
147
+ if (hasEffectListener && !isIntercepting) {
148
+ control.intercept(effectInterceptor);
149
+ }
147
150
  Object.entries(name).forEach(([k, v]) => {
148
151
  if (_set(k, v, false)) {
149
152
  changedKeys.push(k);
@@ -154,8 +157,9 @@ function createStore(initialData = {}) {
154
157
  ...changedKeys,
155
158
  ...effectKeys,
156
159
  ]);
157
- if (!control.isIntercepting()) {
160
+ if (hasEffectListener && !isIntercepting) {
158
161
  effectKeys = [];
162
+ control.stopIntercepting();
159
163
  }
160
164
  }
161
165
  catch (error) {
@@ -166,7 +170,7 @@ function createStore(initialData = {}) {
166
170
  args: [name],
167
171
  type: "store-control",
168
172
  });
169
- if ((_a = control.get(exports.ErrorEventName)) === null || _a === void 0 ? void 0 : _a.hasListener()) {
173
+ if ((_b = control.get(exports.ErrorEventName)) === null || _b === void 0 ? void 0 : _b.hasListener()) {
170
174
  return true;
171
175
  }
172
176
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuindji/reactive",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A JavaScript/TypeScript utility library for building reactive applications with events, actions, stores, and React hooks",
5
5
  "keywords": [
6
6
  "events",