Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove poller #34

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions angular-poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@
reset: function () {
this.stopAll();
pollers = [];
},

/**
* Stop and removes a specific poller service
*/
remove: function (poller) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why passing in poller here instead of adding a delete function to Poller.prototype? That way you can do something like this in your controller:

myPoller.delete();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't see a way to remove it from the pollers array then, open to suggestions :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go: 3831aad. :-)

for (var i = 0, len = pollers.length; i < len; i++) {
if (angular.equals(pollers[i], poller)) {
pollers[i].stop();
pollers.splice(i, 1);
break;
}
}
}
};
}
Expand Down
10 changes: 10 additions & 0 deletions test/angular-poller-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ describe('emguo.poller', function () {
expect(poller2.interval).to.equal(undefined);
expect(poller.size()).to.equal(0);
});

it('should stop and remove a specific poller service on invoking remove().', function () {
poller.remove(poller1);
expect(poller.size()).to.equal(1);
});

it('should handle not finding a specific poller service on invoking remove().', function () {
poller.remove({});
expect(poller.size()).to.equal(2);
});
});
});

Expand Down