Skip to content

Instantly share code, notes, and snippets.

@julienetie
Created May 21, 2022 00:58
Show Gist options
  • Save julienetie/77877ad18928a654ed725bb9200243fd to your computer and use it in GitHub Desktop.
Save julienetie/77877ad18928a654ed725bb9200243fd to your computer and use it in GitHub Desktop.
Anti-framework example
import { pasteInto } from '../../anti-framework.js'
let n = 0
// The view callback prevents conditions and loops and operators at runtime.
const counterView = pasteInto('#root', ({ n }) => `
<button value="-">-</button>
<button value="+">+</button>
<span>${n}</span>
`)
// Below is controller logic Zzz
document.addEventListener('mousedown', ({ target }) => {
if (target.value === '+') n++; if (target.value === '-') n--
counterView({ n })
})
counterView({ n })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment