11// @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 ' ;
44
55const SHOW_USER_MENU = 'base/SHOW_USER_MENU' ;
66const HIDE_USER_MENU = 'base/HIDE_USER_MENU' ;
77const SET_FULLSCREEN_LOADER = 'base/SET_FULLSCREEN_LOADER' ;
88
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 > ;
1418
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,
1927} ;
2028
2129export type Base = {
2230 userMenu : boolean ,
2331 fullscreenLoader : boolean
24- }
32+ } ;
2533
26- const BaseRecord = Record ( {
34+ const initialState : Base = {
2735 userMenu : false ,
2836 fullscreenLoader : false ,
29- } ) ;
30-
31-
32- const initialState : Map < string , * > = BaseRecord ( ) ;
37+ } ;
3338
3439export 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+ } ,
3851} , initialState ) ;
0 commit comments