@exodus/modular-redux

中文文档
1.1.3发布于 2026/10/14MITCommonJS近 30 天下载 1.1万

Exodus modular Redux enhancer

原始使用文档
文档目录11 节
  1. Table of Contents
  2. Overview
  3. Installation
  4. Quick start
  5. Dependencies
  6. Enhanced Store API
  7. store.injectReducer(name, reducer)
  8. Utils API
  9. bindActionCreators(store, actions, deps, onError)
  10. bindHooks(store, hooks, deps)
  11. bindSelectors(store, selectors)

@exodus/modular-redux

Table of Contents

Overview

Redux Store enhancer to support building modular features on top of Redux.

With Modular Redux, each Redux module is responsible for registering itself with the store rather than the other way around. This means not having to export a reducer function (keeping these Redux-specific concepts hidden). This also enables each module to work with more than one "slice" of the state.

Installation

pnpm add @exodus/modular-redux

Quick start

import modularRedux from '@exodus/modular-redux'
import { createStore, applyMiddleware } from 'redux'

const initialState = {}

const middleware = [
  /* ... middlewares */
]

const enhancers = compose(modularRedux, applyMiddleware(...middleware))

const store = createStore(reducers, initialState, enhancers)

Dependencies

Redux modules relies on injecting dependencies for all those things that are out of your module's scope. For example, if a specific module requires geolocation data, it might be wiser to pass this as a module dependency instead of dealign with it internally. Specially if the way it works depends on the target application (the way we get geolocation in mobile might be different than in desktop). This way, we can start building small, testable and composable modules we can reuse throughout features.

Enhanced Store API

store.injectReducer(name, reducer)

Registers a new Redux state slice.

Arguments

NameDescription
nameName of Redux slice. This will be used as state key in the global Redux state
reducerReducer function that dictates how the register slice state mutates

Utils API

Util functions exported from @exodus/modular-redux to bind different pieces of logic to Redux store

bindActionCreators(store, actions, deps, onError)

Wrapper around redux.bindActionCreators to bind action creators to the store and module dependencies

Arguments

NameDescription
storeRedux store
actionsModule action creators object, each with the form of (deps) => action
depsModule dependencies. See Dependencies for mode details.
onErrorError handling function. Called everytime something goes wrong on some action. Optional

Returns

Bound actions object you can return from your module and call directly to dispatch events

bindHooks(store, hooks, deps)

Bind functions to state changes.

Arguments

NameDescription
storeRedux store
hooksHooks definition object in the form of { email: [emailSelector, hookFn] }
depsModule dependencies. See Dependencies for mode details.

bindSelectors(store, selectors)

Transform selector functions into a declarative API to read data out of the Redux slice.

This is an experimental API. Selectors should be still exported from each module for compatibility reasons and other selector composability

Arguments

NameDescription
storeRedux store
selectorsModule selectors functions object. Ex. { getBalaceSelector: (state) => state.balance }

Returns

Selectors API. Each selector entry on the provided object is returned as a getter function. Ex. { getBalaceSelector: (state) => state.balance } -> { getBalace: () => balance }

版本与发布记录

@exodus/modular-redux 共发布 8 个版本,首次发布于 2021/10/20;过去 12 个月发布了 1 个版本。

版本发布日期距今
1.1.3latest2026/10/141 个月前
1.1.22025/05/131.5 年前
1.1.12024/11/252 年前
1.1.02021/11/304 年前
1.0.02021/10/215 年前
1.0.0-rc3beta2021/10/215 年前

关于 @exodus/modular-redux 的常见问题

@exodus/modular-redux 是什么?

Exodus modular Redux enhancer

如何安装 @exodus/modular-redux?

在项目目录运行 npm install @exodus/modular-redux,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:redux(*)、redux-watch(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@exodus/modular-redux 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/exodus__modular-redux 是否存在。

@exodus/modular-redux 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@exodus/modular-redux 可以商用吗?

@exodus/modular-redux 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/modular-redux 的下载量有多少?

根据 npm 官方下载统计,@exodus/modular-redux 在 2026/10/14 – 2026/11/12 这 30 天内被下载 10,925 次,日均约 364 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/modular-redux 还在维护吗?

最新版本 1.1.3 发布于 2026/10/14(1 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 1 个;首次发布于 2021/10/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。