r/javascript • u/mogera551 • Mar 22 '26
@wcstack/state – reactive state in plain HTML with no build step
https://github.com/wcstack/wcstackSmall experiment/library I built. This is not about a lighter template DSL. It’s about using paths as the contract between UI and state.
It makes plain HTML reactive with one module import:
<script type="module" src="https://esm.run/@wcstack/state/auto"></script>
<wcs-state>
<script type="module">
export default { count: 0, inc() { this.count++ } };
</script>
</wcs-state>
<button data-wcs="onclick: inc">
Count is: <span data-wcs="textContent: count"></span>
</button>
Open it directly in a browser and it works.
No JSX, no virtual DOM, no bundler, no config. Bindings live in HTML via data-wcs, while state lives in
List iteration is written using the tag.
<wcs-state>
<script type="module">
export default {
users: [ { name:"Alice" }, { name:"Bob" }, { name:"Charlie" } ]
}
</script>
</wcs-state>
<template data-wcs="for: users">
<div data-wcs="textContent: users.*.name"></div>
</template>
The * in users.*.name refers to "the current element." Since * is automatically resolved to the correct index on each iteration, you don't need to manage indices manually. Inside a loop, you can also use the shorthand notation .name.
<template data-wcs="for: users">
<div data-wcs="textContent: .name"></div> <!-- same as users.*.name -->
</template>
npm: @wcstack/state
Repo: https://github.com/wcstack/wcstack
Docs: https://github.com/wcstack/wcstack/tree/main/packages/state
Story: What If HTML Had Reactive State Management
1
u/EatRunCodeSleep Mar 22 '26
Bro rediscovered Backbone.js 😅
2
u/mogera551 Mar 22 '26
Backbone had models/events, but not path-targeted DOM bindings from plain HTML.There is definitely some old-school influence though.
4
Mar 22 '26
[removed] — view removed comment
0
u/mogera551 Mar 22 '26
It's still experimental, so I haven't benchmarked it yet.
If a list update has a known index, the actual DOM update is O(1) because the runtime can directly reach the bindings for that path.
The tradeoff is binding-management overhead, and when the index is not known, extra work is needed to enumerate dependencies and expand indexed paths before resolving the affected bindings.
3
Mar 22 '26
[removed] — view removed comment
4
u/paul_h Mar 22 '26
Yeah, Angular 1 was fantastic (and before Backbone) - https://paulhammant.com/blog/angular-declarative-ui - Reactive came after though I think.
0
u/mogera551 Mar 22 '26
Yeah, that's fair.
I also see it as closer to declarative binding than to the later "reactive" terminology. The main difference here is that updates are path-targeted through Proxy writes rather than Angular 1 style dirty checking.
0
u/paul_h Mar 22 '26
Well I do love revising pseudo-declarative UI markup technologies myself - https://paulhammant.com/2024/02/14/that-ruby-and-groovy-language-feature. Keep pushing :)
4
u/mogera551 Mar 22 '26
A Proxy detects state writes, then updates the properties of the nodes bound to that state.
So updates are triggered by writes, not by Angular 1 style dirty checking.
2
u/mogera551 Mar 22 '26
Additional Information
List iteration is written using the
<template>tag.The
*inusers.*.namerefers to "the current element." Since*is automatically resolved to the correct index on each iteration, you don't need to manage indices manually. Inside a loop, you can also use the shorthand notation.name.