• Stars
    star
    101
  • Rank 338,289 (Top 7 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

caching in redux made simple

robodux

ci

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.

Features

  • Create actions, reducer, and selectors for common data structures
  • Automates the boring parts of redux
  • Dramatically reduces redux boilerplate
  • Works well with saga-query

What's included

  • createTable: Thinking of reducers as database tables, this function builds actions, reducer, and selectors that builds simple and repeatable operations for that table.
  • createAssign: A catch-all data structure that makes it easy to set or reset the reducer.
  • createList: Store an array of items in a slice
  • createLoaderTable: Store as many independent loaders in this reducer which are all accessible by an id.
  • createSlice: Core function that the above slice helpers leverage. Build action types, action creators, and reducer pairs with one simple function.
  • and more!

Core principles

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.

Getting started

yarn add robodux

Usage

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'] });

References

More Repositories

1

sentences

A multilingual command line sentence tokenizer in Golang
Go
435
star
2

neovimcraft

website that makes it easy to find neovim plugins
TypeScript
319
star
3

lists.sh

a microblog for lists
Go
227
star
4

cofx

A node and javascript library that helps developers describe side-effects as data in a declarative, flexible API.
TypeScript
94
star
5

starfx

A micro-mvc framework for react apps
TypeScript
85
star
6

nvim.sh

neovim plugin search from the terminal
Go
42
star
7

remix-middleware

express-like middleware system for your remix loaders and actions
TypeScript
36
star
8

mudicom

A python package that validates, reads, and extracts images from a DICOM file
Python
33
star
9

gen-readlines

Node.js generator-based line reader
TypeScript
25
star
10

lists-blog

the source for my blog at https://lists.sh
Makefile
23
star
11

use-cofx

declarative side-effects inside react with hooks
TypeScript
22
star
12

redux-cofx

declarative redux middleware for handling side-effects
TypeScript
12
star
13

language-csjs

CSJS syntax highlighter for Atom
CoffeeScript
12
star
14

gen-tester

Test generators with ease
JavaScript
10
star
15

deck-continuations

HTML
10
star
16

scopeify-html

Scope all CSS selectors in HTML
JavaScript
10
star
17

youhood

The neighborhood voting platform
TypeScript
9
star
18

code-nest

Indentation level of source code in popular javascript repositories on Github
JavaScript
8
star
19

react-cofx

Fetch data for a react component with a declarative side-effects library
TypeScript
7
star
20

postcss-scopeify-everything

Scopify all your CSS selectors
JavaScript
6
star
21

listifi

Create lists to share with everyone
TypeScript
6
star
22

electron-plugin-manager

Using atom-plugin-manager to install third-party plugins during runtime
JavaScript
5
star
23

redux-saga-creator

Create a fault-tolerant root saga from an object of sagas
TypeScript
5
star
24

starfx-examples

a modern approach to side-effect and state management for FE apps
TypeScript
4
star
25

redux-plugin

Something something plugins for react redux
JavaScript
3
star
26

redux-router-cofx

activate side-effects when location changes in connected-react-router
TypeScript
3
star
27

c-mysql-learning

MySQL C API, some C learnings
C
2
star
28

prose-blog

Makefile
2
star
29

redux-package-loader

Build packages for each react, redux feature
TypeScript
2
star
30

eslint-plugin-packages

Module boundary detection for local packages
JavaScript
2
star
31

redux-saga-ts

reference implementation of redux-saga using typescript
TypeScript
2
star
32

express-cofx-router

cofx router for express
TypeScript
2
star
33

generator-ts

yeoman generator for typescript libraries
JavaScript
2
star
34

redux-express-query

express-like middleware for your redux side-effects
TypeScript
1
star
35

tmp-expressjs-postgres

TypeScript
1
star
36

lint-workspaces

Linter for yarn workspaces
JavaScript
1
star
37

dcmdb-flask

dcmdb built using python, flask
Python
1
star
38

uss_api

United States of America State Information API
Python
1
star
39

dcmdb

DICOM Search Engine
JavaScript
1
star
40

vdom

playing around with my own vdom
TypeScript
1
star
41

homebrew-sentences

Tap for sentences cli
Ruby
1
star
42

sentdemo

Golang web application to demo sentence tokenization
JavaScript
1
star
43

olwizard.js

Get off my DOM!
JavaScript
1
star
44

postcss-scale-media-query

Scale media query `-width` by some percentage
JavaScript
1
star
45

neurosnap

1
star
46

async-flow-control

Demonstration of different asynchronous design patterns in javascript
HTML
1
star
47

ud_telegram_bot

Urban Dictionary Telegram Bot
JavaScript
1
star
48

rubot

idk my bff jill?
JavaScript
1
star
49

tmp-nextjs

JavaScript
1
star
50

dicom_codify

DICOM Standard 2014 Codified
Python
1
star
51

tslint-package-config

Some custom tslint rules
TypeScript
1
star