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
|
|
13
|
+
[TKey in keyof TStoreState]: TKey extends string ? StateLink<TStoreName, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TKey> : never;
|
|
14
14
|
} & {
|
|
15
|
-
[TKey in
|
|
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
|
};
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -182,18 +182,17 @@ class InternalStore {
|
|
|
182
182
|
return this.state;
|
|
183
183
|
};
|
|
184
184
|
this.dispatch = (instanceKey, payload, reducer) => {
|
|
185
|
-
const
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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();
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -180,18 +180,17 @@ class InternalStore {
|
|
|
180
180
|
return this.state;
|
|
181
181
|
};
|
|
182
182
|
this.dispatch = (instanceKey, payload, reducer) => {
|
|
183
|
-
const
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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