diff --git a/README.md b/README.md index 7b695d3..c6b4c77 100644 --- a/README.md +++ b/README.md @@ -387,15 +387,19 @@ counterReducer(0, increment()); // => 1 A default handler can be attached, which is invoked for all actions not associated with a handler. ```ts -const add = createAction('todos/ADD', length => length)(); -const reset = createAction('', () => 0)(); -const counterReducer = createReducer(0) - .handleAction(add, (state, action) => state + action.payload) - .defaultHandler((state, action) => state = action.payload); - -const store = createStore(counterReducer); -store.dispatch(add(3)); -store.dispatch(reset()); +const increment = createAction('counter/INCREMENT')(); +const decrement = createAction('counter/DECREMENT')(); +const initialState = 0; +const counterReducer = createReducer(initialState) + .handleAction(increment, (state, action) => state + action.payload) + .handleAction(decrement, (state, action) => state - action.payload) + .defaultHandler(() => initialState); +const otherAction = createAction('others/ACTION', () => null)(); + +const store = createStore(counterReducer); // => 0 +store.dispatch(increment(3)); // => 3 +store.dispatch(decrement(2)); // => 2 +store.dispatch(ohterAction()); // => 0 ``` #### Alternative usage with regular switch reducer