Last active
July 20, 2017 08:36
-
-
Save Ajk4/11726bea97280c0ee366a9cb9b804899 to your computer and use it in GitHub Desktop.
Redux in TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type UiAction = { | |
type: 'SET_INVITE_OTHER_USERS_MODAL_OPENED', | |
modalOpened: boolean | |
} | { | |
type: 'SET_IMAGES_FILTER_QUERY', | |
filterQuery: string | |
} | |
export const setInviteOtherUsersModalOpened = (modalOpened: boolean): UiAction => ({ | |
type: 'SET_INVITE_OTHER_USERS_MODAL_OPENED', | |
modalOpened | |
}); | |
export const setImagesFilterQuery = (filterQuery: string): UiAction => ({ | |
type: 'SET_IMAGES_FILTER_QUERY', | |
filterQuery | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {UiAction} from './actions' | |
import {Store} from "../store"; | |
const initialState: Store.Ui = { | |
inviteOtherUsersModalOpened: false, | |
imagesFilterQuery: '' | |
}; | |
export default function uiReducer(state: Store.Ui = initialState, action: UiAction): Store.Ui { | |
switch (action.type) { | |
case 'SET_INVITE_OTHER_USERS_MODAL_OPENED': { | |
return {...state, inviteOtherUsersModalOpened: action.modalOpened} | |
} | |
case 'SET_IMAGES_FILTER_QUERY': { | |
return {...state, imagesFilterQuery: action.filterQuery} | |
} | |
default: | |
return state; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export namespace Store { | |
export type Ui = { | |
inviteOtherUsersModalOpened: boolean, | |
imagesFilterQuery: string | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment