UNPKG

@magicbell/core

Version:

Official MagicBell API wrapper

30 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const Notification_js_1 = tslib_1.__importDefault(require("./Notification.js")); /** * A factory to create notifications. It implements identity map so there is * one and only one representation of a notification in the system. * * @example * const notification = NotificationFactory.create({ id }); * notification.fetch(); */ class NotificationFactory { static identityMap = new Map(); static create(data) { if (data instanceof Notification_js_1.default) return data; let instance = this.identityMap.get(data.id); if (!instance) { instance = new Notification_js_1.default(data); this.cacheInstance(instance); } return instance; } static cacheInstance(instance) { this.identityMap.set(instance.id, instance); } } exports.default = NotificationFactory; //# sourceMappingURL=NotificationFactory.js.map