UNPKG

@anglr/notifications

Version:
183 lines 6.12 kB
import { Injectable, InjectionToken } from '@angular/core'; import { NOTIFICATIONS } from '@anglr/common'; import { generateId, nameof } from '@jscrpt/common'; import * as i0 from "@angular/core"; /** * Base class for notifications services */ class ɵNotificationsService { //######################### properties ######################### /** * @inheritdoc */ get notifications() { throw new Error('Method not implemented.'); } /** * @inheritdoc */ get notificationsChange() { throw new Error('Method not implemented.'); } /** * @inheritdoc */ get destroy() { throw new Error('Method not implemented.'); } //######################### methods ######################### /** * @inheritdoc */ message(_message, _severity, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ default(_message, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ success(_message, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ error(_message, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ info(_message, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ warning(_message, _parameter) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ clearNotifications() { throw new Error('Method not implemented.'); } /** * @inheritdoc */ remove(_notification) { throw new Error('Method not implemented.'); } /** * Gets scoped instance of `Notifications` * @inheritdoc */ getScope(_scopeName) { throw new Error('Method not implemented.'); } /** * @inheritdoc */ ngOnDestroy() { throw new Error('Method not implemented.'); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNotificationsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNotificationsService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵNotificationsService, decorators: [{ type: Injectable }] }); /** * Global notification service that is used for global notifications */ export class GlobalNotificationsService extends ɵNotificationsService { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: GlobalNotificationsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: GlobalNotificationsService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: GlobalNotificationsService, decorators: [{ type: Injectable }] }); /** * Local notification service that is used for local notifications */ export class LocalNotificationsService extends ɵNotificationsService { static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: LocalNotificationsService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: LocalNotificationsService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: LocalNotificationsService, decorators: [{ type: Injectable }] }); /** * Global notifications provider definition */ const GLOBAL_NOTIFICATIONS_DEFINITION = { provide: GlobalNotificationsService, useExisting: NOTIFICATIONS, }; /** * Global notifications provider */ const GLOBAL_NOTIFICATIONS = GLOBAL_NOTIFICATIONS_DEFINITION; Object.defineProperty(GLOBAL_NOTIFICATIONS_DEFINITION, nameof('named'), { get() { return (name, customNotificationsToken) => { return { provide: customNotificationsToken ?? GlobalNotificationsService, useFactory: (notifications) => { return notifications.getScope(name); }, deps: [NOTIFICATIONS], }; }; } }); /** * Local notifications scope name */ export const LOCAL_NOTIFICATIONS_SCOPE_NAME = 'local'; /** * Injection token for injecting local notifications scope name */ export const LOCAL_NOTIFICATIONS_SCOPE = new InjectionToken('LOCAL_NOTIFICATIONS_SCOPE'); /** * Local notifications provider definitions */ const LOCAL_NOTIFICATIONS_DEFINITION = { provide: LocalNotificationsService, useFactory: (notifications) => { return notifications.getScope(LOCAL_NOTIFICATIONS_SCOPE_NAME); }, deps: [NOTIFICATIONS], }; /** * Local notifications provider */ const LOCAL_NOTIFICATIONS = LOCAL_NOTIFICATIONS_DEFINITION; Object.defineProperty(LOCAL_NOTIFICATIONS_DEFINITION, nameof('named'), { get() { return (name = generateId(6), customNotificationsToken) => { const scopeName = `${LOCAL_NOTIFICATIONS_SCOPE_NAME}-${name}`; return [ { provide: customNotificationsToken ?? LocalNotificationsService, useFactory: (notifications) => { return notifications.getScope(scopeName); }, deps: [NOTIFICATIONS], }, { provide: LOCAL_NOTIFICATIONS_SCOPE, useValue: scopeName, } ]; }; } }); export { GLOBAL_NOTIFICATIONS, LOCAL_NOTIFICATIONS }; //# sourceMappingURL=notifications.service.js.map