1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 18:13:49 +01:00
onion/js/stores/global_notification_store.js
2015-06-15 08:44:44 +02:00

41 lines
1.1 KiB
JavaScript

'use strict';
import alt from '../alt';
import GlobalNotificationActions from '../actions/global_notification_actions';
class GlobalNotificationStore {
constructor() {
this.notificationQue = [];
this.bindActions(GlobalNotificationActions);
}
onAppendGlobalNotification(newNotification) {
let notificationDelay = 0;
for(let i = 0; i < this.notificationQue.length; i++) {
notificationDelay += this.notificationQue[i].dismissAfter;
}
this.notificationQue.push(newNotification);
setTimeout(GlobalNotificationActions.emulateEmptyStore, notificationDelay + newNotification.dismissAfter);
}
onEmulateEmptyStore() {
let actualNotificitionQue = this.notificationQue.slice();
this.notificationQue = [];
setTimeout(() => {
this.notificationQue = actualNotificitionQue.slice();
GlobalNotificationActions.shiftGlobalNotification();
}, 400);
}
onShiftGlobalNotification() {
this.notificationQue.shift();
}
}
export default alt.createStore(GlobalNotificationStore, 'GlobalNotificationStore');