And only for the pleasure , here is a case when using a library worth it :-)
<div class="my-chrono"></div> <div class="my-chrono"></div> <div class="my-chrono"></div> <div class="my-chrono"></div> <div class="my-chrono"></div> <div class="my-chrono"></div>
import {define} from 'wicked-elements'; let Counter = function () { let count = 0; let disabled = false; let timer; let start = () => {timer = setInterval(() => { count += 1; disabled = true; m.redraw()}) }; let stop = () => {clearInterval(timer); disabled = false; m.redraw()}; let reset = () => {stop(); count = 0}; let disable = (status) => status; let view = () => [ m(".wrap", m("h1", count ), m("", m("button", {onclick : start, disabled : disabled}, "start"), m("button", {onclick : stop}, "stop"), m("button", {onclick : reset}, "reset") ) ) ] return { view } } function renderComp(target, component) { m.mount(target, component); } define(".my-chrono", { init() { renderComp(this.element, Counter); } })
You can test it here :
MulipleCounters
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
And only for the pleasure , here is a case when using a library worth it :-)
You can test it here :
MulipleCounters