robodux
Advanced tools
Weekly downloads
Readme
One of the biggest complaints developers have with redux is the amount of
boilerplate and new concepts they have to learn to use it. By using the
robodux
pattern the amount of redux boilerplate is dramatically reduced. In
most cases, wiring up action types, action creators, and reducers can be done in
one line of code.
id
.The overriding principle is that effects (like sagas) should be the central processing unit for all business logic in a react/redux application. We should remove as much business logic as possible from reducers and instead centralize them inside of our side-effect handlers.
The other primary principle is to think of redux as a database and reducers as tables. This simplifies the action/reducer logic and makes it possible to build reuseable components which dramatically reducers boilerplate.
Please see style-guide for more details.
yarn add robodux
The primary philosophical change between this library and other libraries is to think of your redux store as a database.
Reducers are database tables and operating on those tables should have a consistent API for managing them.
robodux
has a few slice helpers that cover ~90% of the logic and data
structures needed to build and scale your state.
These are one-line functions that create action types, action creators, and reducers using a simple set of lower-level functions. There's no magic here, it's more of how we think about our state that has made it dramatically simple to automate repetitive tasks in redux.
One of the more useful APIs from this library is createTable
. This slice
helper creates a reducer and a set of actions that make it easy to treat a slice
as a database table.
import { combineReducers, createStore } from 'redux';
import { createTable, createReducerMap, MapEntity } from 'robodux';
// setup reducer state
interface Comment {
message: string;
timestamp: number;
}
interface State {
comments: MapEntity<Comment>;
}
// create reducer and actions
const comments = createTable<Comment>({ name: 'comments' });
// converts multiple slices into an object of reducers to be used with combineReducers
// { comments: (state, action) => state }
const reducers = createReducerMap(comments);
const rootReducer = combineReducers(reducers);
const store = createStore(rootReducer);
// dispatch action to add a record to our table
store.dispatch(
actions.add({
1: { message: 'you awake?', timestamp: 1577117359 },
}),
);
// { comments: { 1: { message: 'you awake?', timestamp: 1577117359 } } }
store.dispatch(
actions.patch({
1: { message: 'Are you awake?' },
}),
);
// { comments: { 1: { message: 'Are you awake?', timestamp: 1577117359 } } }
const selectors = comments.getSelectors((state) => state[comments.name]);
const state = store.getState();
const commentMap = selectors.selectTable(state);
const commentList = selectors.selectTableAsList(state);
const commentOne = selectors.selectById(state, { id: '1' });
const foundComments = selectors.selectByIds(state, { ids: ['1', '3'] });
FAQs
caching in redux made simple
The npm package robodux receives a total of 512 weekly downloads. As such, robodux popularity was classified as not popular.
We found that robodux demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.