npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-pollboy

v1.0.2

Published

Ember polling service.

Downloads

153

Readme

ember-pollboy Travis Coveralls NPM Ember

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.

import Ember from 'ember'

export const pollInterval = 5000 // time in milliseconds

export default Ember.Route.extend({
  getUsers () {
    return this.get('store').findAll('user')
  },

  model () {
    return this.getUsers()
  },

  onPoll ()  {
    return this.getUsers()
      .then((users) => {
        this.set('currentModel', users)
      })
  },

  afterModel () {
    let usersPoller = this.get('usersPoller')

    // Make sure we only create one poller instance. Without this every time onPoll
    // is called afterModel would create a new poller causing us to have a growing list
    // of pollers all polling the same thing (which would result in more frequent polling).
    if (!usersPoller) {
      usersPoller = this.get('pollboy').add(this, this.onPoll, pollInterval)
      this.set('usersPoller', usersPoller)
    }
  },

  deactivate () {
    const usersPoller = this.get('usersPoller')
    this.get('pollboy').remove(usersPoller)
  }
})

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: