Git Product home page Git Product logo

ember-raf-scheduler's Introduction

Build Status

ember-raf-scheduler

Super simple RAF scheduler that integrates with the Ember runloop

Compatibility

  • Ember.js v3.12 or above (possibly older, but older than 3.12 is untested)
  • Ember CLI v4.4 or above
  • Node.js v16 or above

Basics

Super simple example:

import { scheduler } from 'ember-raf-scheduler';

// schedule a job
const job = scheduler.schedule('measure', () => {
  console.log('Hello, world!');
});

// cancel the job
scheduler.forget(job);

There are 4 queues:

  • sync - Wrapped in a runloop, use this queue for all Ember related work
  • layout - This queue can be used for touch up on the Ember work in general (small DOM manipulations, for instance)
  • measure - General measurements should occur here
  • affect - Fixup DOM manipulation after measurements have been done

Tokens

Tokens can be created and passed into the scheduler. All jobs that were scheduled with a token can be cancelled by cancelling the parent token.

import { scheduler, Token } from 'ember-raf-scheduler';

export default Component.extend({
  init() {
    this.token = new Token();
  },

  willDestroy() {
    scheduler.forget(this.token);
  },

  schedule(queue, job) {
    scheduler.schedule(queue, job, this.token);
  }
});

Perf Notes

Measurements in RAFs are basically free if you do them before any other DOM manipulation (same rules as standard forced layouts, etc), so you should batch all measurements in measure and if possible avoid using the sync and layout queues. There are times when it's necessary to do Ember specific manipulations (for instance, you need to use set and you want the template to render before you measure) which is what the sync and layout queues are for.

Installation

  • git clone <repository-url> this repository
  • cd ember-raf-scheduler
  • yarn install

Running

Running Tests

  • yarn test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit https://ember-cli.com/.

ember-raf-scheduler's People

Contributors

mixonic avatar pzuraq avatar mikek2252 avatar robbiethewagner avatar twokul avatar chancancode avatar v-gjy avatar ember-tomster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.