This addon provides a polling service to make it easy to setup polling in Ember routes. One of the benefits to using this service is that it only polls when the page is in view, meaning when a user switches browser tabs, applications, or desktops the polling is paused.
Installation
ember install ember-pollboy
API
Service
In a route you retrieve the service via this.get('pollboy')
. Below is a list of available
methods on this service:
add(context, callback, interval): Poller
- context - The context in which to use for the callback function.
- callback - The callback function to call on each polling interval.
- interval - The interval in which to poll.
This function returns a new Poller instance.
remove(poller): void
- poller - The poller instance to remove. Note: poller will also be stopped before removal.
Usage
Below is an example of a route that uses the ember-pollboy
service to fetch a list
of users and update that list on a polling interval of 5 seconds.
const pollInterval = 5000 // time in milliseconds Route
In the above example you will notice after we retrieve the model we setup a polling
interval using ember-pollboy
. When the route is deactivate we remove our poller from
the service to ensure polling stops when switching routes.
Testing
Run npm test
from the root of the project to run linting checks as well as execute the test suite
and output code coverage.
Test Helpers
The following test helpers are provided at ember-pollboy/test-support/mock
to assist with writing tests for code that uses ember-pollboy
: