Skip to content

Instantly share code, notes, and snippets.

@lhorie
Last active March 24, 2022 02:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhorie/496e564427f704ebdd0f8cd18403ebbe to your computer and use it in GitHub Desktop.
Save lhorie/496e564427f704ebdd0f8cd18403ebbe to your computer and use it in GitHub Desktop.
Friday Fun: Svelte-like variable reactivity in 7LOC with with Proxy

Friday Fun: Svelte-like variable reactivity in 7LOC with with Proxy

Every once in a blue moon, I like to hack up some crazy toy proof of concept to get away from everyday's stiff serious production-ready coding. This morning, I decided to mess around with an idea of implementing something similar to Svelte's reactive variables, but using pure Javascript.

So here's that godawful eye-bleeding fun hack: a 7-line "svelte" (needless to say, it doesn't do nearly enough to be useful in the real world and breaks just about every best practice rule in the book because why the hell not)

https://codepen.io/lhorie/pen/BaRzgRe

Can you figure out why this works? Any ideas to make it more devilish/clever/insane are welcome :)

@Sequoia
Copy link

Sequoia commented Jul 9, 2021

Why use document.querySelector when you can refer to elements directly by their IDs? 🤓 https://codepen.io/Sequoia/pen/MWmjgzg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment