Last active
August 12, 2019 14:00
-
-
Save tehSLy/42cea4c0124fd187d2fc4dc1bab85a31 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { createActions, handleActions, combineActions } from 'redux-actions'; | |
| const defaultState = { counter: 10 }; | |
| const { increment, decrement } = createActions({ | |
| INCREMENT: (amount = 1) => ({ amount }), | |
| DECREMENT: (amount = 1) => ({ amount: -amount }) | |
| }); | |
| const reducer = handleActions( | |
| { | |
| [combineActions(increment, decrement)]: ( | |
| state, | |
| { payload: { amount } } | |
| ) => { | |
| return { ...state, counter: state.counter + amount }; | |
| } | |
| }, | |
| defaultState | |
| ); | |
| export default reducer; | |
| //vs | |
| import {createStore, createApi} from "effector"; | |
| const defaultState = { counter: 10 }; | |
| const counter = createStore(defaultState); | |
| const {increment, decrement} = createApi(counter, { | |
| increment: (s, payload = 1) => ({...s, counter: s.counter + payload}), | |
| decrement: (s, payload = 1) => ({...s, counter: s.counter - payload}) | |
| }); | |
| export default counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment