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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@suddenly/flux

v1.9.1

Published

An implementation of Flux similar to Redux

Readme

@suddenly/flux

A simple implementation of Flux that is loosely based on Redux.

Usage

Actions

You can pass actions directly or return a function that will dispatch actions asynchronously.

When using a function you get dispatch and getState functions as arguments.

const ItemActions = {
  LOADING_ITEMS: "LOADING_ITEMS",
  LOADED_ITEMS: "LAODED_ITEMS",

  loadedItems(items) {
    // Return a literal action to dispatch it
    return { type: ItemActions.LOADED_ITEMS, payload: items };
  }

  loadItems() {
    // Return a function to defer dispatching actions
    return (dispatch, getState) => {
      // getState() returns the current base state
      if (getState().getIn(["Items", "isLoading"])) return;

      dispatch({ type: ItemActions.LOADING_ITEMS });

      fetch("/items").then(items => {
        // You can dispatch other actions
        dispatch(ItemActions.loadedItems(items));
      });
    }
  }
}

Reducers

Reducers work similar to Redux but utilise Immutable.js by default.

import { createState, createReducer } from "@suddenly/flux";
import ItemActions from "../actions/ItemActions";

// createState is a convenience wrapper for Immutable.fromJS()
const initialState = createState({
  isLoading: false,
  all: []
});

export default createReducer(initialState, {
  [ItemActions.LOADING_ITEMS](state, action) {
    return state.set("isLoading", true);
  },

  [ItemActions.LOADED_ITEMS](state, action) {
    return state.merge({
      isLoading: false,
      all: createState(action.payload)
    });
  }
});

You can also pass an optional sideEffect function as the third argument to createReducer that will be called (passing the updated state) once all reducer functions are called.

And then you might combine your reducers:

import { combineReducers } from "@suddenly/flux";

import Items from "./ItemReducer";
import Other from "./OtherReducer";

export default combineReducer({
  Items,
  Other
});

This will create a tree structure with each reducer managing the state under the same key in the store.

In this example, the store would look something like:

{
  Items: {
    isLoading: false,
    all: []
  },
  Other: {
    ...
  }
}

You can also pass a sideEffect function as the second argument to combineReducers. This function will be called with the updated state once all reducers are run.

You can then use this new reducer as context state in a Provider.

Context

First, create a store:

import { Store, createState } from "@suddenly/flux";
import reducer from "./reducers";

const initialState = createState({
  ...
});

export new Store(initialState, reducer);

Then create a Provider at the top level of your app to provide state.

For example, in your App.tsx:

import { Provider } from "@suddenly/flux";
import store from "../store";

export default (props: Props) => {
  return <Provider store={store}>...</Provider>;
};

And now you have a choice of how you want to consume the context - hooks or HOCs.

Hooks

You can use useSelector and useDispatch to hook into the state and actions of the provider.

import { useSelector, useDispatch } from "@suddenly/flux";
import ItemActions from "../actions/ItemActions";

export default () => {
  // Note: this can be simplified further but is meant to be a
  // comparison to the HOC example down futher
  const { items } = useSelector(state => ({
    items: state.getIn(["Items", "all"])
  }));

  const dispatch = useDispatch();

  return (
    <div>
      {items.map(item => {
        return (
          <div>
            {item.get("label")}
            <button onClick={e => dispatch(ItemActions.actionItem(item))}>Action</button>
          </div>
        );
      })}
    </div>
  );
};

HOCs

You can use connect to create a HOC that maps state and dispatch calls into the wrapped component.

import { connect } from "@suddenly/flux";
import ItemActions from "../actions/ItemActions";

interface Props {
  //...
}

export const ItemList = (props: Props) {
  return (
    <div>
      {props.items.map(item => {
        return (
          <div>
            {item.get("label")}
            <button onClick={e => props.actionItem(item)}>Action</button>
          </div>
        )
      })}
    </div>
  );
}

function mapStateToProps (state, ownProps) {
  return {
    items: state.getIn(['Items', 'all'])
  };
}

function mapDispatchToProps (dispatch, ownProps) {
  return {
    actionItem(item) {
      dispatch(ItemActions.actionItem(item));
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(ItemList);

Contributors