2015-06-08 18:14:25 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-06 16:47:59 +02:00
|
|
|
import { alt } from '../alt';
|
2015-06-08 18:14:25 +02:00
|
|
|
|
|
|
|
import GlobalNotificationActions from '../actions/global_notification_actions';
|
|
|
|
|
|
|
|
class GlobalNotificationStore {
|
|
|
|
constructor() {
|
2015-06-09 12:08:14 +02:00
|
|
|
this.notificationQue = [];
|
2015-06-08 18:14:25 +02:00
|
|
|
|
|
|
|
this.bindActions(GlobalNotificationActions);
|
|
|
|
}
|
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
onAppendGlobalNotification(newNotification) {
|
|
|
|
let notificationDelay = 0;
|
|
|
|
for(let i = 0; i < this.notificationQue.length; i++) {
|
|
|
|
notificationDelay += this.notificationQue[i].dismissAfter;
|
2015-06-08 18:14:25 +02:00
|
|
|
}
|
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
this.notificationQue.push(newNotification);
|
|
|
|
setTimeout(GlobalNotificationActions.emulateEmptyStore, notificationDelay + newNotification.dismissAfter);
|
2015-06-08 18:14:25 +02:00
|
|
|
}
|
|
|
|
|
2015-06-09 12:08:14 +02:00
|
|
|
onEmulateEmptyStore() {
|
|
|
|
let actualNotificitionQue = this.notificationQue.slice();
|
|
|
|
|
|
|
|
this.notificationQue = [];
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.notificationQue = actualNotificitionQue.slice();
|
|
|
|
GlobalNotificationActions.shiftGlobalNotification();
|
|
|
|
}, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
onShiftGlobalNotification() {
|
|
|
|
this.notificationQue.shift();
|
2015-06-08 18:14:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-15 08:44:44 +02:00
|
|
|
export default alt.createStore(GlobalNotificationStore, 'GlobalNotificationStore');
|