Created
January 9, 2019 08:10
-
-
Save brookjordan/d2e6bd7fc9ca0ec5149b9dcd9f702c8f to your computer and use it in GitHub Desktop.
Create a new notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@ember/component'; | |
export default Component.extend({ | |
classNames: [ | |
'notification-center-item', | |
], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add `'myNewNotifications'` to `REGISTERED_NOTIFICATION_SERVICES` | |
let REGISTERED_NOTIFICATION_SERVICES = [ | |
'myNewNotifications', | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment