Prettiering initializers and adding deprecation warning for scheduler service
MODIFY
addon/initializers/app-scheduler.js
addon/initializers/app-scheduler.js
@@ -4,5 +4,5 @@ export function initialize(application) {
export default {
name: 'app-scheduler',
- initialize
+ initialize,
};

MODIFY
addon/instance-initializers/init-app-scheduler.js
addon/instance-initializers/init-app-scheduler.js
@@ -4,5 +4,5 @@ export function initialize(application) {
export default {
name: 'init-app-scheduler',
- initialize: initialize
+ initialize: initialize,
};

MODIFY
addon/services/scheduler.js
addon/services/scheduler.js
import Ember from 'ember';
import { DEBUG } from '@glimmer/env';
+import { deprecate } from '@ember/debug';
-const {
- run,
- RSVP,
- Service,
-} = Ember;
+const { run, RSVP, Service } = Ember;
+
+const QUEUE_MAPPING = {
+ afterFirstRoutePaint: 'whenRoutePainted',
+ afterContentPaint: 'whenRouteIdle',
+};
class Token {
constructor() {
@@ -46,13 +48,24 @@ const Scheduler = Service.extend({
this._routerDidTransitionHandler = null;
this._initQueues();
this._connectToRouter();
- this._useRAF = typeof requestAnimationFrame === "function";
+ this._useRAF = typeof requestAnimationFrame === 'function';
},
scheduleWork(queueName, callback) {
const queue = this.queues[queueName];
const token = new Token();
+ deprecate(
+ `Calling \`scheduleWork('${queueName}')\` will be deprecated in favor of it's functional equivalent, ${
+ QUEUE_MAPPING[queueName]
+ }.`,
+ false,
+ {
+ id: 'ember-app-scheduler-service',
+ until: '2.0.0',
+ }
+ );
+
if (queue.isActive) {
queue.tasks.push(callback);
queue.tasks.push(token);
@@ -80,14 +93,13 @@ const Scheduler = Service.extend({
}
}
- this._afterNextPaint()
- .then(() => {
+ this._afterNextPaint().then(() => {
queue.afterPaintDeferred.resolve();
});
},
_initQueues() {
- const queues = this.queues = Object.create(null);
+ const queues = (this.queues = Object.create(null));
const queueNames = this.queueNames;
for (let i = 0; i < queueNames.length; i++) {
@@ -109,9 +121,11 @@ const Scheduler = Service.extend({
return this._nextAfterPaintPromise;
}
- this._nextAfterPaintPromise = new RSVP.Promise((resolve) => {
+ this._nextAfterPaintPromise = new RSVP.Promise(resolve => {
if (this._useRAF) {
- this._nextPaintFrame = requestAnimationFrame(() => this._rAFCallback(resolve));
+ this._nextPaintFrame = requestAnimationFrame(() =>
+ this._rAFCallback(resolve)
+ );
} else {
this._rAFCallback(resolve);
}
@@ -137,11 +151,9 @@ const Scheduler = Service.extend({
};
this._routerDidTransitionHandler = () => {
- this._afterNextPaint()
- .then(() => {
+ this._afterNextPaint().then(() => {
this.flushQueue('afterFirstRoutePaint');
- this._afterNextPaint()
- .then(() => {
+ this._afterNextPaint().then(() => {
this.flushQueue('afterContentPaint');
});
});
@@ -163,7 +175,7 @@ const Scheduler = Service.extend({
cancelAnimationFrame(this._nextPaintFrame);
}
run.cancel(this._nextPaintTimeout);
- }
+ },
});
if (DEBUG) {
@@ -202,7 +214,7 @@ if (DEBUG) {
}
this._super(...arguments);
- }
+ },
});
}

Prettiering initializers and adding deprecation warning for scheduler service