Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brookjordan/d2e6bd7fc9ca0ec5149b9dcd9f702c8f to your computer and use it in GitHub Desktop.
Save brookjordan/d2e6bd7fc9ca0ec5149b9dcd9f702c8f to your computer and use it in GitHub Desktop.
Create a new notification
import Component from '@ember/component';
export default Component.extend({
classNames: [
'notification-center-item',
],
});
// add `'myNewNotifications'` to `REGISTERED_NOTIFICATION_SERVICES`
let REGISTERED_NOTIFICATION_SERVICES = [
'myNewNotifications',
];
import Service from '@ember/service';
import { A } from '@ember/array';
import { later as runLater } from '@ember/runloop';
import moment from 'moment';
const UPDATE_INTERVAL = +moment.duration({ seconds: 10 });
export default Service.extend({
notificationItems: null,
notificationCount: 0,
init() {
this._super(...arguments);
this.set('notificationItems', A());
this.addMessages();
},
addMessages() {
this.get('notificationItems')
.pushObject({
id: `my-new-notification--${this.get('notificationCount')}`,
component: 'notification-item-my-new-notifications',
published: new Date(),
priority: 0,
data: {
message: `There were already ${this.get('notificationCount')} "my-new-notification"s when this was added.`,
},
});
this.incrementProperty('notificationCount');
runLater(this, this.addMessages, UPDATE_INTERVAL);
},
});
<div class="notification-center-item__wrapper">
<div class="notification-center-item__description">
{{data.message}}
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment