-
Notifications
You must be signed in to change notification settings - Fork 55
/
index.js
54 lines (44 loc) · 1.05 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// @flow
import {
createStore,
createContainer,
createSubscriber,
createHook,
} from 'react-sweet-state';
import type { State } from './types';
import * as actions from './actions';
import * as selectors from './selectors';
type Actions = typeof actions;
type ContainerProps = {||};
type UserSelectedState = $Call<typeof selectors.getSelected, State>;
const initialState: State = {
selected: null,
data: null,
loading: false,
};
const Store = createStore<State, Actions>({
initialState,
actions,
});
export const UserContainer = createContainer<State, Actions, ContainerProps>(
Store,
{
onInit: actions.load,
}
);
export const UserSubscriber = createSubscriber<State, Actions>(Store);
export const UserSelectedSubscriber = createSubscriber<
State,
Actions,
UserSelectedState,
void
>(Store, {
selector: selectors.getSelected,
});
export const useUser = createHook<State, Actions>(Store);
export const useUserSelected = createHook<
State,
Actions,
UserSelectedState,
void
>(Store, { selector: selectors.getSelected });