reorganize store code

This commit is contained in:
Géry Debongnie
2019-02-27 13:48:36 +01:00
parent 385156ee72
commit 724181a5ba
21 changed files with 376 additions and 352 deletions
@@ -0,0 +1,40 @@
import { Type } from "../core/component";
import { BaseStore } from "./store";
import { idGenerator } from "../core/utils";
//------------------------------------------------------------------------------
// Notifications Mixin
//------------------------------------------------------------------------------
export interface INotification {
id: number;
title: string;
message: string;
type: "notification" | "warning";
sticky: boolean;
}
export function notificationMixin<T extends Type<BaseStore>>(Base: T) {
return class extends Base {
generateID = idGenerator();
addNotification(notif: Partial<INotification>): number {
const id = this.generateID();
const defaultVals = {
title: "",
message: "",
type: "notification",
sticky: false
};
const notification = Object.assign(defaultVals, notif, { id });
this.trigger("notification_added", notification);
if (!notification.sticky) {
setTimeout(() => this.closeNotification(id), 2500);
}
return id;
}
closeNotification(id: number) {
this.trigger("notification_closed", id);
}
};
}