fix(core): update
This commit is contained in:
@@ -6,6 +6,8 @@ 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 {
|
||||
virtualViewport: TViewport;
|
||||
@@ -66,8 +68,8 @@ export class DomTools {
|
||||
|
||||
public websetup: WebSetup = new WebSetup({
|
||||
metaObject: {
|
||||
title: 'loading...'
|
||||
}
|
||||
title: 'loading...',
|
||||
},
|
||||
});
|
||||
|
||||
public smartstate = new plugins.smartstate.Smartstate();
|
||||
@@ -83,9 +85,13 @@ export class DomTools {
|
||||
smartdelay: plugins.smartdelay,
|
||||
};
|
||||
|
||||
public scroller: plugins.SweetScroll;
|
||||
|
||||
|
||||
public elementInstrumenter = new ElementInstrumenter();
|
||||
public deesComms = new plugins.deesComms.DeesComms();
|
||||
public scroller = new plugins.SweetScroll({
|
||||
/* some options */
|
||||
}); // TODO: switch to scroller class
|
||||
public themeManager = new ThemeManager(this);
|
||||
|
||||
private actionSetVirtualViewport = this.domToolsStatePart.createAction<TViewport>(
|
||||
async (statePart, payload) => {
|
||||
@@ -99,14 +105,7 @@ export class DomTools {
|
||||
public domReady = plugins.smartpromise.defer();
|
||||
public globalStylesReady = plugins.smartpromise.defer();
|
||||
|
||||
constructor() {
|
||||
// lets care about third party stuff
|
||||
this.domToolsReady.promise.then(() => {
|
||||
this.scroller = new plugins.SweetScroll({
|
||||
/* some options */
|
||||
});
|
||||
});
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
private runOnceTrackerStringMap = new Stringmap();
|
||||
private runOnceResultMap = new FastMap();
|
||||
|
26
ts/domtools.classes.elementinstrumenter.ts
Normal file
26
ts/domtools.classes.elementinstrumenter.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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 originalConnectedCallback = elementArg.connectedCallback;
|
||||
const originalDisconnectedCallback = elementArg.disconnectedCallback;
|
||||
|
||||
elementArg.connectedCallback = () => {
|
||||
this.connectedElements.add(elementArg);
|
||||
originalConnectedCallback.apply(elementArg);
|
||||
};
|
||||
elementArg.disconnectedCallback = () => {
|
||||
this.connectedElements.remove(elementArg);
|
||||
originalDisconnectedCallback.apply(elementArg);
|
||||
};
|
||||
}
|
||||
|
||||
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {
|
||||
for (const elementArg of this.connectedElements.getArray()) {
|
||||
await eachFuncArg(elementArg);
|
||||
}
|
||||
}
|
||||
}
|
28
ts/domtools.classes.thememanager.ts
Normal file
28
ts/domtools.classes.thememanager.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { DomTools } from './domtools.classes.domtools';
|
||||
import * as plugins from './domtools.plugins';
|
||||
|
||||
export class ThemeManager {
|
||||
public domtoolsRef: DomTools;
|
||||
|
||||
constructor(domtoolsRefArg: DomTools) {
|
||||
this.domtoolsRef = domtoolsRefArg;
|
||||
}
|
||||
|
||||
public goBright() {
|
||||
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
|
||||
const goBright = (elementArg as any).goBright;
|
||||
if (typeof goBright === 'boolean') {
|
||||
(elementArg as any).goBright = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public goDark() {
|
||||
this.domtoolsRef.elementInstrumenter.forEachelement(async elementArg => {
|
||||
const goBright = (elementArg as any).goBright;
|
||||
if (typeof goBright === 'boolean') {
|
||||
(elementArg as any).goBright = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -2,7 +2,7 @@ import * as plugins from './domtools.plugins';
|
||||
import { DomTools } from './domtools.classes.domtools';
|
||||
import { scrollBarStyles } from './domtools.css.theme';
|
||||
|
||||
import { html } from 'lit-element';
|
||||
import { html, LitElement } from 'lit-element';
|
||||
|
||||
/**
|
||||
* styles to be included in every webcomponent
|
||||
@@ -22,8 +22,13 @@ export const styles = html`
|
||||
* a basic setup for elements
|
||||
* makes sure everything is in check
|
||||
*/
|
||||
export const setup = async (): Promise<DomTools> => {
|
||||
export const setup = async (elementArg?: LitElement): Promise<DomTools> => {
|
||||
const domTools = await DomTools.setupDomTools();
|
||||
|
||||
if (elementArg) {
|
||||
domTools.elementInstrumenter.instrumentElement(elementArg);
|
||||
}
|
||||
|
||||
domTools.runOnce('elementBasicSetup', async () => {
|
||||
// bodyStyles
|
||||
domTools.setGlobalStyles(`
|
||||
|
@@ -19,7 +19,13 @@ import * as webrequest from '@pushrocks/webrequest';
|
||||
import * as websetup from '@pushrocks/websetup';
|
||||
import * as webstore from '@pushrocks/webstore';
|
||||
|
||||
export { smartdelay, smartpromise, smartrouter, smartstate, webrequest, websetup, webstore };
|
||||
// subscope lik
|
||||
import { ObjectMap } from '@pushrocks/lik/dist_ts/lik.objectmap';
|
||||
const lik = {
|
||||
ObjectMap
|
||||
};
|
||||
|
||||
export { lik, smartdelay, smartpromise, smartrouter, smartstate, webrequest, websetup, webstore };
|
||||
|
||||
// third party scope
|
||||
import SweetScroll from 'sweet-scroll';
|
||||
|
Reference in New Issue
Block a user