Socket
Socket
Sign inDemoInstall

@discourse/backburner.js

Package Overview
Dependencies
0
Maintainers
6
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @discourse/backburner.js

A fork of backburner.js


Version published
Weekly downloads
5.7K
increased by21.09%
Maintainers
6
Created
Weekly downloads
 

Readme

Source

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.

FAQs

Last updated on 12 Oct 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc