fix(core): update

This commit is contained in:
Philipp Kunz 2020-12-07 03:13:34 +00:00
parent 94127227a6
commit b60a1bebe0
6 changed files with 9 additions and 49 deletions

View File

@ -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",

View File

@ -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 */

View File

@ -1,29 +0,0 @@
import * as plugins from './domtools.plugins';
import { LitElement } from 'lit-element';
export class ElementInstrumenter {
connectedElements = new plugins.lik.ObjectMap<LitElement>();
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<void>) {
for (const elementArg of this.connectedElements.getArray()) {
await eachFuncArg(elementArg);
}
}
}

View File

@ -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<boolean>(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() {

View File

@ -27,7 +27,8 @@ export const setup = async (elementArg?: LitElement): Promise<DomTools> => {
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 () => {

View File

@ -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';