@chhsiao1981/use-thunk 10.4.0 → 11.0.0
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/ThunkContext.d.ts +7 -0
- package/dist/createReducer.d.ts +4 -0
- package/dist/createThunk.d.ts +4 -0
- package/dist/dispatch.d.ts +4 -0
- package/dist/dispatchFuncMap.d.ts +18 -0
- package/dist/genUUID.d.ts +1 -0
- package/dist/index.d.ts +15 -0
- package/{types → dist}/init.d.ts +0 -3
- package/dist/reduceMap.d.ts +6 -0
- package/dist/reducer.d.ts +5 -0
- package/dist/remove.d.ts +5 -0
- package/dist/setDefaultID.d.ts +5 -0
- package/dist/stateTypes.d.ts +16 -0
- package/dist/states.d.ts +9 -0
- package/{types → dist}/thunk.d.ts +6 -3
- package/dist/thunkContextMap.d.ts +15 -0
- package/dist/thunkContextTypes.d.ts +8 -0
- package/{types → dist}/thunkModuleFuncMap.d.ts +1 -0
- package/dist/update.d.ts +6 -0
- package/dist/useThunk.d.ts +12 -0
- package/dist/useThunkReducer.d.ts +17 -0
- package/package.json +1 -1
- package/src/ThunkContext.tsx +17 -17
- package/src/action/ActionOrThunk.ts +5 -0
- package/src/action/baseAction.ts +6 -0
- package/src/action/index.ts +16 -0
- package/src/action/thunk.ts +5 -0
- package/src/createReducer.ts +7 -7
- package/src/createThunk.ts +31 -0
- package/src/index.ts +21 -27
- package/src/init/index.ts +26 -0
- package/src/init/initCore.ts +31 -0
- package/src/reduceMap.ts +3 -4
- package/src/reducer.ts +4 -4
- package/src/remove.ts +10 -25
- package/src/set.ts +7 -0
- package/src/setDefaultID.ts +5 -5
- package/src/setMap.ts +65 -0
- package/src/stateTypes.ts +4 -3
- package/src/states.ts +17 -17
- package/src/thunkContextMap.ts +4 -4
- package/src/thunkContextTypes.ts +4 -4
- package/src/thunkModule/defaultThunkModuleFuncMap.ts +16 -0
- package/src/thunkModule/index.ts +21 -0
- package/src/update.ts +31 -0
- package/src/useThunk.ts +24 -44
- package/src/useThunkReducer.ts +33 -44
- package/types/ThunkContext.d.ts +4 -4
- package/types/action/ActionOrThunk.d.ts +4 -0
- package/types/action/baseAction.d.ts +5 -0
- package/types/action/index.d.ts +8 -0
- package/types/action/thunk.d.ts +3 -0
- package/types/createThunk.d.ts +5 -0
- package/types/dispatch.d.ts +1 -1
- package/types/dispatchFuncMap.d.ts +4 -5
- package/types/index.d.ts +14 -8
- package/types/init/index.d.ts +7 -0
- package/types/init/initCore.d.ts +9 -0
- package/types/reducer.d.ts +4 -4
- package/types/remove.d.ts +4 -4
- package/types/set.d.ts +4 -0
- package/types/setDefaultID.d.ts +3 -3
- package/types/setMap.d.ts +17 -0
- package/types/stateTypes.d.ts +3 -2
- package/types/states.d.ts +8 -8
- package/types/thunkContextMap.d.ts +4 -4
- package/types/thunkContextTypes.d.ts +4 -4
- package/types/thunkModule/defaultThunkModuleFuncMap.d.ts +5 -0
- package/types/thunkModule/index.d.ts +16 -0
- package/types/update.d.ts +6 -0
- package/types/useThunk.d.ts +5 -8
- package/types/useThunkReducer.d.ts +5 -11
- package/dist/index.js +0 -1723
- package/dist/index.umd.cjs +0 -50
- package/src/action.ts +0 -20
- package/src/dispatch.ts +0 -6
- package/src/dispatchFuncMap.ts +0 -67
- package/src/init.ts +0 -64
- package/src/registerThunk.ts +0 -42
- package/src/setData.ts +0 -26
- package/src/thunk.ts +0 -20
- package/src/thunkModuleFuncMap.ts +0 -11
- package/types/registerThunk.d.ts +0 -4
- package/types/setData.d.ts +0 -5
- /package/{types → dist}/action.d.ts +0 -0
package/types/set.d.ts
ADDED
package/types/setDefaultID.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
1
|
+
import type BaseAction from './action/baseAction';
|
|
2
|
+
import type { ModuleState, State } from './stateTypes';
|
|
3
3
|
export declare const SET_DEFAULT_ID = "@chhsiao1981/use-thunk/SET_DEFAULT_ID";
|
|
4
4
|
export declare const setDefaultID: (myID: string) => BaseAction;
|
|
5
|
-
export declare const reduceSetDefaultID: <S extends State>(
|
|
5
|
+
export declare const reduceSetDefaultID: <S extends State>(moduleState: ModuleState<S>, action: BaseAction) => ModuleState<S>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { set } from './set';
|
|
2
|
+
import type { State } from './stateTypes';
|
|
3
|
+
import type { ThunkModule, ThunkModuleFunc } from './thunkModule';
|
|
4
|
+
import { type DefaultThunkModuleFuncMap } from './thunkModule/defaultThunkModuleFuncMap';
|
|
5
|
+
type VoidReturnType<T extends (...params: any[]) => unknown> = (...params: Parameters<T>) => void;
|
|
6
|
+
export type setMap<S extends State, T extends ThunkModuleFunc<S>> = {
|
|
7
|
+
[action in keyof T]: VoidReturnType<T[action]>;
|
|
8
|
+
} & Omit<DefaultSetMap, keyof T>;
|
|
9
|
+
export type DefaultSetMap = {
|
|
10
|
+
[action in keyof DefaultThunkModuleFuncMap]: VoidReturnType<DefaultThunkModuleFuncMap[action]>;
|
|
11
|
+
};
|
|
12
|
+
export interface setMapByModuleMap<S extends State, T extends ThunkModuleFunc<S>> {
|
|
13
|
+
[name: string]: setMap<S, T>;
|
|
14
|
+
}
|
|
15
|
+
export declare const SET_MAP_BY_MODULE_MAP: setMapByModuleMap<any, any>;
|
|
16
|
+
export declare const constructSetMap: <S extends State, T extends ThunkModuleFunc<S>>(theDo: ThunkModule<S>, set: set<S>, setMap: setMap<S, T>) => setMap<S, T>;
|
|
17
|
+
export {};
|
package/types/stateTypes.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ export type NodeState<S extends State> = {
|
|
|
8
8
|
export type NodeStateMap<S extends State> = {
|
|
9
9
|
[key: string]: NodeState<S>;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
12
|
-
|
|
11
|
+
export type ModuleState<S extends State> = {
|
|
12
|
+
name?: string;
|
|
13
|
+
myClass?: string;
|
|
13
14
|
defaultID?: string | null;
|
|
14
15
|
nodes: NodeStateMap<S>;
|
|
15
16
|
defaultState: S;
|
package/types/states.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type { ThunkModuleFunc } from './
|
|
1
|
+
import type { setMap } from './setMap';
|
|
2
|
+
import type { ModuleState, NodeState, State } from './stateTypes';
|
|
3
|
+
import type { ThunkModuleFunc } from './thunkModule';
|
|
4
4
|
import type { UseThunk } from './useThunk';
|
|
5
|
-
export declare const getDefaultID: <S extends State>(
|
|
6
|
-
export declare const getNode: <S extends State>(
|
|
7
|
-
export declare const getState: <S extends State>(
|
|
8
|
-
export declare const mustGetState: <S extends State>(
|
|
9
|
-
export declare const mustGetStateByThunk: <S extends State, R extends ThunkModuleFunc<S>>(theUseThunk: UseThunk<S, R>, myID?: string) => [S,
|
|
5
|
+
export declare const getDefaultID: <S extends State>(moduleState: ModuleState<S>) => string;
|
|
6
|
+
export declare const getNode: <S extends State>(moduleState: ModuleState<S>, myID?: string) => NodeState<S> | null;
|
|
7
|
+
export declare const getState: <S extends State>(moduleState: ModuleState<S>, myID?: string) => S | null;
|
|
8
|
+
export declare const mustGetState: <S extends State>(moduleState: ModuleState<S>, myID?: string) => S;
|
|
9
|
+
export declare const mustGetStateByThunk: <S extends State, R extends ThunkModuleFunc<S>>(theUseThunk: UseThunk<S, R>, myID?: string) => [S, setMap<S, R>, string];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Context as rContext } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModuleState } from './stateTypes';
|
|
3
3
|
import type { Context } from './thunkContextTypes';
|
|
4
4
|
export type ThunkContextMap = {
|
|
5
5
|
theMap: {
|
|
6
|
-
[
|
|
6
|
+
[moduleName: string]: {
|
|
7
7
|
context: rContext<Context<any>>;
|
|
8
|
-
|
|
9
|
-
current:
|
|
8
|
+
refModuleState: {
|
|
9
|
+
current: ModuleState<any>;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ModuleState, State } from './stateTypes';
|
|
3
3
|
export type Context<S extends State> = {
|
|
4
|
-
|
|
5
|
-
current:
|
|
4
|
+
refModuleState: {
|
|
5
|
+
current: ModuleState<S>;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
setModuleState: Dispatch<SetStateAction<ModuleState<S>>>;
|
|
8
8
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ThunkFunc } from '../action';
|
|
2
|
+
import type { Reducer } from '../reducer';
|
|
3
|
+
import type { State } from '../stateTypes';
|
|
4
|
+
export interface ThunkModuleBase<S extends State> {
|
|
5
|
+
[idx: string]: ThunkFunc<S> | string | Reducer<S> | S | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface ThunkModuleFunc<S extends State> extends ThunkModuleBase<S> {
|
|
8
|
+
[action: string]: ThunkFunc<S>;
|
|
9
|
+
}
|
|
10
|
+
export type ThunkModule<S extends State> = {
|
|
11
|
+
name?: string;
|
|
12
|
+
myClass?: string;
|
|
13
|
+
default?: Reducer<S>;
|
|
14
|
+
defaultState: S;
|
|
15
|
+
} & ThunkModuleBase<S>;
|
|
16
|
+
export type ThunkModuleToFunc<T> = Omit<T, 'name' | 'myClass' | 'default' | 'defaultState'>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type BaseAction from './action/baseAction';
|
|
2
|
+
import type { ModuleState, State } from './stateTypes';
|
|
3
|
+
export declare const UPDATE = "@chhsiao1981/use-thunk/UPDATE";
|
|
4
|
+
export declare const update: <S extends State>(myID: string, data: Partial<S>) => BaseAction;
|
|
5
|
+
export declare const setData: <S extends State>(myID: string, data: Partial<S>) => BaseAction;
|
|
6
|
+
export declare const reduceUpdate: <S extends State>(moduleState: ModuleState<S>, action: BaseAction) => ModuleState<S>;
|
package/types/useThunk.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
import type { ThunkModule, ThunkModuleFunc } from './
|
|
4
|
-
export type UseThunk<S extends State, R extends ThunkModuleFunc<S>> = [
|
|
5
|
-
ClassState<S>,
|
|
6
|
-
DispatchFuncMap<S, R>
|
|
7
|
-
];
|
|
1
|
+
import { type setMap } from './setMap';
|
|
2
|
+
import type { ModuleState, State } from './stateTypes';
|
|
3
|
+
import type { ThunkModule, ThunkModuleFunc } from './thunkModule';
|
|
4
|
+
export type UseThunk<S extends State, R extends ThunkModuleFunc<S>> = [ModuleState<S>, setMap<S, R>];
|
|
8
5
|
/**********
|
|
9
6
|
* useThunk
|
|
10
7
|
**********/
|
|
11
|
-
declare const _default: <S extends State, R extends ThunkModuleFunc<S>>(theDo: ThunkModule<S
|
|
8
|
+
declare const _default: <S extends State, R extends ThunkModuleFunc<S>>(theDo: ThunkModule<S>) => UseThunk<S, R>;
|
|
12
9
|
export default _default;
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
export type Thunk<S extends State, A extends BaseAction> = (dispatch: Dispatch<ActionOrThunk<S, A>>, getClassState: () => ClassState<S>) => void;
|
|
5
|
-
export type ActionOrThunk<S extends State, A extends BaseAction> = A | Thunk<S, A>;
|
|
1
|
+
import type { Reducer } from './reducer';
|
|
2
|
+
import type { set } from './set';
|
|
3
|
+
import type { ModuleState, State } from './stateTypes';
|
|
6
4
|
/**
|
|
7
5
|
* useThunkReducer
|
|
8
6
|
*
|
|
9
7
|
* Augments React's useReducer() hook so that the action
|
|
10
|
-
* dispatcher supports thunks.
|
|
11
|
-
*
|
|
12
|
-
* @param {Function} reducer
|
|
13
|
-
* @param {string} className
|
|
14
|
-
* @returns {[ClassState<S>, Dispatch]}
|
|
8
|
+
* setter (dispatcher) supports thunks.
|
|
15
9
|
*/
|
|
16
|
-
declare const _default: <S extends State
|
|
10
|
+
declare const _default: <S extends State>(reducer: Reducer<S>, moduleName: string) => [ModuleState<S>, set<S>];
|
|
17
11
|
export default _default;
|