Super simple RAF scheduler that integrates with the Ember runloop
- 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
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 worklayout
- This queue can be used for touch up on the Ember work in general (small DOM manipulations, for instance)measure
- General measurements should occur hereaffect
- Fixup DOM manipulation after measurements have been done
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);
}
});
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.
git clone <repository-url>
this repositorycd ember-raf-scheduler
yarn install
ember serve
- Visit your app at http://localhost:4200.
yarn test
(Runsember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
For more information on using ember-cli, visit https://ember-cli.com/.