beestate 0.1.2 → 0.1.3

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.
@@ -10,7 +10,7 @@ export type Store<TStoreName extends string = string, TStoreState extends StoreS
10
10
  [`$$init`]: void;
11
11
  [`$$reset`]: void;
12
12
  } & {
13
- [TKey in Extract<keyof TStoreState, string>]: StateLink<TStoreName, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TKey>;
13
+ [TKey in keyof TStoreState]: TKey extends string ? StateLink<TStoreName, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TKey> : never;
14
14
  } & {
15
- [TKey in Extract<keyof TReducerMap, string>]: TKey extends keyof TStoreState ? never : ReducerLink<TStoreName, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TKey, TReducerMap[TKey]>;
15
+ [TKey in keyof TReducerMap]: TKey extends string ? TKey extends keyof TStoreState ? never : ReducerLink<TStoreName, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TKey, TReducerMap[TKey]> : never;
16
16
  };
@@ -182,18 +182,17 @@ class InternalStore {
182
182
  return this.state;
183
183
  };
184
184
  this.dispatch = (instanceKey, payload, reducer) => {
185
- const changes = reducer(this.state[instanceKey], payload);
185
+ const instanceState = this.state[instanceKey];
186
+ const changes = reducer(instanceState, payload);
186
187
  this.update(instanceKey, changes);
188
+ // TODO Убрать в логгер
189
+ console.log(`dispatch [store: ${this.name}, instance: ${String(instanceKey)}]:`);
190
+ console.dir({ payload: changes, [`prev state`]: instanceState, [`next state`]: changes });
187
191
  };
188
192
  this.update = (instanceKey, changes) => {
189
- if (this.state[instanceKey] !== changes) {
190
- this.state = { ...this.state, [instanceKey]: changes };
191
- this.listeners[instanceKey].forEach((listener) => listener());
192
- this.listenersAll.forEach((listener) => listener());
193
- // TODO Убрать в логгер
194
- console.log(`update [store: ${this.name}, instance: ${String(instanceKey)}]:`);
195
- console.dir(this.state);
196
- }
193
+ this.state = { ...this.state, [instanceKey]: changes };
194
+ this.listeners[instanceKey].forEach((listener) => listener());
195
+ this.listenersAll.forEach((listener) => listener());
197
196
  };
198
197
  this.listeners = {};
199
198
  this.listenersAll = new Set();
@@ -180,18 +180,17 @@ class InternalStore {
180
180
  return this.state;
181
181
  };
182
182
  this.dispatch = (instanceKey, payload, reducer) => {
183
- const changes = reducer(this.state[instanceKey], payload);
183
+ const instanceState = this.state[instanceKey];
184
+ const changes = reducer(instanceState, payload);
184
185
  this.update(instanceKey, changes);
186
+ // TODO Убрать в логгер
187
+ console.log(`dispatch [store: ${this.name}, instance: ${String(instanceKey)}]:`);
188
+ console.dir({ payload: changes, [`prev state`]: instanceState, [`next state`]: changes });
185
189
  };
186
190
  this.update = (instanceKey, changes) => {
187
- if (this.state[instanceKey] !== changes) {
188
- this.state = { ...this.state, [instanceKey]: changes };
189
- this.listeners[instanceKey].forEach((listener) => listener());
190
- this.listenersAll.forEach((listener) => listener());
191
- // TODO Убрать в логгер
192
- console.log(`update [store: ${this.name}, instance: ${String(instanceKey)}]:`);
193
- console.dir(this.state);
194
- }
191
+ this.state = { ...this.state, [instanceKey]: changes };
192
+ this.listeners[instanceKey].forEach((listener) => listener());
193
+ this.listenersAll.forEach((listener) => listener());
195
194
  };
196
195
  this.listeners = {};
197
196
  this.listenersAll = new Set();
package/package.json CHANGED
@@ -19,5 +19,5 @@
19
19
  "prepublishOnly": "npm run build"
20
20
  },
21
21
  "types": "dist/@types",
22
- "version": "0.1.2"
22
+ "version": "0.1.3"
23
23
  }