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

v2.0.0

Published

Middleware for Redux that turns promises into several dispatches of loading, success and error states, confirming to flux standard action schema.

Downloads

157

Readme

Redux loading promise middleware

Middleware for Redux that turns promises into several dispatches of loading, success and error states.

It is useful for getting asynchronous data (eg. API calls) into your redux store. Works well together with redux-actions and is inspired by redux-promise.

It is similar to FSA pattern but has some differences:

  • it dispatch async actions twice: when Promise is started and when promise is finished
  • it has isLoading param that can be checked if promise is finished
  • when Promise is rejected, error param

Installation

This package is distributed via npm.

npm install redux-loading-promise-middleware

Example usage

// store.js
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import promiseMiddleware from 'redux-loading-promise-middleware';
import reducer from './reducer';

const middlewares = compose(
	applyMiddleware(thunkMiddleware),
	applyMiddleware(promiseMiddleware)
);

return createStore(combineReducers({ reducer }), null, middlewares);
// reducer.js
const initialState = {
	todos: [],
	isLoading: false,
	error: null,
};

export default function todos(state = initialState, action) {
	switch (action.type) {
		case 'FETCH_TODOS': {
			return {
				isLoading: action.isLoading, // first time true, second time false
				error: action.error, // valule from rejected promise
				todos: Array.isArray(action.payload) ? action.payload : [], // null or result from successful promise
			};
		}

		default:
			return state;
	}
}
// action.js
export const fetchTodos = () => dispatch => dispatch({
	type: 'FETCH_TODOS',
	payload: fetch('/api/todos'),
});