@chhsiao1981/use-thunk 10.2.0 → 10.3.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/README.md CHANGED
@@ -290,11 +290,11 @@ classStateUser = {
290
290
 
291
291
  ### Basic
292
292
 
293
- ##### `useThunk(theDo: ThunkModuleFunc): [ClassState, DispatchedAction]`
293
+ ##### `useThunk(theDo: ThunkModuleFunc): [ClassState, DispatchedFuncMap]`
294
294
 
295
295
  Similar to `React.useReducer`, but we use `useThunk`, and we also bind the actions with dispatch (similar concept as `mapDispatchToProps`).s
296
296
 
297
- return: `[ClassState<S>, DispatchedAction<S>]`
297
+ return: `[ClassState<S>, DispatchedFuncMap<S, R>]`
298
298
 
299
299
  ##### `init({myID, parentID, doParent, state}, myuuidv4?)`
300
300
 
@@ -318,14 +318,16 @@ generate uuid for react-object.
318
318
 
319
319
  Get the state of `myID`. Get the state of `defaultID` if `myID` is not present. Return `null` if not available.
320
320
 
321
- ##### `getStateOrDefault(state: ClassState, myID?: string): State`
321
+ ##### `mustGetState(state: ClassState, myID?: string): State`
322
322
 
323
323
  Get the state of `myID`. Get the state of `defaultID` if `myID` is not present. Return `defaultState` if not available.
324
324
 
325
- ##### `getStateByThunk(theUseThunk: UseThunk, myID?: string): [State, DispatchedActionMap, theID]`
325
+ ##### `mustGetStateByThunk(theUseThunk: UseThunk, myID?: string): [State, DispatchedActionMap, theID]`
326
326
 
327
327
  Get the state of `myID` by `UseThunk`. Get the state of `defaultID` if `myID` is not present. Return `defaultState` if not available.
328
328
 
329
+ return: `[S, DispatchedFuncMap<S, R>, theID]`
330
+
329
331
  ##### `getDefaultID(state: ClassState): string`
330
332
 
331
333
  get the default id.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chhsiao1981/use-thunk",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "type": "module",
5
5
  "description": "A framework easily using useThunk to manage the data-state.",
6
6
  "homepage": "https://github.com/chhsiao1981/use-thunk",
package/src/index.ts CHANGED
@@ -7,8 +7,8 @@ import registerThunk from './registerThunk'
7
7
  import { remove } from './remove'
8
8
  import { setData } from './setData'
9
9
  import { setDefaultID } from './setDefaultID'
10
- import { getDefaultID, getNode, getState, getStateByThunk, getStateOrDefault } from './states'
11
- import type { ClassState, NodeMeta, NodeState, NodeStateMap, State } from './stateTypes'
10
+ import { getDefaultID, getNode, getState, mustGetState, mustGetStateByThunk } from './states'
11
+ import type { ClassState, NodeState, NodeStateMap, State } from './stateTypes'
12
12
  import ThunkContext from './ThunkContext'
13
13
  import type { ThunkModule, ThunkModuleToFunc } from './thunk'
14
14
  import useThunk, { type UseThunk } from './useThunk'
@@ -20,7 +20,6 @@ export {
20
20
  type UseThunk,
21
21
  type State,
22
22
  type NodeState,
23
- type NodeMeta,
24
23
  type NodeStateMap,
25
24
  // type NodeStateMapByClass, // XXX for global state
26
25
  type ClassState,
@@ -39,8 +38,8 @@ export {
39
38
  getDefaultID,
40
39
  getNode,
41
40
  getState,
42
- getStateOrDefault,
43
- getStateByThunk,
41
+ mustGetState,
42
+ mustGetStateByThunk,
44
43
  init,
45
44
  type InitParams,
46
45
  setData,
package/src/stateTypes.ts CHANGED
@@ -13,10 +13,6 @@ export type NodeStateMap<S extends State> = {
13
13
  [key: string]: NodeState<S>
14
14
  }
15
15
 
16
- export type NodeStateMapByClass<S extends State> = {
17
- [className: string]: NodeStateMap<S>
18
- }
19
-
20
16
  // ClassState
21
17
  export type ClassState<S extends State> = {
22
18
  myClass: string
@@ -24,11 +20,3 @@ export type ClassState<S extends State> = {
24
20
  nodes: NodeStateMap<S>
25
21
  defaultState: S
26
22
  }
27
-
28
- // Node
29
- export type NodeMeta = {
30
- id: string
31
- theClass: string
32
- // @ts-expect-error do can be any type.
33
- do: DispatchFuncMap
34
- }
package/src/states.ts CHANGED
@@ -32,16 +32,16 @@ export const getState = <S extends State>(classState: ClassState<S>, myID?: stri
32
32
  return me.state
33
33
  }
34
34
 
35
- export const getStateOrDefault = <S extends State>(classState: ClassState<S>, myID?: string): S => {
35
+ export const mustGetState = <S extends State>(classState: ClassState<S>, myID?: string): S => {
36
36
  return getState(classState, myID) || classState.defaultState
37
37
  }
38
38
 
39
- export const getStateByThunk = <S extends State, R extends ThunkModuleFunc<S>>(
39
+ export const mustGetStateByThunk = <S extends State, R extends ThunkModuleFunc<S>>(
40
40
  theUseThunk: UseThunk<S, R>,
41
41
  myID?: string,
42
42
  ): [S, DispatchFuncMap<S, R>, string] => {
43
43
  const [classState, theDo] = theUseThunk
44
44
  const theID = myID ? myID : getDefaultID(classState)
45
- const state = getStateOrDefault(classState, theID)
45
+ const state = mustGetState(classState, theID)
46
46
  return [state, theDo, theID]
47
47
  }
package/types/index.d.ts CHANGED
@@ -7,9 +7,9 @@ import registerThunk from './registerThunk';
7
7
  import { remove } from './remove';
8
8
  import { setData } from './setData';
9
9
  import { setDefaultID } from './setDefaultID';
10
- import { getDefaultID, getNode, getState, getStateByThunk, getStateOrDefault } from './states';
11
- import type { ClassState, NodeMeta, NodeState, NodeStateMap, State } from './stateTypes';
10
+ import { getDefaultID, getNode, getState, mustGetState, mustGetStateByThunk } from './states';
11
+ import type { ClassState, NodeState, NodeStateMap, State } from './stateTypes';
12
12
  import ThunkContext from './ThunkContext';
13
13
  import type { ThunkModule, ThunkModuleToFunc } from './thunk';
14
14
  import useThunk, { type UseThunk } from './useThunk';
15
- export { registerThunk, useThunk, ThunkContext, type UseThunk, type State, type NodeState, type NodeMeta, type NodeStateMap, type ClassState, type GetClassState, type Thunk, type ThunkModule, type ThunkModuleToFunc, type Dispatch, type DispatchFuncMap, getDefaultID, getNode, getState, getStateOrDefault, getStateByThunk, init, type InitParams, setData, remove, setDefaultID, genUUID, };
15
+ export { registerThunk, useThunk, ThunkContext, type UseThunk, type State, type NodeState, type NodeStateMap, type ClassState, type GetClassState, type Thunk, type ThunkModule, type ThunkModuleToFunc, type Dispatch, type DispatchFuncMap, getDefaultID, getNode, getState, mustGetState, mustGetStateByThunk, init, type InitParams, setData, remove, setDefaultID, genUUID, };
@@ -8,17 +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 NodeStateMapByClass<S extends State> = {
12
- [className: string]: NodeStateMap<S>;
13
- };
14
11
  export type ClassState<S extends State> = {
15
12
  myClass: string;
16
13
  defaultID?: string | null;
17
14
  nodes: NodeStateMap<S>;
18
15
  defaultState: S;
19
16
  };
20
- export type NodeMeta = {
21
- id: string;
22
- theClass: string;
23
- do: DispatchFuncMap;
24
- };
package/types/states.d.ts CHANGED
@@ -5,5 +5,5 @@ import type { UseThunk } from './useThunk';
5
5
  export declare const getDefaultID: <S extends State>(classState: ClassState<S>) => string;
6
6
  export declare const getNode: <S extends State>(classState: ClassState<S>, myID?: string) => NodeState<S> | null;
7
7
  export declare const getState: <S extends State>(classState: ClassState<S>, myID?: string) => S | null;
8
- export declare const getStateOrDefault: <S extends State>(classState: ClassState<S>, myID?: string) => S;
9
- export declare const getStateByThunk: <S extends State, R extends ThunkModuleFunc<S>>(theUseThunk: UseThunk<S, R>, myID?: string) => [S, DispatchFuncMap<S, R>, string];
8
+ export declare const mustGetState: <S extends State>(classState: ClassState<S>, myID?: string) => S;
9
+ export declare const mustGetStateByThunk: <S extends State, R extends ThunkModuleFunc<S>>(theUseThunk: UseThunk<S, R>, myID?: string) => [S, DispatchFuncMap<S, R>, string];