[ember] ensure that Ember.run and @ember/runloop variants are equally tested

This commit is contained in:
Mike North 2018-09-21 23:26:40 -07:00
parent ff0bdade31
commit 466bd2829c
3 changed files with 50 additions and 56 deletions

View File

@ -1,12 +1,11 @@
import Ember from 'ember';
import RSVP from 'rsvp';
import { run } from '@ember/runloop';
import { assertType } from "./lib/assert";
assertType<string[]>(Ember.run.queues);
function testRun() {
const r = run(() => {
const r = Ember.run(() => {
// code to be executed within a RunLoop
return 123;
});
@ -14,7 +13,7 @@ function testRun() {
function destroyApp(application: Ember.Application) {
Ember.run(application, 'destroy');
run(application, function() {
Ember.run(application, function() {
this.destroy();
});
}
@ -38,48 +37,48 @@ function testBind() {
function testCancel() {
const myContext = {};
const runNext = run.next(myContext, () => {
const runNext = Ember.run.next(myContext, () => {
// will not be executed
});
run.cancel(runNext);
Ember.run.cancel(runNext);
const runLater = run.later(myContext, () => {
const runLater = Ember.run.later(myContext, () => {
// will not be executed
}, 500);
run.cancel(runLater);
Ember.run.cancel(runLater);
const runScheduleOnce = run.scheduleOnce('afterRender', myContext, () => {
const runScheduleOnce = Ember.run.scheduleOnce('afterRender', myContext, () => {
// will not be executed
});
run.cancel(runScheduleOnce);
Ember.run.cancel(runScheduleOnce);
const runOnce = run.once(myContext, () => {
const runOnce = Ember.run.once(myContext, () => {
// will not be executed
});
run.cancel(runOnce);
Ember.run.cancel(runOnce);
const throttle = run.throttle(myContext, () => {
const throttle = Ember.run.throttle(myContext, () => {
// will not be executed
}, 1, false);
run.cancel(throttle);
Ember.run.cancel(throttle);
const debounce = run.debounce(myContext, () => {
const debounce = Ember.run.debounce(myContext, () => {
// will not be executed
}, 1);
run.cancel(debounce);
Ember.run.cancel(debounce);
const debounceImmediate = run.debounce(myContext, () => {
const debounceImmediate = Ember.run.debounce(myContext, () => {
// will be executed since we passed in true (immediate)
}, 100, true);
// the 100ms delay until this method can be called again will be canceled
run.cancel(debounceImmediate);
Ember.run.cancel(debounceImmediate);
}
function testDebounce() {
@ -88,9 +87,9 @@ function testDebounce() {
const myContext = { name: 'debounce' };
run.debounce(runIt, 150);
run.debounce(myContext, runIt, 150);
run.debounce(myContext, runIt, 150, true);
Ember.run.debounce(runIt, 150);
Ember.run.debounce(myContext, runIt, 150);
Ember.run.debounce(myContext, runIt, 150, true);
Ember.Component.extend({
searchValue: 'test',
@ -106,19 +105,19 @@ function testDebounce() {
}
function testBegin() {
run.begin();
Ember.run.begin();
// code to be executed within a RunLoop
run.end();
Ember.run.end();
}
function testJoin() {
run.join(() => {
Ember.run.join(() => {
// creates a new run-loop
});
run(() => {
Ember.run(() => {
// creates a new run-loop
run.join(() => {
Ember.run.join(() => {
// joins with the existing run-loop, and queues for invocation on
// the existing run-loops action queue.
});
@ -133,14 +132,14 @@ function testJoin() {
function testLater() {
const myContext = {};
run.later(myContext, () => {
Ember.run.later(myContext, () => {
// code here will execute within a RunLoop in about 500ms with this == myContext
}, 500);
}
function testNext() {
const myContext = {};
run.next(myContext, () => {
Ember.run.next(myContext, () => {
// code to be executed in the next run loop,
// which will be scheduled after the current one
});
@ -160,12 +159,12 @@ function testOnce() {
function testSchedule() {
Ember.Component.extend({
init() {
run.schedule('sync', this, () => {
Ember.run.schedule('sync', this, () => {
// this will be executed in the first RunLoop queue, when bindings are synced
console.log('scheduled on sync queue');
});
run.schedule('actions', this, () => {
Ember.run.schedule('actions', this, () => {
// this will be executed in the 'actions' queue, after bindings have synced.
console.log('scheduled on actions queue');
});
@ -183,12 +182,12 @@ function testScheduleOnce() {
}
const myContext = {};
run(() => {
run.scheduleOnce('afterRender', myContext, sayHi);
run.scheduleOnce('afterRender', myContext, sayHi);
Ember.run(() => {
Ember.run.scheduleOnce('afterRender', myContext, sayHi);
Ember.run.scheduleOnce('afterRender', myContext, sayHi);
// sayHi will only be executed once, in the afterRender queue of the RunLoop
});
run.scheduleOnce('actions', myContext, () => {
Ember.run.scheduleOnce('actions', myContext, () => {
console.log('Closure');
});
}
@ -199,6 +198,6 @@ function testThrottle() {
const myContext = { name: 'throttle' };
run.throttle(runIt, 150);
run.throttle(myContext, runIt, 150);
Ember.run.throttle(runIt, 150);
Ember.run.throttle(myContext, runIt, 150);
}

View File

@ -1,9 +1,8 @@
import Ember from 'ember';
import RSVP from 'rsvp';
import { run } from '@ember/runloop';
import EmberObject from '@ember/object';
Ember.run.queues; // $ExpectType EmberRunQueues[]
const queues: string[] = Ember.run.queues;
run.queues; // $ExpectType EmberRunQueues[]
const queues: string[] = run.queues;
function testRun() {
run(() => { // $ExpectType number
@ -11,8 +10,8 @@ function testRun() {
return 123;
});
function destroyApp(application: Ember.Application) {
Ember.run(application, 'destroy');
function destroyApp(application: EmberObject) {
run(application, 'destroy');
run(application, function() {
this.destroy();
});
@ -20,9 +19,9 @@ function testRun() {
}
function testBind() {
Ember.Component.extend({
EmberObject.extend({
init() {
const bound = Ember.run.bind(this, this.setupEditor);
const bound = run.bind(this, this.setupEditor);
bound();
},
@ -91,14 +90,14 @@ function testDebounce() {
run.debounce(myContext, runIt, 150);
run.debounce(myContext, runIt, 150, true);
Ember.Component.extend({
EmberObject.extend({
searchValue: 'test',
fetchResults(value: string) {},
actions: {
handleTyping() {
// the fetchResults function is passed into the component from its parent
Ember.run.debounce(this, this.get('fetchResults'), this.get('searchValue'), 250);
run.debounce(this, this.get('fetchResults'), this.get('searchValue'), 250);
}
}
});
@ -123,11 +122,9 @@ function testJoin() {
});
});
new RSVP.Promise((resolve) => {
Ember.run.later(() => {
resolve({ msg: 'Hold Your Horses' });
}, 3000);
});
run.later(() => {
console.log({ msg: 'Hold Your Horses' });
}, 3000);
}
function testLater() {
@ -146,9 +143,9 @@ function testNext() {
}
function testOnce() {
Ember.Component.extend({
EmberObject.extend({
init() {
Ember.run.once(this, 'processFullName');
run.once(this, 'processFullName');
},
processFullName() {
@ -157,7 +154,7 @@ function testOnce() {
}
function testSchedule() {
Ember.Component.extend({
EmberObject.extend({
init() {
run.schedule('sync', this, () => {
// this will be executed in the first RunLoop queue, when bindings are synced
@ -171,7 +168,7 @@ function testSchedule() {
}
});
Ember.run.schedule('actions', () => {
run.schedule('actions', () => {
// Do more things
});
}

View File

@ -17,8 +17,6 @@
"paths": {
"@ember/object": ["ember__object"],
"@ember/object/*": ["ember__object/*"],
"@ember/engine": ["ember__engine"],
"@ember/engine/*": ["ember__engine/*"],
"@ember/runloop": ["ember__runloop"],
"@ember/runloop/*": ["ember__runloop/*"]
},