npm 包 redux-metric 使用教程

阅读时长 4 分钟读完

简介

redux-metric 是一个可重用的 Redux 中间件,用于在应用程序中跟踪性能指标和错误。

安装

使用 npm 安装:

使用方法

  1. 引入 redux-metric
  1. 使用 metricMiddleware 装在你的应用程序
  1. 在 redux 的 action 中使用 metric
-- -------------------- ---- -------
------ ----- ------------------- - -- -- ----- -------- -- -
  ----- ------ - - ----- ------ ---- ------ ---------- --- ---------------- --

  --- -
    ----- ---- - ----- ----------------

    -- ---
    ---------- ----- ------------------------ -------- ---- ---

    -------------- - --- -----------------
    ----------------- -----

  - ----- ------- -
    -- ---
    ---------- ----- ------------------------ -------- ----- ---

    -------------- - --- -----------------
    -------------- - -----
    ------------------- - --------------
  -

  -----------------
--
展开代码

参数

metric 对象包含以下参数:

参数 类型 说明
name String 跟踪事件的名称
startTime Number 事件开始时间(毫秒)
endTime Number 事件结束时间(毫秒)
isSuccess Boolean 事件是否成功
isError Boolean 事件是否发生错误
errorMessage String 错误消息

示例代码

-- -------------------- ---- -------
------ ------ - --------- - ---- --------
------ - ------- - ---- --------------
------ - ------------------- - ---- ------------

----- --- ------- --------- -
  ------------------- -
    ---------------------------
  -

  -------- -
    ------ -
      -----
        --------------------- -- ------------------
        ------------------- -- ---------------------------------
        ---------------- -- ------------------------------
      ------
    --
  -
-

----- --------------- - ----- -- --
  ---------- ----------------
  -------- --------------
  ------------- -------------------
  ----- -----------
---

----- ------------------ - -
  -------------- --------------------
--

------ ------- ------------------------ -------------------------
展开代码

结论

redux-metric 可以帮助你跟踪性能指标和错误,并且可以重用在其他 Redux 应用程序中。它可以帮助你优化应用程序的性能,提升用户体验。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60067008e361a36e0bce8b1e

纠错
反馈

纠错反馈