1
1
// @flow
2
- import { createAction , handleActions } from 'redux-actions' ;
3
- import { Record , type Map } from 'immutable ' ;
2
+ import { createAction , handleActions , type ActionTypes } from 'redux-actions' ;
3
+ import produce from 'immer ' ;
4
4
5
5
const SHOW_USER_MENU = 'base/SHOW_USER_MENU' ;
6
6
const HIDE_USER_MENU = 'base/HIDE_USER_MENU' ;
7
7
const SET_FULLSCREEN_LOADER = 'base/SET_FULLSCREEN_LOADER' ;
8
8
9
- export type BaseActionCreators = {
10
- showUserMenu ( ) : any ,
11
- hideUserMenu ( ) : any ,
12
- setFullscreenLoader ( visibility : boolean ) : any ,
13
- } ;
9
+ const showUserMenu = createAction ( SHOW_USER_MENU ) ;
10
+ const hideUserMenu = createAction ( HIDE_USER_MENU ) ;
11
+ const setFullscreenLoader = createAction (
12
+ SET_FULLSCREEN_LOADER ,
13
+ ( visibility ) : boolean => visibility ) ;
14
+
15
+ type ShowUserMenuAction = ActionType < typeof showUserMenu > ;
16
+ type HideUserMenuAction = ActionType < typeof hideUserMenu > ;
17
+ type SetFullscreenLoaderAction = ActionType < typeof setFullscreenLoader > ;
14
18
15
- export const actionCreators = {
16
- showUserMenu : createAction ( SHOW_USER_MENU ) ,
17
- hideUserMenu : createAction ( HIDE_USER_MENU ) ,
18
- setFullscreenLoader : createAction ( SET_FULLSCREEN_LOADER ) ,
19
+ export interface BaseActionCreators {
20
+ showUserMenu ( ) : ShowUserMenuAction ,
21
+ hideUserMenu ( ) : HideUserMenuAction ,
22
+ setFullscreenLoader ( ) : SetFullscreenLoaderAction
23
+ }
24
+
25
+ export const actionCreators : BaseActionCreators = {
26
+ showUserMenu, hideUserMenu, setFullscreenLoader,
19
27
} ;
20
28
21
29
export type Base = {
22
30
userMenu : boolean ,
23
31
fullscreenLoader : boolean
24
- }
32
+ } ;
25
33
26
- const BaseRecord = Record ( {
34
+ const initialState : Base = {
27
35
userMenu : false ,
28
36
fullscreenLoader : false ,
29
- } ) ;
30
-
31
-
32
- const initialState : Map < string , * > = BaseRecord ( ) ;
37
+ } ;
33
38
34
39
export default handleActions ( {
35
- [ SHOW_USER_MENU ] : state => state . set ( 'userMenu' , true ) ,
36
- [ HIDE_USER_MENU ] : state => state . set ( 'userMenu' , false ) ,
37
- [ SET_FULLSCREEN_LOADER ] : ( state , { payload : visibility } ) => state . set ( 'fullscreenLoader' , visibility ) ,
40
+ [ SHOW_USER_MENU ] : state => produce ( state , ( draft ) => {
41
+ draft . userMenu = true ;
42
+ } ) ,
43
+ [ HIDE_USER_MENU ] : state => produce ( state , ( draft ) => {
44
+ draft . userMenu = false ;
45
+ } ) ,
46
+ [ SET_FULLSCREEN_LOADER ] : ( state , action : SetFullscreenLoaderAction ) => {
47
+ return produce ( state , ( draft ) => {
48
+ draft . fullscreenLoader = action . payload ;
49
+ } ) ;
50
+ } ,
38
51
} , initialState ) ;
0 commit comments