Skip to content

alloc/preact-sigma

Repository files navigation

preact-sigma

Purpose

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

Installation

npm install preact-sigma @preact/signals immer preact

Quick Example

import { Sigma } from "preact-sigma";

type CounterState = { count: number };

class Counter extends Sigma<CounterState> {
  constructor() {
    super({
      count: 0,
    });
  }

  get doubled() {
    return this.count * 2;
  }

  increment() {
    this.count += 1;
  }
}

interface Counter extends CounterState {}

const counter = new Counter();

counter.increment();

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

Documentation Map

About

Reactive, class-based models for Preact: Immutability, transparent signals, isolated writes, optional persistence – Powered by immer and @preact/signals

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors