UNPKG

@nent/core

Version:

Functional elements to add routing, data-binding, dynamic HTML, declarative actions, audio, video, and so much more. Supercharge static HTML files into web apps without script or builds.

47 lines (44 loc) 1.33 kB
/*! * NENT 2022 */ import { f as forceUpdate } from './index-916ca544.js'; import { e as eventBus } from './index-f7016b94.js'; import { a as state, o as onChange } from './state-27a8a5bc.js'; /* istanbul ignore file */ /* It subscribes to an event on the event bus and calls forceUpdate on the component when the event is emitted */ class CommonStateSubscriber { constructor(component, commonSetting, eventName, events = eventBus) { this.component = component; this.eventName = eventName; this.events = events; if (state[commonSetting]) { this.subscribeToEvents(); } else { this.stateSubscription = onChange(commonSetting, enabled => { var _a; if (enabled) { this.subscribeToEvents(); } else { (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.call(this); } }); } } subscribeToEvents() { this.subscription = this.events.on(this.eventName, () => { forceUpdate(this.component); }); } /** * It unsubscribes from the observable. */ destroy() { var _a, _b; (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.call(this); (_b = this.stateSubscription) === null || _b === void 0 ? void 0 : _b.call(this); } } export { CommonStateSubscriber as C };