beestate 0.1.1 → 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.
- package/dist/@types/createStoreRegistry.d.ts +2 -2
- package/dist/@types/createUseProp.d.ts +6 -0
- package/dist/@types/createUsePropAll.d.ts +6 -0
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/types/Store.d.ts +2 -2
- package/dist/cjs/index.cjs.js +19 -20
- package/dist/esm/index.esm.js +18 -19
- package/package.json +1 -1
- package/dist/@types/createUseState.d.ts +0 -6
- package/dist/@types/createUseStateAll.d.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare function createStoreRegistry(): {
|
|
2
2
|
useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TReducerName, TReducer>) => import("./types/Dispatcher.tsx").Dispatcher<TStoreState, TReducer>;
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
useProp: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: import("./types/StateLink.tsx").StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKey?: import("./index.tsx").InstanceKey) => TStoreState[TStateName];
|
|
4
|
+
usePropAll: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: import("./types/StateLink.tsx").StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKeys?: import("./index.tsx").InstanceKey[] | ((state: TStoreState) => boolean)) => [instanceKey: import("./index.tsx").InstanceKey, state: TStoreState[TStateName]][];
|
|
5
5
|
useStore: {
|
|
6
6
|
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TInitPayload extends import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap> = import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap>, TResetPayload extends import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap> = import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TInitPayload, TResetPayload>): void;
|
|
7
7
|
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TInitPayload extends import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap> = import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap>, TResetPayload extends import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap> = import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TInitPayload, TResetPayload>): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type InstanceKey } from './types/index.tsx';
|
|
2
|
+
import { type ReducerMap } from './types/index.tsx';
|
|
3
|
+
import { type StateLink } from './types/index.tsx';
|
|
4
|
+
import { type StoreRegistry } from './types/index.tsx';
|
|
5
|
+
import { type StoreState } from './types/index.tsx';
|
|
6
|
+
export declare function createUseProp(storeRegistry: StoreRegistry): <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKey?: InstanceKey) => TStoreState[TStateName];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type InstanceKey } from './types/index.tsx';
|
|
2
|
+
import { type ReducerMap } from './types/index.tsx';
|
|
3
|
+
import { type StateLink } from './types/index.tsx';
|
|
4
|
+
import { type StoreRegistry } from './types/index.tsx';
|
|
5
|
+
import { type StoreState } from './types/index.tsx';
|
|
6
|
+
export declare function createUsePropAll(storeRegistry: StoreRegistry): <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKeys?: InstanceKey[] | ((state: TStoreState) => boolean)) => [instanceKey: InstanceKey, state: TStoreState[TStateName]][];
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { createStore } from './createStore.tsx';
|
|
|
4
4
|
export { createStoreRegistry } from './createStoreRegistry.tsx';
|
|
5
5
|
export { InternalStore } from './InternalStore.tsx';
|
|
6
6
|
export { StoreProvider } from './StoreProvider.tsx';
|
|
7
|
-
export declare const useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TReducerName, TReducer>) => import("./types/Dispatcher.tsx").Dispatcher<TStoreState, TReducer>,
|
|
7
|
+
export declare const useDispatcher: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TReducerName extends string = string, TReducer extends import("./types/Reducer.tsx").Reducer<TStoreState, any> = import("./types/Reducer.tsx").Reducer<TStoreState, any>>(reducerLink: import("./types/ReducerLink.tsx").ReducerLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TReducerName, TReducer>) => import("./types/Dispatcher.tsx").Dispatcher<TStoreState, TReducer>, useProp: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: import("./types/StateLink.tsx").StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKey?: import("./index.tsx").InstanceKey) => TStoreState[TStateName], usePropAll: <TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: import("./types/StateLink.tsx").StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKeys?: import("./index.tsx").InstanceKey[] | ((state: TStoreState) => boolean)) => [instanceKey: import("./index.tsx").InstanceKey, state: TStoreState[TStateName]][], useStore: {
|
|
8
8
|
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TInitPayload extends import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap> = import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap>, TResetPayload extends import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap> = import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, registerInstance: import("./types/RegisterDefaultInstance.tsx").RegisterDefaultInstance<TInitPayload, TResetPayload>): void;
|
|
9
9
|
<TStoreState extends import("./types/StoreState.tsx").StoreState = import("./types/StoreState.tsx").StoreState, TReducerMap extends import("./types/ReducerMap.tsx").ReducerMap<TStoreState> = import("./types/ReducerMap.tsx").ReducerMap<TStoreState>, TInitPayload extends import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap> = import("./types/InitPayload.tsx").InitPayload<TStoreState, TReducerMap>, TResetPayload extends import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap> = import("./types/ResetPayload.tsx").ResetPayload<TStoreState, TReducerMap>>(store: import("./types/Store.tsx").Store<string, TStoreState, TReducerMap>, instanceKeys: import("./index.tsx").InstanceKey[], registerInstance: import("./types/RegisterInstance.tsx").RegisterInstance<TInitPayload, TResetPayload>): void;
|
|
10
10
|
};
|
|
@@ -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
|
@@ -43,8 +43,8 @@ function createUseDispatcher(storeRegistry) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function
|
|
47
|
-
return function
|
|
46
|
+
function createUseProp(storeRegistry) {
|
|
47
|
+
return function useProp(stateLink, instanceKey) {
|
|
48
48
|
const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
49
49
|
const contextInstanceKey = React.useContext(internalStoreProps.context);
|
|
50
50
|
const actualInstanceKey = instanceKey ?? contextInstanceKey ?? DEFAULT_INSTANCE_KEY;
|
|
@@ -70,8 +70,8 @@ function createUseState(storeRegistry) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
function
|
|
74
|
-
return function
|
|
73
|
+
function createUsePropAll(storeRegistry) {
|
|
74
|
+
return function usePropAll(stateLink, instanceKeys) {
|
|
75
75
|
const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
76
76
|
const prevStateAllRef = React.useRef({ prevStateAll: [] });
|
|
77
77
|
if (!(internalStoreProps.uniqKey in storeRegistry)) {
|
|
@@ -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();
|
|
@@ -281,13 +280,13 @@ function createUseStore(storeRegistry) {
|
|
|
281
280
|
function createStoreRegistry() {
|
|
282
281
|
const storeRegistry = {};
|
|
283
282
|
const useDispatcher = createUseDispatcher(storeRegistry);
|
|
284
|
-
const
|
|
285
|
-
const
|
|
283
|
+
const useProp = createUseProp(storeRegistry);
|
|
284
|
+
const usePropAll = createUsePropAll(storeRegistry);
|
|
286
285
|
const useStore = createUseStore(storeRegistry);
|
|
287
286
|
return {
|
|
288
287
|
useDispatcher,
|
|
289
|
-
|
|
290
|
-
|
|
288
|
+
useProp,
|
|
289
|
+
usePropAll,
|
|
291
290
|
useStore,
|
|
292
291
|
};
|
|
293
292
|
}
|
|
@@ -330,7 +329,7 @@ function StoreProvider(props) {
|
|
|
330
329
|
return (jsxRuntime.jsx(Context.Provider, { value: props.instanceKey, children: props.children }));
|
|
331
330
|
}
|
|
332
331
|
|
|
333
|
-
const { useDispatcher,
|
|
332
|
+
const { useDispatcher, useProp, usePropAll, useStore, } = createStoreRegistry();
|
|
334
333
|
|
|
335
334
|
exports.DESTROY = DESTROY;
|
|
336
335
|
exports.InternalStore = InternalStore;
|
|
@@ -338,6 +337,6 @@ exports.StoreProvider = StoreProvider;
|
|
|
338
337
|
exports.createStore = createStore;
|
|
339
338
|
exports.createStoreRegistry = createStoreRegistry;
|
|
340
339
|
exports.useDispatcher = useDispatcher;
|
|
341
|
-
exports.
|
|
342
|
-
exports.
|
|
340
|
+
exports.useProp = useProp;
|
|
341
|
+
exports.usePropAll = usePropAll;
|
|
343
342
|
exports.useStore = useStore;
|
package/dist/esm/index.esm.js
CHANGED
|
@@ -41,8 +41,8 @@ function createUseDispatcher(storeRegistry) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function
|
|
45
|
-
return function
|
|
44
|
+
function createUseProp(storeRegistry) {
|
|
45
|
+
return function useProp(stateLink, instanceKey) {
|
|
46
46
|
const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
47
47
|
const contextInstanceKey = useContext(internalStoreProps.context);
|
|
48
48
|
const actualInstanceKey = instanceKey ?? contextInstanceKey ?? DEFAULT_INSTANCE_KEY;
|
|
@@ -68,8 +68,8 @@ function createUseState(storeRegistry) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function
|
|
72
|
-
return function
|
|
71
|
+
function createUsePropAll(storeRegistry) {
|
|
72
|
+
return function usePropAll(stateLink, instanceKeys) {
|
|
73
73
|
const internalStoreProps = stateLink[INTERNAL_STORE_PROPS_ACCESSOR];
|
|
74
74
|
const prevStateAllRef = useRef({ prevStateAll: [] });
|
|
75
75
|
if (!(internalStoreProps.uniqKey in storeRegistry)) {
|
|
@@ -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();
|
|
@@ -279,13 +278,13 @@ function createUseStore(storeRegistry) {
|
|
|
279
278
|
function createStoreRegistry() {
|
|
280
279
|
const storeRegistry = {};
|
|
281
280
|
const useDispatcher = createUseDispatcher(storeRegistry);
|
|
282
|
-
const
|
|
283
|
-
const
|
|
281
|
+
const useProp = createUseProp(storeRegistry);
|
|
282
|
+
const usePropAll = createUsePropAll(storeRegistry);
|
|
284
283
|
const useStore = createUseStore(storeRegistry);
|
|
285
284
|
return {
|
|
286
285
|
useDispatcher,
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
useProp,
|
|
287
|
+
usePropAll,
|
|
289
288
|
useStore,
|
|
290
289
|
};
|
|
291
290
|
}
|
|
@@ -328,6 +327,6 @@ function StoreProvider(props) {
|
|
|
328
327
|
return (jsx(Context.Provider, { value: props.instanceKey, children: props.children }));
|
|
329
328
|
}
|
|
330
329
|
|
|
331
|
-
const { useDispatcher,
|
|
330
|
+
const { useDispatcher, useProp, usePropAll, useStore, } = createStoreRegistry();
|
|
332
331
|
|
|
333
|
-
export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, useDispatcher,
|
|
332
|
+
export { DESTROY, InternalStore, StoreProvider, createStore, createStoreRegistry, useDispatcher, useProp, usePropAll, useStore };
|
package/package.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type InstanceKey } from './types/index.tsx';
|
|
2
|
-
import { type ReducerMap } from './types/index.tsx';
|
|
3
|
-
import { type StateLink } from './types/index.tsx';
|
|
4
|
-
import { type StoreRegistry } from './types/index.tsx';
|
|
5
|
-
import { type StoreState } from './types/index.tsx';
|
|
6
|
-
export declare function createUseState(storeRegistry: StoreRegistry): <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKey?: InstanceKey) => TStoreState[TStateName];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type InstanceKey } from './types/index.tsx';
|
|
2
|
-
import { type ReducerMap } from './types/index.tsx';
|
|
3
|
-
import { type StateLink } from './types/index.tsx';
|
|
4
|
-
import { type StoreRegistry } from './types/index.tsx';
|
|
5
|
-
import { type StoreState } from './types/index.tsx';
|
|
6
|
-
export declare function createUseStateAll(storeRegistry: StoreRegistry): <TStoreState extends StoreState = StoreState, TReducerMap extends ReducerMap<TStoreState> = ReducerMap<TStoreState>, TStateName extends keyof TStoreState = keyof TStoreState>(stateLink: StateLink<string, TStoreState, TReducerMap[`$$init`], TReducerMap[`$$reset`], TStateName>, instanceKeys?: InstanceKey[] | ((state: TStoreState) => boolean)) => [instanceKey: InstanceKey, state: TStoreState[TStateName]][];
|