File tree 5 files changed +56
-21
lines changed
5 files changed +56
-21
lines changed Original file line number Diff line number Diff line change
1
+ import Manager from './store' ;
2
+
3
+ import type { SetStateAction } from 'react' ;
4
+ import type { Options , State } from '../@types' ;
5
+
6
+ export function createStore ( options ?: Options ) : void {
7
+ return Manager . store ( options ) ;
8
+ }
9
+
10
+ export function setStore < StateType extends State = State > (
11
+ item : SetStateAction < StateType >
12
+ ) {
13
+ return Manager . set ( item ) ;
14
+ }
15
+
16
+ export function getStore < StateType = any > ( item ?: string ) : StateType {
17
+ return Manager . get ( item ) ;
18
+ }
19
+
20
+ export function resetStore ( ) {
21
+ return Manager . reset ( ) ;
22
+ }
Original file line number Diff line number Diff line change 1
1
import useForceUpdate from 'use-force-update' ;
2
- import { SetStateAction , useEffect } from 'react' ;
3
2
4
3
import Manager from './store' ;
5
4
6
- import { Options , State } from '../@types/core' ;
7
- import { SetStoreFn , Reducer } from '../@types/functions' ;
8
-
9
- export function createStore ( options ?: Options ) : void {
10
- return Manager . store ( options ) ;
11
- }
5
+ import type { State } from '../@types/core' ;
6
+ import type { SetStoreFn , Reducer } from '../@types/functions' ;
12
7
13
8
export function useStore < StateType = any > ( ) : [ State , SetStoreFn < State > ] ;
14
9
export function useStore < StateType = any > (
@@ -87,12 +82,4 @@ export function useStaticReducer<PayloadType = any>(
87
82
return Manager . useReducer < PayloadType > ( reducer ) ;
88
83
}
89
84
90
- export function setStore < StateType extends State = State > (
91
- item : SetStateAction < StateType >
92
- ) {
93
- return Manager . set ( item ) ;
94
- }
95
85
96
- export function getStore < StateType = any > ( item ?: string ) : StateType {
97
- return Manager . get ( item ) ;
98
- }
Original file line number Diff line number Diff line change @@ -182,6 +182,14 @@ export default class Manager {
182
182
return runner < PayloadType > ( reducerFunction ( reducer . name ) ) ;
183
183
}
184
184
185
+ /**
186
+ * Reset state to it's default value
187
+ */
188
+ public static reset ( ) {
189
+ this . applyPluginHook ( 'onReset' , this . _options . defaultState ) ;
190
+ this . set ( this . _options . defaultState ) ;
191
+ }
192
+
185
193
protected static _pluginInit ( plugins : Plugin [ ] ) {
186
194
plugins . forEach ( ( plugin : any ) => {
187
195
/**
Original file line number Diff line number Diff line change @@ -2,11 +2,15 @@ export * from './@types';
2
2
export * from './plugins/' ;
3
3
4
4
export {
5
- createStore ,
6
- setStore ,
7
- getStore ,
8
5
useStore ,
9
6
useStaticStore ,
10
7
useReducer ,
11
8
useStaticReducer ,
12
9
} from './core/hooks' ;
10
+
11
+ export {
12
+ createStore ,
13
+ setStore ,
14
+ getStore ,
15
+ resetStore ,
16
+ } from './core/functions' ;
You can’t perform that action at this time.
0 commit comments