๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’

signux

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
s

signux

Reactive state and effect system for TypeScript, inspired by functional programming

1.1.0
latest
Version published
Weekly downloads
6
-50%
Maintainers
1
Weekly downloads
 
Created
Issues
0

๐Ÿงฉ Signux

Minimal reactive primitives for building fine-grained reactivity in JavaScript and TypeScript.
Composable, testable, and framework-agnostic.

โœจ Features

  • โœ… state, computed, and event primitives
  • โœ… pipe(...) for functional reactive composition
  • โœ… Built-in async handling via stateAsync and mapAsync
  • โœ… Small, fast, and tree-shakable
  • โœ… Type-safe and JSDoc-documented

๐Ÿ“ฆ Installation

bun add signux
# or
npm install signux

๐Ÿš€ Usage

Reactive state

import { state } from "signux";

const counter = state(0);

console.log(counter()); // 0

counter
  .on(
    { subscribe: (fn) => setInterval(() => fn(1), 1000) },
    (prev, n) => prev + n,
  )
  .create();

Derived state (computed)

import { computed } from "signux";

const first = state("Ada");
const last = state("Lovelace");

const fullName = computed(() => \`\${first()} \${last()}\`);
console.log(fullName()); // Ada Lovelace

Events

import { event } from "signux";

const click = event<MouseEvent>();
click.subscribe((e) => console.log("Clicked!", e));

๐Ÿงช Async support

stateAsync

import { stateAsync } from "signux";

const user = stateAsync(fetchUser);
user.fetch(1);

const { loading, data, error } = user();

mapAsync operator

import { event } from "signux";
import { mapAsync } from "signux/operators";

const search = event<string>();

const results = search.pipe(mapAsync((query) => fetchResults(query))).toState();

๐Ÿงฉ Operators

Operators are chainable transformations for events and state:

import { map, filter, debounce } from "signux/operators";

const search = event<string>();

const trimmed = search.pipe(
  map((s) => s.trim()),
  filter((s) => s.length > 2),
  debounce(300),
);

Available operators:

  • map
  • filter
  • debounce
  • merge
  • mapAsync

๐Ÿ“š API Summary

  • state<T>() โ€“ create mutable reactive state
  • computed<T>() โ€“ create derived state that auto-tracks dependencies
  • event<T>() โ€“ create an event emitter that can be observed
  • stateAsync(fetcher) โ€“ reactive wrapper for async operations
  • .pipe(...) โ€“ apply transformation operators
  • effect(fn) โ€“ run a reactive side-effect

๐Ÿ›  Type safety

All primitives and operators are fully typed and documented using JSDoc.
IntelliSense works out of the box in TypeScript and modern editors.

๐Ÿงผ Minimal footprint

No proxies. No magic. Just simple reactive building blocks you control.

๐Ÿ“„ License

MIT

FAQs

Package last updated on 19 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts