Last active
November 9, 2017 10:45
-
-
Save tlaitinen/c6ec07fc87a3e0176712e82569f43842 to your computer and use it in GitHub Desktop.
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 {ActionCreator} from 'react-redux-typescript'; | |
| export interface CrudResult { | |
| results: string[]; | |
| totalCount: number; | |
| } | |
| export interface CrudState<E,Q> { | |
| readonly queries: Readonly<{[queryName:string]: Q}>; | |
| readonly results: Readonly<{[queryName:string]: CrudResult}>; | |
| readonly loading: Readonly<{[queryName:string]: boolean}>; | |
| readonly busy: Readonly<{[entityId:string]: boolean}>; | |
| readonly entities: Readonly<{[entityId:string]: E}>; | |
| readonly selected: Readonly<{[entityId:string]: boolean}>; | |
| } | |
| function mkActionCreators<N,E,Q>(names) { | |
| return { | |
| SetBusy: new ActionCreator<N['SET_BUSY'], {entityId:string, busy:boolean}>(names('SET_BUSY')), | |
| ClearSelected: new ActionCreator<N['CLEAR_SELECTED', {queryName:string}>(names('CLEAR_SELECTED')), | |
| SetSelected: new ActionCreator<N['SET_SELECTED', {queryName:string, entityIdList:string[], selected:boolean}>(names('SET_SELECTED')), | |
| SetLoading: new ActionCreator<N['SET_LOADING', {queryName:string, loading:boolean}>(names('SET_LOADING')), | |
| SetQuery: new ActionCreator<N['SET_QUERY', {queryName:string, query:Q}>(names('SET_QUERY')), | |
| Receive: new ActionCreator<N['RECEIVE', {queryName:string, results:E[], totalCount:number}>(names('RECEIVE')), | |
| LocalUpdate: new ActionCreator<N['LOCAL_UPDATE'], {entityId:string, entity:Entity}>(names('LOCAL_UPDATE')) | |
| }; | |
| } | |
| export type Action<N,E,Q> = ActionCreator<N['SET_BUSY'], {entityId:string, busy:boolean}> | |
| | ActionCreator<N['CLEAR_SELECTED'], {queryName:string}> | |
| | ActionCreator<N['SET_SELECTED'], {queryName:string,entityIdList:string[], selected:boolean}> | |
| | ActionCreator<N['SET_LOADING'], {queryName:string, loading:boolean}> | |
| | ActionCreator<N['SET_QUERY'], {queryName:string, query:Q}> | |
| | ActionCreator<N['RECEIVE'], {queryName:string, results:E[], totalCount:number}> | |
| | ActionCreator<N['LOCAL_UPDATE'], {entityId:string, entity:E}>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment