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

redux-store-provider

v2.1.0

Published

redux store provider

Readme

ReduxStoreProvider

npm Github file size npm

这个库是为了简化 redux 创建 Action 和 Reducer 的过程,使创建过程语义化,提升应用自明性方便后期维护。

本库把 Store 数据简化分为 单一型列表型,单一型就是一个 Object,对象上边的属性由开发者所定义。列表型就是一个 Array,但是它也包含单一型的数据类型,两者在列表型时可以同时使用,默认扩展了 total 字段,来记录列表总条数,如果开发者有需要还可以自定义更多属性。

安装

npm install redux-store-provider --save

手册

import Redux from 'redux';
import ReduxStoreProvider from 'redux-store-provider';


const UserStore = new ReduxStoreProvider({ key: 'USER' })
  .begin('set_name')
  // 定义 Action 触发 Reducer
  .action((type, name) => {
    return {
      type,
      name,
    };
  })
  // 定义 Reducer 执行设置用户名的逻辑
  .reducer((type, state, action) => {
    const newState = {...state};
    // 设置用户名
    newState.name = action.name;

    return newState;
  })
  .end()

  .begin('set_other')
  .action(...)
  .reducer(...)
  .end();

const store = Redux.createStore(
  Redux.combineReducers({
    userStore: UserStore.getReducer()
  })
);

// 进行设置操作
store.dispatch(UserStore.getAction().set_name('Sanonz'));

成员

static type(name) ⇒ string

生成一个在 Action 中使用的 type 字符串

| Param | Type | Description | | --- | --- | --- | | name | string | name value |

static config(options) ⇒ this

全局配置,设置后将会覆盖默认设置并且在全局生效

| Param | Type | Description | | --- | --- | --- | | [options] | Object | 数据 | | options.initialState | Object | 单一型配置 | | options.initialStateList | Object | 列表型配置 |

// 单一型 Store 配置
ReduxStoreProvider.config({
  initialState: {
    value: {}
  }
});

// 列表型 Store 配置
ReduxStoreProvider.config({
  initialState: {
    list: [],
    total: 0,
    value: {}
  }
});

static ReduxStoreProvider.getInitialState() ⇒ Object

获取单一型全局默认 Store 值

static ReduxStoreProvider.getInitialStateList() ⇒ Object

获取列表型全局默认 Store 值

new ReduxStoreProvider()

初始化一个 Store 值

| Param | Type | Default | Description | | --- | --- | --- | --- | | [options] | Object | {} | 数据 | | options.key | string | 自动生成 | 初始化 Store 的 KEY,必须具有单一性 | | options.type | string | single | single 单一型,list 列表型 | | options.initialState | Object | | 初始化 Store,将会覆盖全局默认设置 |

const UserStore = new ReduxStoreProvider({ key: 'USER' });

ReduxStoreProvider.setInitialState(value) ⇒ this

覆盖默认 Store,仅在当前 Store 生效

| Param | Type | Description | | --- | --- | --- | | value | Object | 数据 |

ReduxStoreProvider.getInitialState() ⇒ Object

获取当前 Store 的值

UserStore.getInitialState();
// 返回值
// {
//   name: 'Sanonz',
//   email: '[email protected]'
//   ...
// }

ReduxStoreProvider.begin(name) ⇒ this

开始定义扩展会话,支持链式操作,例如:instance.begin('like').action(fun).reducer(fun).end()

| Param | Type | Description | | --- | --- | --- | | name | string | 扩展方法名 |

ReduxStoreProvider.action(handler) ⇒ this

在当前会话定义一个 Action,可以触发 Reducer

| Param | Type | Description | | --- | --- | --- | | handler | function | 扩展方法 |

ReduxStoreProvider.reducer(handler) ⇒ this

在当前会话定义一个 Reducer,可以在 Action 中触发

| Param | Type | Description | | --- | --- | --- | | handler | function | 扩展方法 |

ReduxStoreProvider.end() ⇒ this

关闭定义扩展会话

ReduxStoreProvider.getAction() ⇒ Object

获取当前 Store 的 Action,包括默认和自定义

默认的 Action 列表

  • action.set(path, value)
  • action.merge(value)

列表型同时包含一下方法

  • action.fill(value, total)
  • action.shift()
  • action.unshift(value)
  • action.pop()
  • action.push(value)
  • action.insert(index, value)
  • action.replace(index, value)
  • action.remove(index)

ReduxStoreProvider.getReducer() ⇒ function

获取当前 Store 的 Reducer,包括默认和自定义

例子

查看博客:使用 redux-store-provider 简化 react 开发流程