Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Created September 30, 2019 18:13
Show Gist options
  • Save mikaelbr/b58116500717aa911dad338303488077 to your computer and use it in GitHub Desktop.
Save mikaelbr/b58116500717aa911dad338303488077 to your computer and use it in GitHub Desktop.
const { button } = createUiFramework();
let initialState = { counter: 0 };
// Our application taking a state.
function app(state) {
// When we click on the button, rerender with new state where the counter is incremented
const onClick = () => render(app, { ...state, counter: state.counter + 1 });
return button({ type: "button", onClick }, `Increment ${state.counter}!`);
}
// Render function similar to React.
function render(fn, s) {
// Empty body, just to illustrate a point. Shouldn't be used in production.
document.body.innerHTML = "";
// Re-add our components with state.
document.body.appendChild(fn(s));
}
// Do initial render
render(app, initialState);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment