Skip to content

Commit

Permalink
Fix bug with defer where it is not variadic
Browse files Browse the repository at this point in the history
  • Loading branch information
goatslacker committed Feb 12, 2015
1 parent 48efd69 commit eb4e3a0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
10 changes: 7 additions & 3 deletions dist/alt-with-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,13 @@ var Alt = (function () {

// Set all the properties on action
obj[action] = newAction[ACTION_HANDLER];
obj[action].defer = function (x) {
return setTimeout(function () {
return newAction[ACTION_HANDLER](x);
obj[action].defer = function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

setTimeout(function () {
return newAction[ACTION_HANDLER].apply(null, args);
});
};
obj[action][ACTION_KEY] = actionName;
Expand Down
10 changes: 7 additions & 3 deletions dist/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,13 @@ var Alt = (function () {

// Set all the properties on action
obj[action] = newAction[ACTION_HANDLER];
obj[action].defer = function (x) {
return setTimeout(function () {
return newAction[ACTION_HANDLER](x);
obj[action].defer = function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

setTimeout(function () {
return newAction[ACTION_HANDLER].apply(null, args);
});
};
obj[action][ACTION_KEY] = actionName;
Expand Down
4 changes: 3 additions & 1 deletion src/alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ your own custom identifier for each store`

// Set all the properties on action
obj[action] = newAction[ACTION_HANDLER]
obj[action].defer = (x) => setTimeout(() => newAction[ACTION_HANDLER](x))
obj[action].defer = (...args) => {
setTimeout(() => newAction[ACTION_HANDLER].apply(null, args))
}
obj[action][ACTION_KEY] = actionName
obj[constant] = actionName

Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ module.exports = {
assert.equal(Array.isArray(secondStore.getState().foo), true, 'shorthand for multiple elements pass through goes as array')
assert.equal(secondStore.getState().foo[0], 1, 'shorthand for multiple elements pass through goes as array')
assert.equal(secondStore.getState().foo[1], 0, 'shorthand for multiple elements pass through goes as array')

myActions.shortHandBinary.defer(2, 1)
setTimeout(() => {
assert.equal(secondStore.getState().foo[0], 2, 'shorthand for defer multiple elements pass through goes as array')
assert.equal(secondStore.getState().foo[1], 1, 'shorthand for defer multiple elements pass through goes as array')
})
},

'access of stores'() {
Expand Down

0 comments on commit eb4e3a0

Please sign in to comment.