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

reedux

v0.1.3

Published

A really simple approach to managing Redux store paths and reducers

Downloads

96

Readme

Reedux

As applications grow, there's the idea to move away from one large combined reducer, and break down code into modules that depend on a store export

npm downloads Build Status License: MIT dependencies Status devDependencies Status peerDependencies Status

This is another implementation of Dynamic Reducers Loading. Chances are you already built one yourself. Other people did. If you did too, you are not alone

This library is:

  • arguably the simplest solution
  • can be added late into a project at zero cost
  • requires no modifications to the existing project
  • can cope with heavy tooling (think async middlewares)
  • compatible with all of the official dev tools
  • will not change the behavior of Redux in any way
  • declarative, easy to use - the same syntax that you're familiar with
  • supports and promotes ducks-modular-redux / re-ducks
  • supports adding reducers by type - you can specify the action type as the first parameter when registering new reducers
  • supports HMR without storing extra information on the store
  • supports server-side rendering with preloaded state
  • does one thing, and one thing only
  • no runtime dependencies
  • small footprint, under 100 lines of code
  • fully tested
  • licensed under MIT, completely free to use

There is a peer dependency of Redux 3 and above, and a soft dependency on WeakMaps. Most projects already have support for it via babel-polyfill but if yours doesn't, here is an excellent polyfill

API

reedux(object store, [function existingReducer])
  • the default export in the lib
  • store is the store to be managed
  • existingReducer should be supplied if the given store already has a reducer
  • returns a storePath() function for the given store

storePath(string name, any initialState)
  • registers a new store path in your current store
  • the store path will be populated with initialState at the end of the call
  • returns reducer() function for the given store path

reducer([string type], function reducer)
  • registers a reducer

Example

Suppose you already have store.js exporting a Redux store:

// import it
import { createStore } from 'redux'; 

// get your store
const store = createStore(s => s);
export default store;

All you have to do now is write someModule.js

// use it on top of your store
import reedux from 'reedux';
import store from './store.js';

const storePath = reedux(store);
const reducer = storePath('customers', []);

// now you can add a reducer
reducer((customers, action) => {
  switch(action.type) {
    case 'addCustomer':
      return [...customers, action.customerData];
    case 'deleteCustomer': 
      return [...customers.filter(customer => customer.id !== action.customerId)];
    default:
      return customers;
  }
});

Alternative syntax

reducer('addCustomer', (customers, action) => 
  ([...customers, action.customerData]));

reducer('deleteCustomer', (customers, action) => 
  ([...customers.filter(customer => customer !== action.customerId)]));

Limitations

  • Deleting reducers or store paths is not supported

Similar efforts