Skip to content

Instantly share code, notes, and snippets.

@Ajk4
Last active July 20, 2017 08:36
Show Gist options
  • Save Ajk4/11726bea97280c0ee366a9cb9b804899 to your computer and use it in GitHub Desktop.
Save Ajk4/11726bea97280c0ee366a9cb9b804899 to your computer and use it in GitHub Desktop.
Redux in TypeScript
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
});
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;
}
}
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