0.1.0 • Published 9 years ago

ember-cli-poll v0.1.0

Weekly downloads
157
License
MIT
Repository
github
Last release
9 years ago

ember-cli-poll

This is an npm package that contains a polling serivce for ember-data packaged as an Ember CLI Addon.

Installation

To install simply run

ember install ember-cli-poll

in your Ember CLI project's root.

Usage

In your route start up the polling service.

import Ember from 'ember';

var ApplicationRoute = Ember.Route.extend({
  poll: Ember.inject.service(),
  afterModel: function () {
    this._super(...arguments);
    this.get('poll').start({
      idle_timeout: 10000,
      interval: 2000,
    });
  }
});

export default ApplicationRoute;

Then from a route, you can setup polling for a resource in the afterModel hook and remove it in a will transition

var ExampleRoute = Ember.Route.extend({
  poll: Ember.inject.service(),
  ...
  afterModel: function (model, transition) {
    this.get('poll').setup({
      name: 'contactsPoll', // a poll name should be unique
      resource_name: 'contacts', // a resource name
      url: `http://some_domain.com/contacts/${contact_id}` // url to fetch resource
    });
  },
  actions: {
    willTransition: function (transition) {
      this._super(transition);
      this.get('poll').removePoll('contactsPoll'); // remove the resource from polling
    },
  }
  ...
});

Or you can use it with a component using the lifecycle hooks.

var SomeComponent = Ember.component.extend({
  poll: Ember.inject.service(),
  didInsertElement: function () {
    this._super();
    var query_params = {
      some_param: 'some_value',
      other_param: 'other_value'
    };
    this.get('poll').setup({
      name: 'usersPoll', // a poll name should be unique
      resource_name: 'users', // resource name
      url: `http://some_domain.com/users`, // url to fetch resource
      params: query_params // query params
    });
  },
  willDestroy: function () {
    this._super();
    this.get('poll').removePoll('usersPoll'); // remove resource from polling
  }
});

export default SomeComponent;
0.1.0

9 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago