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-middleware

v0.1.21

Published

Set of logical Redux middleware.

Downloads

1,005

Readme

redux-middleware

common redux middleware

NPM

NPM

Disclaimer: This library is in early development alongside redux-addons. It will be changing rapidly and is not ready for production use.

npm i -S redux-middleware

Will install middlewares to:

ES5 => 'redux-middleware/lib'

ES6+ => 'redux-middleware/src/lib'

Usage

configureStore.js
import { createStore } from 'redux'
import { applyLogicalMiddleware } from 'redux-middleware'
import rootReducer from '../reducers'

const createStore = applyLogicalMiddleware()(createStore)

export default function configureStore() {
  return createStore(rootReducer, initialState)
}
middleware.js
import { applyMiddleware } from 'redux'

import metaRouter from 'redux-middleware/lib/metaRouter'
import thunk from 'redux-middleware/lib/thunk'
import readyStatePromise from 'redux-middleware/lib/readyStatePromise'
import logger from 'redux-middleware/lib/logger'
import crashReporter from 'redux-middleware/lib/crashReporter'


/** Default array of useful redux middleware */
export default function middleware() {
  return  [ metaRouter
          , thunk
          , readyStatePromise
          , logger
          , crashReporter
          ]
}

export const applyLogicalMiddleware = () => applyMiddleware(...middleware())
metaRouter.js (Needs work)
import timeoutScheduler from './timeoutScheduler'
import identityHandler from './identityHandler'
import apiDispatcher from './apiDispatcher'
import routeHandler from './routeHandler'
import idleMiddleware from './idleMiddleware'
import errorHandler from './errorHandler'

/**
 * Lets you dispatch special actions with a { meta } field.
 *
 * This middleware will chain through all middleware specified in metaMap in
 * order and return the result.
 */
export const createMetaRouter = (metaMap = new Map( [ [ 'delay', timeoutScheduler ]
                                                    , [ 'identity', identityHandler ]
                                                    , [ 'api', apiDispatcher ]
                                                    , [ 'route', routeHandler ]
                                                    , [ 'idle', idleMiddleware ]
                                                    , [ 'err', errorHandler ]
                                                    ] )) => store => next => action => {
  if(!action.meta)
    return next(action)
  const supportedTypes = metaMap.keys()
  const metaTypes = Object.keys(action.meta)
  let result = metaTypes.filter(x => supportedTypes.includes(x))
                        .map(x => metaMap.get(x))
                        .reduce((last, middleware) => middleware(last), action)
  return next(result)
}

export default createMetaRouter()