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.

49 lines (45 loc) 1.35 kB
/*! * NENT 2022 */ 'use strict'; const index$1 = require('./index-1829aebc.js'); const index = require('./index-637e8c28.js'); const state = require('./state-f97ff0e6.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 = index.eventBus) { this.component = component; this.eventName = eventName; this.events = events; if (state.state[commonSetting]) { this.subscribeToEvents(); } else { this.stateSubscription = state.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, () => { index$1.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); } } exports.CommonStateSubscriber = CommonStateSubscriber;