Created
March 22, 2018 14:17
-
-
Save tlaitinen/0b1f4be8c56197200639f0c3b7f9e98e 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 * as crud from './crud'; | |
| import {RootState} from '../reducers'; | |
| export interface Query { | |
| offset?: number; | |
| limit?: number; | |
| } | |
| export interface Project { | |
| id: string; | |
| name: string; | |
| } | |
| export type Action = crud.Action<'projects', Project, Query>; | |
| export type State = crud.State<Project, Query>; | |
| async function fetchFunc(query:Query):Promise<{results:Project[], totalCount:number}> { | |
| // TODO | |
| } | |
| async function putFunc(projectId:string, project:Project):Promise<Project> { | |
| // TODO | |
| } | |
| async function postFunc(project:Project):Promise<Project> { | |
| // TODO | |
| } | |
| async function deleteFunc(projectId:string):Promise<void> { | |
| // TODO | |
| } | |
| const getState = (state:RootState) => state.projects; | |
| export const selectors = crud.mkSelectors<Project, Query, RootState>(getState); | |
| export const actions = crud.mkActions<'projects', | |
| Project, | |
| Query, | |
| RootState>({ | |
| crud:'projects', | |
| getId: p => p.id, | |
| getState, | |
| fetchFunc, | |
| putFunc, | |
| postFunc, | |
| deleteFunc | |
| }); | |
| export const reducer = crud.mkReducer<'projects', Project, Query>('projects'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment