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

react-state-pro

v1.1.7

Published

简单好用,强大的各种redux工具替代品

Downloads

30

Readme

react-state-pro

Usage

安装

npm install react-state-pro --save

运行 example

cd react-state-pro && npm install
cd react-state-pro/example && npm install
npm install global-create-react
npm start

编写store配置

config['state1'] = export default {
    state: {// 目前支持state必须是一个对象,不支持重新赋值
        count: 0,
        urlParam: null,
    },
    mutations:{
        add(state, data) {
            state.count = data;
        },
        changeUrlParam(state, data) {
            state.urlParam = data;
        }
    },
    actions: {
        async add({commit, store}, {count}) {
            setTimeout(function () {
                commit('add', store.count + count);
            }, 1000);
        },
        async changeUrlParam({commit}, {data}) {
            setTimeout(() => {
                commit('changeUrlParam', data)
            }, 2000);
        } 
    },
}
export default config;

生成store, 然后传入store, 生成Provider, connect

// 文件: createStore.js 
import { createProviderAndConnect, createStore } from '../../src/index';
import stateConfig from './modules';
const state = createStore(stateConfig);
const context = createProviderAndConnect(state);
const Provider = context.Provider;
const connect = context.connect;
export {Provider, connect};

首页,以及子组件配置

首页

import { Provider } from './createStore';
ReactDOM.render(
    <Provider>
        <Router history={history}>
            <Switch>
                <Route path="/app/:count" component={App} />
                <Redirect to="/app" />
            </Switch>
        </Router>
    </Provider>,
document.getElementById('app'));

子组件

import { connect } from './createStore';
export default connect(() => {
    // 类似react-redux的mapStateToProps
})(Component)

API

createProviderAndConnect

用来生成Provider,以及connect

createStore

用来生成state

autoActions

组件默认发起的action,只有action调用commit之后,组件才会被渲染

requireProps

组件默认的必选参数,参数也可以来自state,当参数不满足要求的时候,会显示tyepError的值

startRequest

当有默认的autoAction, 请求过程中显示的元素

typeError

当必选参数不满足要求的时候,显示的元素

waitRequest

当autoActions有很多个的时候,告诉你目前有那些action正在请求

state API

state

默认值,必须是一个对象

actions

所有的异步操作

mutations

所有的同步操作,state只有在这里面才会被改变

dispatch

异步操作触发器

commit

通过操作触发器,只有在dispatch里面可用