@aics/redux-utils

中文文档
0.6.0发布于 2021/12/17MITTypeScriptESM + CJS零依赖近 30 天下载 3593

Utilities for working with Redux. There are others out there--this is ours.

原始使用文档

@aics/redux-utils

This package extracts state management and testing utilities from cookiecutter-react-redux and elsewhere.

All functions, classes, and interfaces are exported from the top level of this package. There is no default export. For example:

import { configureMockStore, ResponseStub, makeReducer } from "@aics/redux-utils";

Examples:

  1. Test that a redux-logic logic responds to an action, makes an HTTP request, and dispatches another action with the result of that HTTP request. Provide a mock value for the response of the HTTP request.
import { configureMockStore } from "@aics/redux-utils";
import { expect } from "chai";

describe("configureMockStore", () => {
    interface State {
        foo: string;
        bar: number;
    }

    const initialState = {
        foo: "hello",
        bar: 123,
    };

    const simpleReducer: Reducer = (state = initialState, action) => {
        if (action.payload) {
            return {
                ...state,
                ...action.payload,
            };
        }

        return state;
    };

    const logic = createLogic({
        type: "TEST1",
        process: async (deps, dispatch, done) {
            const response = await deps.httpClient.get("/api/1.0/foo/bar");
            dispatch({ type: "TEST3", payload: response.data });
            done();
        },
    });

    const responseStub = {
        when: "/api/1.0/foo/bar",
        respondWith: { data: "Hello from the endpoint" },
    };

    // DON'T MISS THE ASYNC!
    it("creates a mock Redux store with some helpful defaults and utilies", async () => {
        const { store, actions, logicMiddleware } = configureMockStore<State>({
            state: initialState,
            reducer: simpleReducer,
            responseStubs: [responseStub]
            logics: [logic],
        });

        store.dispatch({ type: "TEST1" });

        // AFTER THIS POINT, ALL LOGICS HAVE FINISHED RUNNING
        await logicMiddleware.whenComplete();

        expect(actions.includes({ type: "TEST1" })).to.be.true;

        // dispatched by logic
        expect(actions.includes({ type: "TEST3", payload: "Hello from the endpoint" })).to.be.true;
    });
});

Exports

actions

  • Functions:

    • [[batchActions]]
    • [[enableBatching]]
  • Interfaces:

    • [[BatchedAction]]

ActionTracker

  • Classes:

    • [[ActionTracker]]
  • Interfaces:

    • [[Actions]]

constants

  • Functions:
    • [[makeConstant]]

mock-http-client

  • Functions

    • [[createMockHttpClient]]
  • Interfaces

    • [[ResponseStub]]

mock-store

  • Functions

    • [[configureMockStore]]
  • Interfaces

    • [[ConfigureMockStoreConfig]]

reducers

  • Functions

    • [[makeReducer]]
  • Interfaces

    • [[ActionHandler]]
    • [[ActionTypeToHandlerMap]]

state

  • Functions
    • [[mergeState]]

store

  • Functions

    • [[configureStore]]
  • Constants

    • [[defaultReduxLogicDeps]]
  • Interfaces:

    • [[ConfigureStoreConfig]]
    • [[ReduxLogicDependencies]]

版本与发布记录

@aics/redux-utils 共发布 13 个版本,首次发布于 2019/12/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.0latest2021/12/174 年前
0.6.0-12021/12/114 年前
0.6.0-02021/12/114 年前
0.5.02020/09/196 年前
0.5.0-22020/09/186 年前
0.5.0-12020/09/186 年前

关于 @aics/redux-utils 的常见问题

@aics/redux-utils 是什么?

Utilities for working with Redux. There are others out there--this is ours.

如何安装 @aics/redux-utils?

在项目目录运行 npm install @aics/redux-utils,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:axios(0.x)、redux(4.x)、lodash(4.x)、redux-logic(3.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aics/redux-utils 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aics/redux-utils 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@aics/redux-utils 可以商用吗?

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

@aics/redux-utils 的下载量有多少?

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

@aics/redux-utils 还在维护吗?

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