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 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-request-async-middleware

v2.3.2

Published

With this package, you can use react-redux without action, actionType, reducer, etc.

Readme

redux-request-async-middleware

With this package, you can use react-redux without action, actionType, reducer, etc.

Install

npm i redux-request-async-middleware

or

yarn add redux-request-async-middleware

propertys

| Property | Description | | -------- | ----------- | | requests | this is a reducer | | reduxRequest | correct middleware | | initReduxRequest | init function, initReduxRequest(store), it's required | | request | request(subject, model, next), next is a optional param, model must be a Promise | | clear | clear(subject), you can clear this subject in the store |

Usage

Provider

import React from 'react';
import {createStore, applyMiddleware, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import {initReduxRequest, reduxRequest, requests} from 'redux-request-async-middleware';

export default class extends React.Component {
    render() {
        const rootReducer = combineReducers({requests}); // you can add other reducers
        const store = createStore(rootReducer, applyMiddleware(reduxRequest));
        initReduxRequest(store); // to make sure that request can get the store.dispatch function, so it is important 
        return <Provider store={store}>{this.props.children}</Provider>
    }
}

model

import fetch from '../../libs/http/fetch';
//fetch is your own warpped Promise,you can handle request and response inside
//you can also ues xhr, but it must be a warpped Promise

export default class model {
    static yourModel1(param) {
        return fetch('/api/yourModel1', {body: {param}, method: 'POST'});
    }
}

subject

export const subject = {
    yourSubject1: 'yourSubject1',
    yourSubject1: 'yourSubject2',
    yourSubject1: 'yourSubject3',
}

Component

import React from 'react';
import model from './model';
import { connect } from "react-redux";
import { subject } from './subject';
import { request, clear, reduxUtils } from 'redux-request-async-middleware';

@connect(state => {
    let yourSubject1State = state.requests[subject.yourSubject1];
    let yourSubject2State = state.requests[subject.yourSubject2];
    let yourSubject3State = state.requests[subject.yourSubject3];
    let loading = reduxUtils.getLoading([yourSubject1State, yourSubject2State, yourSubject3State]);
    //there you can get the loading state
    let yourSubject1 = reduxUtils.getResponse(yourSubject1State);
    let yourSubject2 = reduxUtils.getResponse(yourSubject2State);
    let yourSubject3 = reduxUtils.getResponse(yourSubject3State);
    //if you add the subject in following select, you can handle data here
    //you can add the subject in other component select to realize cross-page operation
    return { loading, yourSubject1, yourSubject2, yourSubject3 };
})
export default class YourComponent extends React.Component {
    componentDidMount() {
        request(subject.yourSubject1, () => model.yourModel1(param));
        //request base usage
        
        const next = res => yourNext()
        request(subject.yourSubject2, () => model.yourModel2(param), next);
        //with this, you can get the callback
    }
    
    componentWillUnmount() {
        clear(subject.yourSubject1);
        // you can clear the subject in redux store
    }
    
    render() {
        let { loading, yourSubject1, yourSubject2, yourSubject3 } = this.props;
        return(
            <OtherComponent 
                data1={yourSubject1} 
                data2={yourSubject2} 
                data3={yourSubject3} 
                loading={loading} 
            />
        )
    }
}