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

actiontypemiddleware

v1.0.1

Published

Middleware for watching actions that pass through the store and subscribing to them

Downloads

8

Readme

actiontypemiddleware

This middleware allows you to subscribe to a redux-store on a case-by-case basis depending on what type of action has been called. It's super easy to use and is useful for various scenarios including unit testing

Installation

npm install ---save-dev actiontypemiddleware

Properties

middleware

(function) the main middleware function

subscriptions

(object) the list of subscriptions to the middleware

Methods

subscribe(name, type, callback)

name: (string) the name of the subscription. Multiple action types can be subscribed under the same name.

type: (string) the redux action type.

callback: (function) the callback function invoked whenever the subscribed action is dispatched to the store. The callback accepts an object of the following structure: {timestamp: date in milliseconds, action: dispatched action}

unsubscribe(name)

name: (string) the name of the subscription to remove.

unsubscribeAction(name, type)

name: (string) the name of the subscription.

type: (string) the specific action type to unsubscribe from under this name. If there is only one action subscribed under this name then it will remove the entire subscription

Usage

The following usage assumes you are familiar with redux actions and redux stores. For further information please refer to this excellent documentation.

The middleware works on a subscription based model, meaning you can turn it on and off at will.

import ACTIONTYPEM from 'actiontypemiddleware'
import { createStore, applyMiddleware } from 'redux'
import reducers from './reducers'

/* import this object wherever it's needed and turn it on and off to listen for actions */
export const signOutButton = {
    on() {
        ACTIONTYPEM.subscribe('signout', 'USER_SIGN_OUT', signOutButton.listener)
    },
    off() {
        ACTIONTYPEM.unsubscribe('signout')
    },
    listner({timestamp, action}){
        console.log(`someone signed out at: ${timestamp}`)
        console.log('the action data is', action)
    }
}

export default createStore(reducers, applyMiddleware(ACTIONTYPEM.middleware))