UNPKG

activator-oce-exporter

Version:

Extract Activator binder and convert it to valid OCE mono pacakge

37 lines (29 loc) 864 B
import { httpRequest } from './utils'; class ThemeApplier { static getFetchConfigHandler(url) { let configPromise = null; return function fetchConfigHandler() { if (!configPromise) { configPromise = httpRequest(url); } return configPromise; }; } constructor(configURL) { this.fetchConfig = ThemeApplier.getFetchConfigHandler(configURL); this.init(); } async init() { const { colors } = await this.fetchConfig(); ThemeApplier.applyColors(document.documentElement, colors); } static applyColors(root, colors) { Object.keys(colors) .forEach(colorName => root.style.setProperty(colorName, colors[colorName])); } async getConfig() { return this.fetchConfig(); } } const themeApplier = new ThemeApplier(`../shared/src/config.json?ts=${Date.now()}`); export { themeApplier };