Here is an optimised version :-)
import {render, html} from 'uhtml'; const App = (function () { const State = { counter : 0 } function incer () { State.counter += 1; App.redraw() } function view () { return html` <h1>${State.counter}</h1> <button class="counter" onclick=${incer}>INC</button> <input value = "not erased"/>` } function redraw () { render(app, view()) } return { redraw } })() App.redraw()
You can test it here : SSMOPT
And if you want to get a little further
import {render, html} from 'uhtml'; const Header = () => html`<h1>Header</h1>` const Footer = () => html`<h1>Footer</h1>` const Counter = (state, actions) => html` <h1>${state.counter}</h1> <button class="counter" onclick=${actions.inc}>INC</button> <input value = "not erased"/>` const App = (function () { const State = { counter : 0 } const Actions = { inc : () => { State.counter += 1; redraw(); } } function view (s, a) { return html` ${Header()} ${Counter(s, a)} ${Footer()} ` } function redraw () { render(app, view(State, Actions)) } return { redraw } })() App.redraw()
You can test it here IntroSamPattern
Hi @artydev- this is really interesting. I've not heard of the uthml package before. What exactly is it used/needed for vs the original package?
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.
Here is an optimised version :-)
You can test it here : SSMOPT
And if you want to get a little further
You can test it here IntroSamPattern
Hi @artydev- this is really interesting. I've not heard of the uthml package before. What exactly is it used/needed for vs the original package?