@discourse/backburner.js

中文文档
2.7.1-0发布于 2022/10/12MITTypeScriptCommonJS零依赖近 30 天下载 5142

A fork of backburner.js

原始使用文档
文档目录6 节
  1. TL;DR
  2. API
  3. Constructor
  4. Instance methods
  5. Example usage
  6. Benchmarks

backburner.js Build Status

A rewrite of the Ember.js run loop as a generic microlibrary.

TL;DR

A priority queue that will efficiently batch, order, reorder and process work; done via scheduling work on specific queues.

API

Constructor

ConstructorDescription
new Backburner()instantiate a Backburner instance with an array of queue names

Instance methods

MethodDescription
Backburner#runexecute the passed function and flush any deferred actions
Backburner#deferdefer the passed function to run inside the specified queue
Backburner#deferOncedefer the passed function to run inside the specified queue, only execute it once
Backburner#setTimeoutexecute the passed function in a specified amount of time
Backburner#debounceexecute the passed function in a specified amount of time, reset timer upon additional calls
Backburner#throttlerate-limit the passed function for a specified amount of time
Backburner#cancelcancel a deferOnce, setTimeout, debounce or throttle
Backburner#onAdd an event callback. Supports the following events:
  • begin - Fires whenever the runloop begins. Callbacks are passed the current instance and the previous instance.
  • end - Fires whenever the runloop ends. Callbacks are passed the current instance and the next instance.
Backburner#offRemoves an event callback
Backburner#joinJoin the passed method with an existing queue and execute immediately, if there isn't one use Backburner#run
Backburner#getDebugInfoReturns debug information for counters, timers and queues, which includes surfacing the stack trace information for the respective calls

Alias

AliasDescription
Backburner#schedulesame as defer
Backburner#scheduleOncesame as deferOnce
Backburner#latersame as setTimeout

Example usage

The following code will only cause a single DOM manipulation:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Backburner demo</title>
  </head>

  <body>
    <div id="name"></div>

    <script type="module">
      import Backburner from './dist/es6/backburner.js'

      var backburner = new Backburner(['render']),
        person = {name: 'Erik'};

      function updateName() {
        document.querySelector('#name').innerHTML = person.name;
      }

      function setName(name) {
        person.name = name;
        backburner.deferOnce('render', updateName);
      }

      backburner.run(function() {
        setName('Kris');
        setName('Tom');
        setName('Yehuda');
      });
    </script>
  </body>
</html>

Benchmarks

The /bench directory includes a number of performance benchmarks.

To run in node:

yarn ember build
node ./bench/index.js # (all benchmarks)
node ./bench/index.js ./bench/benches/some-file.js # (specific benchmark)

Or to run in a browser, run yarn ember server, and visit http://localhost:4200 in a browser. Be aware that having the developer tools open/closed can affect JS performance.

版本与发布记录

@discourse/backburner.js 共发布 1 个版本,首次发布于 2022/10/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.7.1-0latest2022/10/124 年前

关于 @discourse/backburner.js 的常见问题

@discourse/backburner.js 是什么?

A fork of backburner.js

如何安装 @discourse/backburner.js?

在项目目录运行 npm install @discourse/backburner.js,或使用 pnpm add / yarn add / bun add。

@discourse/backburner.js 支持 TypeScript 吗?

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

@discourse/backburner.js 支持 ESM 还是 CommonJS?

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

@discourse/backburner.js 可以商用吗?

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

@discourse/backburner.js 的下载量有多少?

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

@discourse/backburner.js 还在维护吗?

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