2.0.1 • Published 4 years ago

create-reducer-object v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

create-reducer-object

This is a very simple helper library. Traditionally, according to the Redux documentation, reducers are written like this:

function myFirstReducer(state, action) {
  switch (action.type) {
    case 'TODO_ADDED':
      return todoAdded(state, action);
  }

  return state;
}

This results in long, unwieldy switch statements when you have many different actions.

You can write the equivalent of the above, using this library, as follows:

import { createReducerObject } from 'create-reducer-object';

const initialState = {
  todos: [],
};

const myFirstReducer = createReducerObject({
  TODO_ADDED: todoAdded
}, initialState);

Typescript compatibility

The module is written in and fully compatible with Typescript. You can define your state like so:

import { createReducerObject } from 'create-reducer-object';

type State = {
  todos: Todo[];
};

const initialState: State = {
  todos: [],
};

const myFirstReducer = createReducerObject<State>({
  TODO_ADDED: todoAdded,
}, initialState);
2.0.1

4 years ago

2.0.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

5 years ago

1.0.0

5 years ago