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

redux-hmr-registry

v1.2.1

Published

Redux HMR & incremental loading registry

Downloads

39

Readme

ReduxHMRRegistry

Enable code splitting for redux

Installation

NPM:

$ npm install --save redux-hmr-registry

Yarn:

yarn add redux-hmr-registry

Import

In ES6: import { MiddlewareRegistry, ReducerRegistry, combineLazyReducers } from 'redux-hmr-registry'

Use with redux

Here an example to create store and enabling code splitting with redux:

import { applyMiddleware, compose, createStore } from 'redux'
import { MiddlewareRegistry, ReducerRegistry, combineLazyReducers } from 'redux-hmr-registry'

const reducers = {
  hello: (state = 'Hello World!') => state
}

const middlewareRegistry = new MiddlewareRegistry({
  middlewares: {
    myMiddleware: store => next => action => {
      /* ... */
    }
  }
})

const middlewares = [middlewareRegistry.createMiddleware()]

const store = createStore(
  combineLazyReducers(reducers),
  compose(applyMiddleware(...middlewares))
)

const reducerRegistry = new ReducerRegistry({
  reducers,
  registerListener: (dynamicReducers) => {
    store.replaceReducer(combineLazyReducers(dynamicReducers, store.getState()))
  }
})

Later in your code:

// For register to a new middleware
middlewareRegistry.register('dynamicMiddleware', dynamicMiddleware)
// For register to a new reducer
reducerRegistry.register('dynamicMiddleware', dynamicMiddleware)

API

combineLazyReducers (Function)

Combines reducers and returns a new reducer that must be passed to redux.

If you use connected-react-router you can pass reducer create by combineLazyReducers to connectRouter(history) ex: connectRouter(history)(combineLazyReducers(reducers))

Arguments:

  • reducers (Object): an object when each property is a reducer function
  • [initialState] (Object): usefull if you need to set initial state of reducer that not exist or has been removed.

MiddlewareRegistry (ES6 Class)

Enable code splitting for redux middlewares

Constructor:

  • [options={}] (Object):
    • [middlewares={}] (Object): a key/value object where key is name of middleware and value the middleware itself

Methods:

  • createMiddleware: returns a middleware to use with redux
  • register(name, middleware): adds name middleware
    • name (String): middleware name
    • middleware (Function): redux middleware
  • unregister(name): removes name middleware
    • name (String): middleware name

ReducerRegistry (ES6 Class)

Enable code splitting for redux reducers

Constructor:

  • [options={}] (Object):
    • [reducers={}] (Object): a key/value object where key is name of reducer and value the reducer itself
    • [registerListener] (Function): function called when register or unregister a reducer. Usefull to call store.replaceReducer(/*...*/) to dynamically replace redux reducer.

Methods:

  • register(name, reducer): adds name reducer
    • name (String): reducer name
    • reducer (Function): redux reducer
  • setRegisterListener(listener): set listener call on register and unregister
    • listener (Function): a function that takes registered reducers in first argument
  • unregister(name): removes name reducer
    • name (String): reducer name