Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // store/coreReducer.ts
- import { Action } from 'redux';
- interface Dictionary<T> {
- [key: string]: T;
- }
- export function callAction<Data>(type: string, data?: Data): Action<Data> {
- return { type, data };
- }
- export abstract class ReducerCollection<State> {
- protected actions: Dictionary<(state: State, action?) => State> = this.createActions();
- protected initialState: State = this.initState();
- public changeState<Data>(
- state: State = this.initialState,
- action: Action<Data> = { type: '', data: undefined }
- ): State {
- if (action.type && this.actions[action.type]) {
- return this.actions[action.type](state, action);
- }
- return state;
- }
- protected abstract createActions(): Dictionary<(state: State, action?) => State>;
- protected abstract initState(): State;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement