Ember CLI Push.js Shim

Add native javascript Notifications to your application

View on Github View on NPM

Installation

You can install it like a standard Ember addon. This brings in the Push.js dependency and makes it available as an ES6 style import

ember install ember-cli-push-js-shim

Creating Notifications

Here is a simple example showing how to display a notification

import Ember from 'ember';
import Push from 'pushjs';

export default Ember.Route.extend({
  actions: {
    createNotification() {
      Push.create('Hello World!');
    }
  }
});

Closing Notifications

You can close notifications in two ways, either by giving the notifcation a tag

import Ember from 'ember';
import Push from 'pushjs';

export default Ember.Route.extend({
  actions: {
    createTaggedNotification() {
      Push.create('Hello World!', {
        tag: 'example'
      });
    },

    closeTaggedNotification() {
      Push.close('example');
    }
  }
});

Or by storing a reference to the promise created

import Ember from 'ember';
import Push from 'pushjs';

export default Ember.Route.extend({
  actions: {
    createPromiseNotification() {
      this.set('createPromise', Push.create('Hello World!'));
    },

    closePromiseNotification() {
      this.get('createPromise').then( notification => {
        notification.close();
      });
    }
  }
});

Closing All Notifications

You can clear all notifications with one method

import Ember from 'ember';
import Push from 'pushjs';

export default Ember.Route.extend({
  actions: {
    createMultipleNotification() {
      Push.create('First Notification');
      Push.create('Second Notification');
      Push.create('Third Notification');
    },

    closeAllNotification() {
      Push.clear();
    }
  }
});

Options

In addition to the required title there are also several options

For example here is a notification which times out after 2 seconds with a description and an image

import Ember from 'ember';
import Push from 'pushjs';

export default Ember.Route.extend({
  actions: {
    createOptionsNotification() {
      Push.create('Notification With Options', {
        timeout: 2000,
        body: 'A longer description goes here.',
        icon: 'assets/images/chrismasters_icon-f1839364625d2d9882a5c2127a8f1bf7.png'
      });
    }
  }
});

Further Information

See Push.js for more details, or the Github repo for this project