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

@shotzoom/redux-reqres

v0.0.1

Published

Redux request/response middleware.

Downloads

4

Readme

Redux Reqres

Request response synchronization middleware. Syncronization should be used when multiple async actions may be dispatched to fetch data, but only the last response should be serviced such as type aheads and search filtering.

Installation

npm install @shotzoom/redux-reqres --save

Usage

To use, simply apply the middleware to your redux store and then dispatch the created request/response action creators.

import { createStore, applyMiddleware } from 'redux';
import { middlware } from '@shotzoom/redux-reqres';
import reducer from './reducer';

const store = createStore(
  reducer,
  applyMiddleware(middlware)
);

After the middleware has been applied, use the reqres action creators to dispatch syncronized request/response action pairs.

import { reqres } from '@shotzoom/redux-reqres';

const query = (term) => {
  const { request, response } = reqres('api/find');

  return (dispatch) => {
    dispatch(request({ type: 'FIND' }));
    fetch(`api/find?query=${term}`)
      .then((r) => r.json())
      .then((json) => {
        dispatch(response({ type: 'FIND_RECEIVE', results: json.results }));
      });
  };
};

store.dispatch(query('1'));
store.dispatch(query('2'));
store.dispatch(query('3'));
store.dispatch(query('4')); // only service this response.

The request and response action creators will wrap any action that is passed in and will only service the inner action when they meet the following criteria.

  1. Has not yet been dispatched.
  2. The request has not be invalidated by another request with the same key.
const first = reqres('some key unique to the action creator');
const second = reqres('some key unique to the action creator');

store.dispatch(first.request({ type: 'FIND' });
store.dispatch(first.request({ type: 'FIND' }); // will not service inner action again.
store.dispatch(second.request({ type: 'FIND' }); // will invalidate first request.
store.dispatch(first.response({ type: 'FIND_RECEIVE' })); // will not be serviced.
store.dispatch(second.response({ type: 'FIND_RECEIVE' })); // will be serviced.
store.dispatch(second.response({ type: 'FIND_RECEIVE' })); // has already been serviced.