resig.js
Version:
Universal reactive signal library with complete platform features: signals, animations, CRDTs, scheduling, DOM integration. Works identically across React, SolidJS, Svelte, Vue, and Qwik.
69 lines (68 loc) • 2.12 kB
TypeScript
/**
* State Machine Algebra - State management with algebraic operations
* XState replacement with category-theoretic foundations
*/
import { Effect } from '../core/effect';
export interface State<S, A> extends Effect<A> {
readonly get: () => State<S, S>;
readonly put: (s: S) => State<S, void>;
readonly modify: (f: (s: S) => S) => State<S, void>;
}
/**
* Creates a State effect with state management operations
*/
export declare const state: <S, A>(initialState: S, initialValue: A) => State<S, A> & {
_setState: (s: S) => void;
_setValue: (a: A) => void;
};
/**
* State machine with transitions
*/
export interface StateMachine<S, A> {
readonly state: S;
readonly send: (action: A) => void;
readonly subscribe: (fn: (state: S) => void) => () => void;
readonly getState: () => S;
readonly dispatch: (action: A) => void;
}
/**
* Creates a state machine with reducer-like transitions
*/
export declare const machine: <S, A>(initialState: S, reducer: (state: S, action: A) => S) => StateMachine<S, A>;
/**
* Finite State Machine with explicit states and transitions
*/
export interface FSM<S extends string, A> {
readonly current: S;
readonly send: (action: A) => void;
readonly can: (action: A) => boolean;
readonly subscribe: (fn: (state: S) => void) => () => void;
}
export type Transition<S extends string, A> = {
from: S;
to: S;
on: A;
guard?: () => boolean;
};
/**
* Creates a finite state machine with explicit transitions
*/
export declare const fsm: <S extends string, A>(initialState: S, transitions: Transition<S, A>[]) => FSM<S, A>;
/**
* Natural transformation: State → Signal (lens view)
* Simplified implementation that maps over the value
*/
export declare const lens: <S, A, B>(f: (a: A) => B) => (stateEffect: State<S, A>) => State<S, B>;
/**
* Combines multiple state machines
*/
export declare const combine: <S1, S2, A1, A2>(machine1: StateMachine<S1, A1>, machine2: StateMachine<S2, A2>) => StateMachine<{
m1: S1;
m2: S2;
}, {
type: 'm1';
action: A1;
} | {
type: 'm2';
action: A2;
}>;