UNPKG

@dooboostore/dom-render

Version:
68 lines (67 loc) 1.89 kB
import { ComponentBase } from "../ComponentBase.js"; import { DomRender } from "../../DomRender.js"; import { RawSet } from "../../rawsets/RawSet.js"; var Timer; ((_Timer) => { _Timer.selector = "dr-timer"; class Timer2 extends ComponentBase { async onInitRender(param, rawSet) { await super.onInitRender(param, rawSet); this.getAttribute("onCreated")?.(this); } isRunning() { return this.value !== void 0; } start() { const timems = this.getAttribute("value"); if (timems) { this.value = parseInt(timems); const intervalValue = this.getAttribute("interval") ?? 1e3; console.log("int", this.value, intervalValue); this.interval = setInterval(() => { if (this.value) { this.value--; } else { clearInterval(this.interval); this.value = void 0; this.interval = void 0; } }, intervalValue); } } stop() { if (this.interval) { clearInterval(this.interval); this.interval = void 0; this.value = void 0; } } onChangeAttrRender(name, val, other) { super.onChangeAttrRender(name, val, other); console.log("-----", name, val, this.getElement()); } onDestroyRender(data) { super.onDestroyRender(data); if (this.interval) { clearInterval(this.interval); } } } _Timer.Timer = Timer2; })(Timer || (Timer = {})); var Timer_default = { timer: (config) => { return RawSet.createComponentTargetElement({ name: `${Timer.selector}`, template: "#innerHTML#", objFactory: (e, o, r2, counstructorParam) => { return DomRender.run({ rootObject: new Timer.Timer(...counstructorParam), config }); } }); } }; export { Timer, Timer_default as default }; //# sourceMappingURL=Timer.js.map