-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($interval): pass arguments in callback #10632
Conversation
Note that according to MDN, IE9 does not support the additional arguments. |
due to the way angular is handling promise.then(null, null, function() {
fn.apply(null, args);
}); promise.then(null, null, args.length === 0 ? fn : function() {
fn.apply(null, args);
}); |
@gdi2290: Good point ;) BTW, if it gets merged, it would be good to have the docs updatd as well (imo). |
fe6d7f7
to
2607697
Compare
I added docs and optimise the code a bit to check args once * @param {...*=} Pass additional parameters to the executed function. |
expect(task2).toHaveBeenCalledWith('Task2'); | ||
$window.flush(1000); | ||
expect(task3).toHaveBeenCalledWith('I', 'am', 'a', 'Task3', 'spy'); | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sequence of expectations seems not quite right. Since we are using $interval
then each of the spies should have been called once per flush.
How about something more like:
$window.flush(1000);
expect(task1).toHaveBeenCalledWith('Task1');
expect(task2).toHaveBeenCalledWith('Task2');
expect(task3).toHaveBeenCalledWith('I', 'am', 'a', 'Task3', 'spy');
task1.reset();
task2.reset();
task3.reset();
$window.flush(1000);
expect(task1).toHaveBeenCalledWith('Task1');
expect(task2).toHaveBeenCalledWith('Task2');
expect(task3).toHaveBeenCalledWith('I', 'am', 'a', 'Task3', 'spy');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the tests (and rebase master) with an $interval
count of 2 otherwise the second part of this won't work since the .reset()
only resets the state of the spy and not $interval
.
2607697
to
76a3684
Compare
I have a question about the mocks. https://github.com/angular/angular.js/blob/master/src/ngMock/angular-mocks.js#L456 I'm assuming I need to update the mocks with the same logic but it seems a bit crazy that I can add a feature to |
76a3684
to
1186623
Compare
@gdi2290 - the tests of the |
1186623
to
3108486
Compare
I pushed up changes to mock to reflect the
either one that's chosen I think a new PR would make sense for that change while this one should be good |
3108486
to
690d321
Compare
Actually |
In the meantime, this PR looks fine from the point of view of this feature, so let's land it too. |
Similar to how [`setInterval`](http://mdn.io/setInterval#Syntax) works, this commit allows users of `$interval` to add additional parameters to the call, which will now be passed on to the callback function. Closes angular#10632
Similar to how [`setInterval`](http://mdn.io/setInterval#Syntax) works, this commit allows users of `$interval` to add additional parameters to the call, which will now be passed on to the callback function. Closes angular#10632
PR has updated Docs and Tests
setInterval
allows you to pass arguments into the callback functionin
the …3rd argument. Since that’s taken I added it to the …5th
http://mdn.io/setInterval#Syntax
similar pull request #10631