constructor (app) { log('constructor run with: ', app); this.pid = app.pluginId; this.config = { local: app.localModules || ctor.array() }; this.t = { e: app.errTimeout, n: app.timeout }; this.location = { protocol: app.protocol, host: app.host, path: app.path, ptm: app.pathToModule, ptc: app.pathToConfig }; this.modules = ctor.object(); this.missingModules = ctor.array(); this.talker = new Talker(this.pid); this.talker.addListener(); this.getConfigurationFromCache(); }
constructor (remote, local) { if (Array.isArray(remote)) { this.cfg = remote; } else { this.cfg = ctor.array(ctor.object({v: 0, k: ''})); } if (Array.isArray(local)) { this.cfg = this.cfg.concat(local); } return this.cfg; }
getConfigurationFromCache () { log('getConfigurationFromCache'); let rawConfiguration = this.talker.api.localStorage.get(`${this.pid}cfg`); let configuration = helper.parseJson(rawConfiguration); if(!configuration) { configuration = new Configuration(null, this.config.local); this.talker.api.localStorage.set(`${this.pid}cfg`, configuration); this.talker.api.localStorage.set(`${this.pid}ttl`, 0); this.config.global = ctor.array(ctor.object({v: 0, k: ''})); } else { configuration = new Configuration(this.config.global, this.config.local); } this.config.all = { key: configuration[0].k, ttl: ctor.number(this.talker.api.localStorage.get(`${this.pid}ttl`) || 0), version: configuration[0].v, modules: [], raw: configuration }; }