From b60a1bebe03af0b2c8647c6ec72bcdbabe46dafd Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 7 Dec 2020 03:13:34 +0000 Subject: [PATCH] fix(core): update --- package.json | 1 + ts/domtools.classes.domtools.ts | 3 --- ts/domtools.classes.elementinstrumenter.ts | 29 ---------------------- ts/domtools.classes.thememanager.ts | 19 +++----------- ts/domtools.elementbasic.ts | 3 ++- ts/domtools.plugins.ts | 3 ++- 6 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 ts/domtools.classes.elementinstrumenter.ts diff --git a/package.json b/package.json index 4869007..d3d4bec 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@pushrocks/smartdelay": "^2.0.10", "@pushrocks/smartpromise": "^3.1.3", "@pushrocks/smartrouter": "^1.0.6", + "@pushrocks/smartrx": "^2.0.19", "@pushrocks/smartstate": "^1.0.21", "@pushrocks/webrequest": "^2.0.13", "@pushrocks/websetup": "^3.0.11", diff --git a/ts/domtools.classes.domtools.ts b/ts/domtools.classes.domtools.ts index 4595f98..be5a481 100644 --- a/ts/domtools.classes.domtools.ts +++ b/ts/domtools.classes.domtools.ts @@ -6,7 +6,6 @@ import { TViewport } from './domtools.breakpoints'; import { Scroller } from './domtools.classes.scroller'; import { delayForRandom } from '@pushrocks/smartdelay'; import { WebSetup } from '@pushrocks/websetup'; -import { ElementInstrumenter } from './domtools.classes.elementinstrumenter'; import { ThemeManager } from './domtools.classes.thememanager'; export interface IDomToolsState { @@ -85,8 +84,6 @@ export class DomTools { smartdelay: plugins.smartdelay, }; - - public elementInstrumenter = new ElementInstrumenter(); public deesComms = new plugins.deesComms.DeesComms(); public scroller = new plugins.SweetScroll({ /* some options */ diff --git a/ts/domtools.classes.elementinstrumenter.ts b/ts/domtools.classes.elementinstrumenter.ts deleted file mode 100644 index c6a19ee..0000000 --- a/ts/domtools.classes.elementinstrumenter.ts +++ /dev/null @@ -1,29 +0,0 @@ -import * as plugins from './domtools.plugins'; -import { LitElement } from 'lit-element'; - -export class ElementInstrumenter { - connectedElements = new plugins.lik.ObjectMap(); - - public instrumentElement(elementArg: LitElement) { - const addToConnectedElementsFunc = (eventArg: CustomEvent) => { - this.connectedElements.add(elementArg); - }; - const removeFromConnectedElementsFunc = eventArg => { - this.connectedElements.remove(elementArg); - elementArg.removeEventListener('domtools-connected', addToConnectedElementsFunc); - elementArg.removeEventListener('domtools-disconnected', removeFromConnectedElementsFunc); - }; - elementArg.addEventListener('domtools-connected', addToConnectedElementsFunc); - elementArg.addEventListener('domtools-disconnected', removeFromConnectedElementsFunc); - - if (elementArg.parentElement) { - this.connectedElements.add(elementArg); - } - } - - public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise) { - for (const elementArg of this.connectedElements.getArray()) { - await eachFuncArg(elementArg); - } - } -} \ No newline at end of file diff --git a/ts/domtools.classes.thememanager.ts b/ts/domtools.classes.thememanager.ts index 6acd781..c37693b 100644 --- a/ts/domtools.classes.thememanager.ts +++ b/ts/domtools.classes.thememanager.ts @@ -8,34 +8,23 @@ export class ThemeManager { public goBrightBoolean = false; public preferredColorSchemeMediaMatch = window.matchMedia('(prefers-color-scheme: light)'); + public themeObservable = new plugins.smartrx.rxjs.ReplaySubject(1); + constructor(domtoolsRefArg: DomTools) { this.domtoolsRef = domtoolsRefArg; - // lets take care of elements being added that need to know of the current theme - this.domtoolsRef.elementInstrumenter.connectedElements.eventSubject.subscribe(async eventData => { - await this.setThemeStatusForElement(eventData.payload, this.goBrightBoolean); - }); - // lets care this.goBrightBoolean = this.preferredColorSchemeMediaMatch.matches; this.preferredColorSchemeMediaMatch.addEventListener('change', eventArg => { this.goBrightBoolean = eventArg.matches; this.updateAllConnectedElements(); }); - } - - private async setThemeStatusForElement (elementArg: LitElement, goBrightBool: boolean) { - const goBright = (elementArg as any).goBright; - if (typeof goBright === 'boolean') { - (elementArg as any).goBright = goBrightBool; - } + this.updateAllConnectedElements(); } private async updateAllConnectedElements() { document.body.style.background = this.goBrightBoolean ? '#fff' : '#000'; - this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => { - await this.setThemeStatusForElement(elementArg, this.goBrightBoolean); - }); + this.themeObservable.next(this.goBrightBoolean); } public goBright() { diff --git a/ts/domtools.elementbasic.ts b/ts/domtools.elementbasic.ts index c10a96a..751cb00 100644 --- a/ts/domtools.elementbasic.ts +++ b/ts/domtools.elementbasic.ts @@ -27,7 +27,8 @@ export const setup = async (elementArg?: LitElement): Promise => { const domTools = await DomTools.setupDomTools(); if (elementArg) { - domTools.elementInstrumenter.instrumentElement(elementArg); + // lets do something with the element + // not used right now } domTools.runOnce('elementBasicSetup', async () => { diff --git a/ts/domtools.plugins.ts b/ts/domtools.plugins.ts index 5b55af9..91be290 100644 --- a/ts/domtools.plugins.ts +++ b/ts/domtools.plugins.ts @@ -14,6 +14,7 @@ export { typedrequest }; import * as smartdelay from '@pushrocks/smartdelay'; import * as smartpromise from '@pushrocks/smartpromise'; import * as smartrouter from '@pushrocks/smartrouter'; +import * as smartrx from '@pushrocks/smartrx'; import * as smartstate from '@pushrocks/smartstate'; import * as webrequest from '@pushrocks/webrequest'; import * as websetup from '@pushrocks/websetup'; @@ -25,7 +26,7 @@ const lik = { ObjectMap }; -export { lik, smartdelay, smartpromise, smartrouter, smartstate, webrequest, websetup, webstore }; +export { lik, smartdelay, smartpromise, smartrouter, smartrx, smartstate, webrequest, websetup, webstore }; // third party scope import SweetScroll from 'sweet-scroll';