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.

65 lines (59 loc) 2.13 kB
/*! * NENT 2022 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index$1 = require('./index-1829aebc.js'); const index$2 = require('./index-637e8c28.js'); const factory = require('./factory-0d7ddff9.js'); const index = require('./index-96f3ab3f.js'); const interfaces = require('./interfaces-393094fa.js'); require('./interfaces-95d0415a.js'); require('./values-b2399e33.js'); require('./promises-463f4e01.js'); require('./logging-37c154cf.js'); /* istanbul ignore file */ const store = index.createStore({ autoplay: true, }); const { state, onChange, reset, dispose } = store; const VideoSwitch = class { constructor(hostRef) { index$1.registerInstance(this, hostRef); this.enabledKey = 'autoplay'; this.storage = null; this.autoPlay = true; /** * The data provider to store the audio-enabled state in. */ this.dataProvider = 'storage'; } async componentWillLoad() { this.autoPlay = state.autoplay; this.storage = (await factory.getDataProvider(this.dataProvider)); if (this.storage) { const autoplay = await this.storage.get(this.enabledKey); state.autoplay = autoplay !== 'false'; } this.videoSubscription = onChange('autoplay', async (a) => { var _a; this.autoPlay = a; await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.enabledKey, a.toString())); index$2.eventBus === null || index$2.eventBus === void 0 ? void 0 : index$2.eventBus.emit(interfaces.VIDEO_EVENTS.AutoPlayChanged, a); }); } toggleAutoPlay() { var _a; state.autoplay = ((_a = this.checkbox) === null || _a === void 0 ? void 0 : _a.checked) || false; } disconnectedCallback() { var _a; (_a = this.videoSubscription) === null || _a === void 0 ? void 0 : _a.call(this); } render() { return (index$1.h(index$1.Host, null, index$1.h("input", { type: "checkbox", class: this.inputClass, id: this.inputId, ref: e => { this.checkbox = e; }, onChange: () => this.toggleAutoPlay(), checked: this.autoPlay }))); } }; exports.n_video_switch = VideoSwitch;