Redux Unhandled Action 项目教程

Redux Unhandled Action 项目教程

redux-unhandled-actionRedux middleware that logs an error to the console when an action is fired and the state is not mutated, 项目地址:https://gitcode.com/gh_mirrors/re/redux-unhandled-action

1、项目的目录结构及介绍

redux-unhandled-action/
├── src/
│   ├── index.js
│   └── ...
├── test/
│   ├── index.test.js
│   └── ...
├── .gitignore
├── .npmignore
├── LICENSE.txt
├── README.md
├── package-lock.json
├── package.json
  • src/:包含项目的源代码,其中 index.js 是入口文件。
  • test/:包含项目的测试代码,其中 index.test.js 是测试入口文件。
  • .gitignore:指定 Git 版本控制系统忽略的文件和目录。
  • .npmignore:指定 npm 发布时忽略的文件和目录。
  • LICENSE.txt:项目的许可证文件。
  • README.md:项目的说明文档。
  • package-lock.json:锁定项目依赖的版本。
  • package.json:项目的配置文件,包含依赖、脚本等信息。

2、项目的启动文件介绍

项目的启动文件位于 src/index.js,该文件主要负责导出 Redux 中间件 reduxUnhandledAction。以下是文件的主要内容:

import { createStore, applyMiddleware } from "redux";
import reduxUnhandledAction from "redux-unhandled-action";
import reducer from "./reducer";

// 自定义回调处理未被处理的action
const callback = (action) => console.error(`${action.type} 没有导致新的状态对象创建`);

const store = createStore(reducer, applyMiddleware(reduxUnhandledAction(callback)));

该文件通过 applyMiddlewarereduxUnhandledAction 中间件应用到 Redux 的 store 中,并提供了一个可选的回调函数来处理未被处理的 action。

3、项目的配置文件介绍

项目的配置文件主要是 package.json,该文件包含了项目的基本信息、依赖、脚本等配置。以下是文件的主要内容:

{
  "name": "redux-unhandled-action",
  "version": "1.0.0",
  "description": "A simple redux middleware that will log an error to the console if the state returned from a dispatch is equal to the state before the dispatch",
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "redux",
    "middleware",
    "unhandled",
    "action"
  ],
  "author": "Social Tables Inc",
  "license": "Apache-2.0",
  "dependencies": {
    "redux": "^4.0.5"
  },
  "devDependencies": {
    "jest": "^26.0.1"
  }
}
  • name:项目的名称。
  • version:项目的版本号。
  • description:项目的描述。
  • main:项目的入口文件。
  • scripts:项目的脚本命令。
  • keywords:项目的关键词。
  • author:项目的作者。
  • license:项目的许可证。
  • dependencies:项目的依赖包。
  • devDependencies:项目的开发依赖包。

通过以上配置文件,可以快速了解项目的依赖关系和基本信息,方便进行开发和维护。

redux-unhandled-actionRedux middleware that logs an error to the console when an action is fired and the state is not mutated, 项目地址:https://gitcode.com/gh_mirrors/re/redux-unhandled-action

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虞熠蝶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值