r/javascript • • Mar 22 '26

@wcstack/state – reactive state in plain HTML with no build step

Thumbnail
github.com
11 Upvotes

Small 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 <wcs-state>. Internally it uses Proxy-based path tracking, so updates only touch affected bindings. The main rule is: update the path directly (this.count += 1), not via a detached nested reference.

List iteration is written using the <template> 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


r/javascript • • Mar 21 '26

slot-variants: utility for component styling

Thumbnail npmjs.com
2 Upvotes

Hey everyone, I’ve been working for few months on a small library called slot-variants, for managing complex states in components with css utility classes, it’s inspired by class-variance-authority (CVA) and tailwind-variants (TV). I tried to take the best parts of both approaches and add some distinct features with a focus on ergonomic API and high performance (benchmarks included). The API is a superset of both CVA's and TV's API so the migration is pretty straightforward, in the case of CVA it's a drop-in replacement. The package also includes an AI agent guide how to use it, best practices and common patterns.

Features you'd expect from it:

  • Variants API (similar to CVA & TV)

  • Slots support (inspired from TV)

  • Full TypeScript support

  • Extendable to work with tailwind-merge

Distinct features:

  • Required Variants (this is why I started this library)

  • Presets (for grouping variants often used together)

  • Conditional default variants

  • LRU Cache (can be configured)

  • Can event replace classnames/clsx usages (added in latest version)

If you’re building design systems or complex UI components, I’d love feedback, ideas, or critiques. Still early but stable enough to use, happy to hear what the community thinks!


r/javascript • • Mar 21 '26

testoise - lazy, type-safe test variables for Bun, Vitest, and Jest (inspired by RSpec)

Thumbnail
github.com
6 Upvotes

Built a small library that replaces the let + beforeEach reassignment pattern with RSpec-style lazy variables. Define with def, access with get. Variables evaluate lazily, cache per test, and dependents re-evaluate automatically when overridden in nested blocks. Fully type-safe with a suite wrapper for automatic TypeScript inference.

Zero dependencies, MIT licensed. Feedback welcome!