diff --git a/addon/helpers/queue.js b/addon/helpers/queue.js index bec1a14c..5905a672 100644 --- a/addon/helpers/queue.js +++ b/addon/helpers/queue.js @@ -1,19 +1,23 @@ import { helper } from '@ember/component/helper'; import isPromise from '../utils/is-promise'; +function invokeMaybeNullable(curr, args) { + return curr == null ? undefined : curr(...args); +} + export function queue(actions = []) { return function(...args) { let invokeWithArgs = function(acc, curr) { if (isPromise(acc)) { - return acc.then(() => curr(...args)); + return acc.then(() => invokeMaybeNullable(curr, args)); } - return curr(...args); + return invokeMaybeNullable(curr, args); }; return actions.reduce((acc, curr, idx) => { if (idx === 0) { - return curr(...args); + return invokeMaybeNullable(curr, args); } return invokeWithArgs(acc, curr); diff --git a/tests/unit/helpers/queue-test.js b/tests/unit/helpers/queue-test.js index 3b5bd8fe..8186899b 100644 --- a/tests/unit/helpers/queue-test.js +++ b/tests/unit/helpers/queue-test.js @@ -34,6 +34,14 @@ module('Unit | Helper | queue', function(hooks) { assert.ok(step3.calledOnce, 'step3 called once'); }); + test('it ignores null-like values', function(assert) { + let queued = queue([undefined, step1, null, step2, undefined]); + queued(2, 4); + + assert.ok(step1.calledOnce, 'step1 called once'); + assert.ok(step2.calledOnce, 'step2 called once'); + }); + test('it passes all functions the same arguments', function(assert) { let queued = queue([step1, step2, step3]); queued(2, 4);