UNPKG

igniteui-webcomponents

Version:

Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.

76 lines 2.7 kB
import { createIconDefaultMap } from './registry/default-map.js'; import { ActionType } from './registry/types.js'; export class IconsStateBroadcast { static { this._origin = 'igniteui-webcomponents'; } constructor(iconsCollection, iconReferences) { this._channel = null; this._iconsCollection = iconsCollection; this._iconReferences = iconReferences; globalThis.addEventListener('pageshow', this); globalThis.addEventListener('pagehide', this); this._create(); } send(data) { this._channel?.postMessage(data); } handleEvent(event) { switch (event.type) { case 'message': this._syncState(event); break; case 'pageshow': this._create(); break; case 'pagehide': this._dispose(); break; } } _syncState({ data: { actionType, origin }, }) { if (actionType !== ActionType.SyncState || origin === IconsStateBroadcast._origin) { return; } this.send({ actionType: ActionType.SyncState, collections: this._getUserSetCollection(this._iconsCollection).toPlainMap(), references: this._getUserRefsCollection(this._iconReferences).toPlainMap(), origin: IconsStateBroadcast._origin, }); } _create() { if (!this._channel) { this._channel = new BroadcastChannel('ignite-ui-icon-channel'); this._channel.addEventListener('message', this); } } _dispose() { this._channel?.removeEventListener('message', this); this._channel?.close(); this._channel = null; } _getUserRefsCollection(collections) { const userSetIcons = createIconDefaultMap(); for (const [collectionKey, collection] of collections.entries()) { for (const [iconKey, icon] of collection.entries()) { if (icon.external) { userSetIcons.getOrCreate(collectionKey).set(iconKey, icon); } } } return userSetIcons; } _getUserSetCollection(collections) { const userSetIcons = createIconDefaultMap(); for (const [collectionKey, collection] of collections.entries()) { if (collectionKey === 'internal') { continue; } for (const [iconKey, icon] of collection.entries()) { userSetIcons.getOrCreate(collectionKey).set(iconKey, icon); } } return userSetIcons; } } //# sourceMappingURL=icon-state.broadcast.js.map