From d3d667d3076a640249cc998565bfa28aba8b59ea Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 5 Jan 2018 11:38:51 -0500 Subject: [PATCH 1/2] [BUGFIX beta] Fix issues with `run.debounce` with only method and wait. Update to backburner.js@2.0.2 Fixes issues with calling `Ember.run.debounce(someFunction, timeDelay)`. Prior to this change, ^ would throw an error. --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a3da963e9a9..35761a43c1d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 84b8f0ac4c0..8ecfe681e9b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" backo2@1.0.2: version "1.0.2" From db305cfc45b84c5b9b1c2b8c8b13b11821e74658 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 5 Jan 2018 11:47:34 -0500 Subject: [PATCH 2/2] [BUGFIX beta] Add simple Ember.run.debounce tests. Some very basic tests around common usage patterns to help prevent regressions in the future. --- .../tests/run_loop/debounce_test.js | 80 ++++++++++++++++--- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/packages/ember-metal/tests/run_loop/debounce_test.js b/packages/ember-metal/tests/run_loop/debounce_test.js index ba0f6063767..09b38d2511a 100644 --- a/packages/ember-metal/tests/run_loop/debounce_test.js +++ b/packages/ember-metal/tests/run_loop/debounce_test.js @@ -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); } });