Fixing incorrect logic on abort. Fixing discarded promises on multiple willTransitions
MODIFY
addon/scheduler.js
addon/scheduler.js
@@ -9,15 +9,13 @@ let _whenRouteIdle;
reset();
-export const TRANSITION_INTERUPTED = 'TRANSITION INTERUPTED';
-
export function beginTransition() {
- _checkForPriorTransition();
-
+ if (_didTransition.isResolved) {
_didTransition = _defer();
_whenRoutePainted = _didTransition.promise.then(_afterNextPaint);
_whenRouteIdle = _whenRoutePainted.then(_afterNextPaint);
}
+}
export function endTransition() {
_didTransition.resolve();
@@ -83,15 +81,6 @@ export function useRAF(
export function useRequestIdleCallback() {}
-function _checkForPriorTransition() {
- if (!_didTransition.isResolved) {
- let error = new Error(TRANSITION_INTERUPTED);
- error.code = TRANSITION_INTERUPTED;
-
- _didTransition.reject(error);
- }
-}
-
let _activeRAFs = 0;
function _afterNextPaint() {
let promise = new RSVP.Promise(resolve => {

MODIFY
package.json
package.json
"ember-ajax": "^3.0.0",
"ember-cli": "~2.15.1",
"ember-cli-dependency-checker": "^2.0.0",
- "ember-cli-eslint": "^4.0.0",
+ "ember-cli-eslint": "^4.2.3",
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
- "ember-cli-qunit": "^4.3.2",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
- "ember-qunit": "3.4.0",
+ "ember-qunit": "^3.4.0",
"ember-resolver": "^4.0.0",
"ember-source": "2.18.0",
"eslint-config-prettier": "^2.9.0",

MODIFY
tests/dummy/app/routes/aborted-paint.js
tests/dummy/app/routes/aborted-paint.js
import Ember from 'ember';
export default Ember.Route.extend({
- beforeModel() {
+ beforeModel(transition) {
+ transition.abort();
this.transitionTo('first-paint');
},
});

ADD
tests/dummy/app/templates/error.hbs
+<div>Error</div>
\ No newline at end of file

MODIFY
tests/unit/scheduler-test.js
tests/unit/scheduler-test.js
@@ -5,7 +5,6 @@ import {
routeSettled,
beginTransition,
endTransition,
- TRANSITION_INTERUPTED,
} from 'ember-app-scheduler';
import { useRAF } from 'ember-app-scheduler/scheduler';
@@ -53,21 +52,25 @@ module('Unit | Scheduler', function(hooks) {
await routeSettled();
});
- test('whenRouteIdle with transition interuped', async function(assert) {
- assert.expect(1);
+ test('whenRouteIdle with transition interupted', async function(assert) {
+ assert.expect(3);
beginTransition();
- try {
- let routeIdle = whenRouteIdle();
+ whenRouteIdle().then(() => {
+ assert.step('first whenRouteIdle');
+ });
+
beginTransition();
- await routeIdle;
- } catch (reason) {
- assert.equal(reason.code, TRANSITION_INTERUPTED);
- }
+
+ whenRouteIdle().then(() => {
+ assert.step('second whenRouteIdle');
+ });
endTransition();
await routeSettled();
+
+ assert.verifySteps(['first whenRouteIdle', 'second whenRouteIdle']);
});
});

Fixing incorrect logic on abort. Fixing discarded promises on multiple willTransitions