@nent/core
Version:
93 lines (88 loc) • 2.61 kB
JavaScript
/*!
* NENT 2022
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-1829aebc.js');
const factory = require('./factory-0d7ddff9.js');
const state = require('./state-9c7a0826.js');
const state$1 = require('./state-f97ff0e6.js');
require('./index-637e8c28.js');
require('./interfaces-95d0415a.js');
require('./index-96f3ab3f.js');
require('./values-b2399e33.js');
require('./promises-463f4e01.js');
require('./logging-37c154cf.js');
const AudioSwitch = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.storage = null;
/**
* Which state property this switch controls.
*/
this.setting = 'enabled';
/**
* The data provider to store the audio state in.
*/
this.dataProvider = 'storage';
}
get stateKey() {
return `audio-${this.setting}`;
}
setValue(value) {
switch (this.setting) {
case 'enabled': {
state$1.state.audioEnabled = value;
break;
}
case 'muted': {
state.state.muted = value;
break;
}
}
}
getValue() {
switch (this.setting) {
case 'enabled': {
return state$1.state.audioEnabled;
}
case 'muted': {
return state.state.muted;
}
}
}
async componentWillLoad() {
var _a;
this.storage = (await factory.getDataProvider(this.dataProvider));
if (this.storage) {
const value = await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.get(this.stateKey));
if (value != null) {
this.setValue(value == 'true');
}
}
this.subscription =
this.setting == 'muted'
? state.onChange('muted', async (m) => {
var _a;
await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.stateKey, m.toString()));
})
: state$1.onChange('audioEnabled', async (m) => {
var _a;
await ((_a = this.storage) === null || _a === void 0 ? void 0 : _a.set(this.stateKey, m.toString()));
});
}
toggle() {
var _a;
this.setValue(((_a = this.checkbox) === null || _a === void 0 ? void 0 : _a.checked) || false);
}
disconnectedCallback() {
var _a;
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.call(this);
}
render() {
return (index.h(index.Host, null, index.h("input", { type: "checkbox", class: this.inputClass, id: this.inputId, ref: e => {
this.checkbox = e;
}, onChange: () => this.toggle(), checked: this.getValue() })));
}
};
exports.n_audio_switch = AudioSwitch;