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.

66 lines 2.4 kB
import { createIconDefaultMap } from './registry/default-map.js'; import { ActionType } from './registry/types.js'; export class IconsStateBroadcast { constructor(collections, refsCollection) { this.collections = collections; this.refsCollection = refsCollection; this.create(); globalThis.addEventListener('pageshow', () => this.create()); globalThis.addEventListener('pagehide', () => this.dispose()); } send(data) { if (this.channel) { this.channel.postMessage(data); } } handleEvent({ data }) { if (data.actionType !== ActionType.SyncState || data.origin === IconsStateBroadcast.origin) { return; } this.send({ actionType: ActionType.SyncState, collections: this.getUserSetCollection(this.collections).toMap(), references: this.getUserRefsCollection(this.refsCollection).toMap(), origin: IconsStateBroadcast.origin, }); } create() { if (!this.channel) { this.channel = new BroadcastChannel('ignite-ui-icon-channel'); this.channel.addEventListener('message', this); } } dispose() { if (this.channel) { 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; } } IconsStateBroadcast.origin = 'igniteui-webcomponents'; //# sourceMappingURL=icon-state.broadcast.js.map