0.1.0 • Published 8 years ago

ember-cli-poll v0.1.0

Weekly downloads
157
License
MIT
Repository
github
Last release
8 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

8 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago