Created
October 15, 2019 14:21
-
-
Save WDever/0c9f1eb2880c287d962a1984e4886edb to your computer and use it in GitHub Desktop.
This file contains 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
// action.types.ts | |
export enum EditorTypes { | |
SET_BLOCK_TEXT = 'SET_BLOCK_TEXT', | |
SET_BLOCK_TYPE = 'SET_BLOCK_TYPE', | |
SET_CURRENT_BLOCK = 'SET_CURRENT_BLOCK', | |
ADD_BLOCK = 'ADD_BLOCK', | |
DELETE_BLOCK = 'DELETE_BLOCK', | |
} | |
// actions.ts | |
export interface SetBlockTextPayload { | |
text: string; | |
} | |
const { SET_BLOCK_TEXT, ADD_BLOCK } = EditorTypes; | |
// const setText = createStandardAction(SET_TEXT)<SetTextPayload>(); | |
// export type SetText = getType(setText); | |
export const editorActions = { | |
setText: createStandardAction(SET_BLOCK_TEXT)<SetBlockTextPayload>(), | |
addBlock: createStandardAction(ADD_BLOCK)(), | |
}; | |
export type editorReducerAction = ActionType<typeof editorActions>; | |
// reducer.ts | |
const initialState: EditorModel = { | |
blocks: [ | |
{ | |
id: 0, | |
type: 'span', | |
text: '', | |
}, | |
], | |
}; | |
const editorReducer = createReducer<EditorModel, editorReducerAction>( | |
initialState, | |
{ | |
SET_BLOCK_TEXT: (state, action) => produce(state, draft => {}), | |
}, | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment