Redux Fluent
Tiny and eloquent way to manage a redux-like state manager (3K, dependencies free, definitions included).
Motivation
Redux is great, every recent web application was most likely been built on top of it, however we really think we can simplify it further and after our investigation we came out with:
- Reducers usually tend to grow and become hard to maintain, 'cause of the amount of switch-cases.
- Concepts such as Action, Action Type and Action Creator could be squashed into only one.
- The push towards the standards should be stronger.
Installation
To install the stable version:
npm install --save redux-fluent
Usage
import { createAction, createReducer } from 'redux-fluent';
const addTodo = createAction('@@todos | add');
const addTodoTask = (state, { payload }) => ({
...state,
list: state.list.concat(payload),
});
const todosReducer = createReducer('@@todos')
.case(addTodo)
.then(addTodoTask)
.default()
;
export { todosReducer, addTodo };
import { createStore, combineReducers } from 'redux';
import { createCombinableReducers } from 'redux-fluent';
import { otherReducer } from './otherReducer';
import { todosReducer, addTodo } from './todosReducer';
const reducers = combineReducers(
createCombinableReducers(todosReducer, otherReducer),
);
const store = createStore(reducers);
store.dispatch(
addTodo({
id: 1,
title: 'Walk Gipsy',
}),
);