npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

robodux

v15.0.2

Published

caching in redux made simple

Downloads

1,162

Readme

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