From 7367f2277b9d1b2db2f4c919b393e2307a244841 Mon Sep 17 00:00:00 2001 From: Magic-Neko <312651922@qq.com> Date: Mon, 19 Feb 2024 11:12:13 +0800 Subject: [PATCH] =?UTF-8?q?[Issues:=20#I921X7]=20=E6=B7=BB=E5=8A=A0react-l?= =?UTF-8?q?ogger=E6=8C=87=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1224/redux-logger.md | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 1224/redux-logger.md diff --git a/1224/redux-logger.md b/1224/redux-logger.md new file mode 100644 index 000000000..7590abdc0 --- /dev/null +++ b/1224/redux-logger.md @@ -0,0 +1,121 @@ +> 模板版本:v0.1.3 + +

+

redux-logger

+

+

+ + License + +

+ +> [!tip] [Github 地址](https://github.com/LogRocket/redux-logger) + +## 安装与使用 + +#### **npm** +```bash +npm install redux-logger@^3.0.6 +``` + +typescript 项目需下载对应包的类型声明 +```bash +npm install @types/redux-logger +``` + +#### **yarn** + +```bash +yarn add redux-logger@^3.0.6 +``` + +typescript 项目需下载对应包的类型声明 +```bash +yarn add @types/redux-logger +``` + +下面的代码展示了这个库的基本使用场景: + +场景一: +```js +import { applyMiddleware, createStore } from 'redux'; +// Logger with default options +import logger from 'redux-logger' +const store = createStore( + reducer, + applyMiddleware(logger) +) + +``` + +场景二: +```js +import { applyMiddleware, createStore } from 'redux'; +import { createLogger } from 'redux-logger' + +const logger = createLogger({ + // ...options +}); + +const store = createStore( + reducer, + applyMiddleware(logger) +); +``` +## 约束与限制 + +### 兼容性 + +在下述版本验证通过: + 1. RNOH:0.72.11; + SDK:OpenHarmony(api11) 4.1.0.53; + IDE:DevEco Studio 4.1.3.412; + ROM:2.0.0.52; + 2. RNOH:0.72.13; + SDK:HarmonyOS NEXT Developer Preview1; + IDE:DevEco Studio 4.1.3.500; + ROM:2.0.0.58; + + +#### logger + +**API** + +| 名称 | 说明 | 类型 | 鸿蒙支持 | +| ---- | ---- | ---- | -------- | +logger | 默认日志记录 | Redux.Middleware | yes + +#### createLogger + +**API** + +| 名称 | 说明 | 类型 | 鸿蒙支持 | +| ---- | ---- | ---- | -------- | +createLogger | 自定义日志记录 | Redux.Middleware | yes + +**属性** + +| 名称 | 说明 | 类型 | 是否必填 | 鸿蒙支持 | +| ---- | ---- | ---- | -------- | -------- | +| predicate? | if specified this function will be called before each action is processed with this middleware | LoggerPredicate,undefined | NO | yes | +| collapsed | takes a Boolean or optionally a Function that receives `getState` function for accessing current store state and `action` object as parameters. Returns `true` if the log group should be collapsed, `false` otherwise | boolean,undefined | NO | yes | +| duration | print the duration of each action? | Attribute | NO | yes | +| timestamp | print the timestamp with each action?| boolean ,undefined | NO | yes | +| level | console's level | string , ActionToString , LevelObject , undefined | NO | yes | +| colors | colors for title, prev state, action and next stat | ColorsObject,false,undefined | NO | yes | +| titleFormatter | Format the title used when logging actions | string | NO | yes | +| stateTransformer | Transform state before print. Eg. convert Immutable object to plain JSON | any | NO | yes | +| actionTransformer | Transform action before print. Eg. convert Immutable object to plain JSON | any | NO | yes | +| errorTransformer | Transform error before print. Eg. convert Immutable object to plain JSON | any | NO | yes | +| logger | implementation of the `console` API | any | NO | yes | +| logErrors | should the logger catch, log, and re-throw errors? | boolean,undefined | NO | yes | +| diff | (alpha) show diff between states? | boolean,undefined | NO | yes | +| diffPredicate | (alpha) filter function for showing states diff, similar to `predicate` | LoggerPredicate ,undefined| NO | yes | + +## 遗留问题 + +## 其他 + +## 开源协议 + +本项目基于 [The MIT License (MIT)](https://github.com/LogRocket/redux-logger/blob/master/LICENSE) ,请自由地享受和参与开源。 \ No newline at end of file -- Gitee