npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

coaction

v3.1.0

Published

A sleek JavaScript library designed for high-performance and multithreading web apps.

Downloads

931

Readme

coaction

Node CI npm license

English documentation · 中文文档

An efficient and flexible state management library for building high-performance, multithreading web applications.

Coaction uses alien-signals internally for cached getter/computed state, React selector reactivity, and adapter-facing subscriptions. The core package also re-exports the signal primitives for advanced integrations.

Installation

Install it with pnpm:

pnpm add coaction

Usage

import { create } from 'coaction/local';

const store = create((set) => ({
  count: 0,
  get doubleCount() {
    return this.count * 2;
  },
  increment() {
    set(() => {
      this.count += 1;
    });
  }
}));

Core stores are immutable by default. Getters and methods can read through this, but writes to Coaction-owned state must happen inside set() or set((draft) => ...). Direct writes such as this.count += 1 in a store method throw because they bypass the commit path that notifies subscribers, produces patches when enabled, and synchronizes worker/client mirrors in shared mode.

Coaction fixes the public state schema after initialization. A single store cannot add new top-level state keys later, and a slices store cannot add new slice keys or new top-level fields inside a slice. Replacement-style APIs such as apply() may omit a known single-store root key; the public getter remains present and reads as undefined, but no unknown key is promoted into the public module. Slice root keys are stricter and cannot be removed or replaced with non-object values. Keep dynamic data inside an existing object or array field.

Mutable adapters such as MobX, Pinia, and Valtio keep Coaction raw state, public state, and the external mutable runtime synchronized for known schema keys. Coaction still treats its raw/public schema as authoritative: out-of-band unknown properties written directly onto a third-party mutable runtime are not promoted into Coaction state, and adapter-specific docs define whether that external runtime property is pruned, restored, or left to the underlying library.

Accessor getters are cached automatically through the built-in signal runtime. Use get(deps, selector) when you want to declare dependencies manually:

const store = create((set, get) => ({
  count: 0,
  doubleCount: get(
    (state) => [state.count],
    (count) => count * 2
  ),
  increment() {
    set(() => {
      this.count += 1;
    });
  }
}));

Local stores can import signal primitives from coaction/local. Adapter authors use the statically separate coaction/adapter entry:

import { computed, effect, signal } from 'coaction/local';
import { defineExternalStoreAdapter } from 'coaction/adapter';

Adapter and Middleware Utilities

coaction/adapter exports utilities for adapter and middleware authors. These are not needed for normal application state updates, but they are part of the supported integration surface used by the official packages:

  • Mutable adapter helpers: applyMutableAdapterPatches, replaceMutableAdapterState, toMutableAdapterSnapshot, snapshotMutableAdapterPureState, isEqualMutableAdapterSnapshot, getMutableAdapterOwnEnumerableKeys, isMutableAdapterUnsafeKey.
  • Root replacement helpers: createRootReplacementPatches, applyRootReplacementWithPatches.
  • Patch safety helpers: assertSafePatches, sanitizePatches, UnsafePatchPathError.
  • State shape helpers: StateSchemaError, isStateSchemaError, sanitizeReplacementState, sanitizeInitialStateValue, replaceOwnEnumerable.

Runtime mutation paths reject unsafe patch paths before applying state changes. If a store.patch() hook returns a path containing __proto__, prototype, or constructor, Coaction throws UnsafePatchPathError instead of silently dropping that patch and applying the rest.

Shared JSON contract

Import create from coaction/shared when state crosses a Worker, SharedWorker, or injected transport boundary:

import { create } from 'coaction/shared';

Shared state, action arguments, action results, patch values, and full-sync snapshots must be JSON trees: finite numbers, strings, booleans, null, dense arrays, and plain records. Coaction rejects values that JSON would normalize or cannot represent losslessly, including undefined, BigInt, NaN, infinity, negative zero, functions in data, symbols, accessors, platform objects, sparse arrays, circular references, and repeated object references. Local stores do not inherit this restriction.

An authority and every connected client must use the same Coaction major and wire protocol. Mixed-major shared deployments are unsupported.

Store methods using this are rebound to the latest state when invoked from getState(), so destructuring remains safe:

const store = create((set) => ({
  count: 0,
  increment() {
    set(() => {
      this.count += 1;
    });
  }
}));

const { increment } = store.getState();
increment();

API Reference

Store Shape Mode (sliceMode)

create() uses sliceMode: 'auto' by default. For backward compatibility, auto still treats a non-empty object whose enumerable values are all functions as slices. That shape is ambiguous with a plain store that only contains methods, so development builds warn and you should set sliceMode explicitly.

You can force behavior explicitly:

  • sliceMode: 'single': treat object input as a single store.
  • sliceMode: 'slices': require object-of-slice-functions input.
create({ ping: () => 'pong' }, { sliceMode: 'single' });
create({ counter: (set) => ({ count: 0 }) }, { sliceMode: 'slices' });

Documentation

You can find the documentation here.