UNPKG

@furystack/shades-common-components

Version:

Common UI components for FuryStack Shades

30 lines 1.24 kB
import { defineService } from '@furystack/inject'; import { EventHub } from '@furystack/utils'; export const NotyService = defineService({ name: '@furystack/shades-common-components/NotyService', lifetime: 'singleton', factory: ({ onDispose }) => { const hub = new EventHub(); let notyList = []; const onNotyAddListener = (newNoty) => { notyList = [...notyList, newNoty]; }; const onNotyRemoveListener = (removedNoty) => { notyList = notyList.filter((noty) => noty !== removedNoty); }; hub.addListener('onNotyAdded', onNotyAddListener); hub.addListener('onNotyRemoved', onNotyRemoveListener); onDispose(() => { notyList = []; hub.removeListener('onNotyAdded', onNotyAddListener); hub.removeListener('onNotyRemoved', onNotyRemoveListener); // eslint-disable-next-line furystack/prefer-using-wrapper -- Disposal is deferred to the injector's onDispose hook. hub[Symbol.dispose]?.(); }); const service = Object.assign(hub, { getNotyList: () => [...notyList], }); return service; }, }); //# sourceMappingURL=noty-service.js.map