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.

61 lines (60 loc) 1.52 kB
/*! * NENT 2022 */ import { dir, log, table, warn, } from '../../../../services/common/logging'; import { APP_EVENTS } from '../interfaces'; import { appState, onAppChange } from '../state'; export class DefaultAppProvider { constructor(win = window, eventBus) { this.win = win; this.disposeThemeSubscription = onAppChange('darkMode', t => { if (t == null) win === null || win === void 0 ? void 0 : win.localStorage.removeItem('darkMode'); else win === null || win === void 0 ? void 0 : win.localStorage.setItem('darkMode', t.toString()); eventBus === null || eventBus === void 0 ? void 0 : eventBus.emit(APP_EVENTS.ThemeChanged, t); }); win.addEventListener('storage', () => { this.getTheme(); }); this.getTheme(); } getTheme() { var _a; const mode = (_a = this.win) === null || _a === void 0 ? void 0 : _a.localStorage.getItem('darkMode'); if (mode != null) { appState.darkMode = mode == 'true'; } else { appState.darkMode = null; } } setDarkMode(data) { const { value } = data; appState.darkMode = value != undefined ? Boolean(value) : null; } log(data) { const { message } = data; if (message) { log(message); } else { table(data); } } warn(data) { const { message } = data; if (message) { warn(message); } else { table(data); } } dir(data) { dir(data); } destroy() { this.disposeThemeSubscription(); } }