-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoreBinder.ts
30 lines (27 loc) · 915 Bytes
/
StoreBinder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { StonexModules, StonexStore } from '.'
/**
* StoreBinder it is structure which helps Stonex Module to connect with Store
*/
export declare interface StoreBinder<State, MP = any> {
getState: () => State,
moduleName: string
modules: StonexModules<MP>
resetState: (callback?: (state: any) => any) => void
setState: (changes: (((state: State) => Partial<State>) | Partial<State>), callback?: (state: State) => any) => any
}
/**
* Function which creates and returns StoreBinder
*
* @param {string} moduleName
* @param {StonexStore<MP>} store
*/
export const createStoreBinder = <MP, State>(
moduleName: string,
store: StonexStore<MP>,
): StoreBinder<State, MP> => ({
getState: store.getState.bind(store, moduleName),
moduleName,
modules: store.modules,
resetState: store.resetState.bind(store, moduleName),
setState: store.setState.bind(store, moduleName),
})