Skip to content

Instantly share code, notes, and snippets.

@tehSLy
Last active August 12, 2019 14:00
Show Gist options
  • Select an option

  • Save tehSLy/42cea4c0124fd187d2fc4dc1bab85a31 to your computer and use it in GitHub Desktop.

Select an option

Save tehSLy/42cea4c0124fd187d2fc4dc1bab85a31 to your computer and use it in GitHub Desktop.
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