dphilipson / typescript-fsa-reducers

Fluent syntax for defining typesafe reducers on top of typescript-fsa.
MIT License
220 stars 16 forks source link

Fix equivalent example in README #19

Closed sompylasar closed 7 years ago

sompylasar commented 7 years ago

The state variable came from nowhere.

Using this library, the above is exactly equivalent to the following code:

import { reducerWithInitialState } from "typescript-fsa-reducers";

const reducer = reducerWithInitialState(INITIAL_STATE)
    .case(setName, (action, name) => ({ ...state, name }))
    .case(addBalance, (action, amount) => ({
        ...state,
        balance: state.balance + amount,
    }))
    .case(setIsFrozen, (action, isFrozen) => ({ ...state, isFrozen }));
dphilipson commented 7 years ago

You're absolutely right, thank you very much for the PR!