Skip to content

Commit

Permalink
Merge pull request #16067 from rwjblue/update-backburner
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix issues with `run.debounce` with only method and wait.
  • Loading branch information
rwjblue authored Jan 5, 2018
2 parents d007c27 + db305cf commit a8ee02e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-plugin-transform-proto-to-assign": "^6.23.0",
"babel-template": "^6.24.1",
"backburner.js": "^2.0.0",
"backburner.js": "^2.0.2",
"broccoli-babel-transpiler": "^6.1.1",
"broccoli-concat": "^3.2.2",
"broccoli-debug": "^0.6.3",
Expand Down
80 changes: 69 additions & 11 deletions packages/ember-metal/tests/run_loop/debounce_test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
import { run } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';

const originalDebounce = run.backburner.debounce;
let wasCalled = false;

moduleFor('Ember.run.debounce', class extends AbstractTestCase {
constructor() {
super();
['@test Ember.run.debounce - with target, with method, without args'](assert) {
let done = assert.async();

let calledWith = [];
let target = {
someFunc(...args) {
calledWith.push(args);
}
};

run.debounce(target, target.someFunc, 10);
run.debounce(target, target.someFunc, 10);
run.debounce(target, target.someFunc, 10);

setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
done();
}, 20);
}

['@test Ember.run.debounce - with target, with method name, without args'](assert) {
let done = assert.async();

let calledWith = [];
let target = {
someFunc(...args) {
calledWith.push(args);
}
};

run.backburner.debounce = function() { wasCalled = true; };
run.debounce(target, 'someFunc', 10);
run.debounce(target, 'someFunc', 10);
run.debounce(target, 'someFunc', 10);

setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
done();
}, 20);
}

teardown() {
run.backburner.debounce = originalDebounce;
['@test Ember.run.debounce - without target, without args'](assert) {
let done = assert.async();

let calledWith = [];
function someFunc(...args) {
calledWith.push(args);
}

run.debounce(someFunc, 10);
run.debounce(someFunc, 10);
run.debounce(someFunc, 10);

setTimeout(() => {
assert.deepEqual(calledWith, [ [] ], 'someFunc called once with correct arguments');
done();
}, 20);
}

['@test Ember.run.debounce uses Backburner.debounce'](assert) {
run.debounce(() => {});
assert.ok(wasCalled, 'Ember.run.debounce used');
['@test Ember.run.debounce - without target, with args'](assert) {
let done = assert.async();

let calledWith = [];
function someFunc(...args) {
calledWith.push(args);
}

run.debounce(someFunc, { isFoo: true }, 10);
run.debounce(someFunc, { isBar: true }, 10);
run.debounce(someFunc, { isBaz: true }, 10);

setTimeout(() => {
assert.deepEqual(calledWith, [ [ { isBaz: true } ] ], 'someFunc called once with correct arguments');
done();
}, 20);
}
});
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,9 @@ backbone@^1.1.2:
dependencies:
underscore ">=1.8.3"

backburner.js@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.0.0.tgz#ca78f7357776e24885f4dd4a887249b35fdd9c6c"
backburner.js@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/backburner.js/-/backburner.js-2.0.2.tgz#d0049c0c6fd023084b66afeb82849f704ac6315e"

[email protected]:
version "1.0.2"
Expand Down

0 comments on commit a8ee02e

Please sign in to comment.