Skip to content

alloc/preact-sigma

Repository files navigation

preact-sigma

Purpose

preact-sigma is a typed state-model builder for Preact and TypeScript. It keeps top-level public state reactive, derived reads local to the model, writes explicit through actions, and side effects owned by explicit setup.

Installation

npm install preact-sigma

Quick Example

import { SigmaType } from "preact-sigma";

const Counter = new SigmaType<{ count: number }>("Counter")
  .defaultState({
    count: 0,
  })
  .computed({
    doubled() {
      return this.count * 2;
    },
  })
  .actions({
    increment() {
      this.count += 1;
    },
  });

const counter = new Counter();

counter.increment();

console.log(counter.count); // 1
console.log(counter.doubled); // 2

Documentation Map

About

An exploration in agent-friendly state management using Preact Signals and Immer

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors