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

@topojs/core

v0.2.5

Published

Core runtime for TopoJS — statespace, nodes, edges, cycle detection and propagation

Readme

@topojs/core

Runtime engine for TopoJS — statespace, nodes, edges, cycle detection, and propagation.

Installation

npm install @topojs/core

Overview

@topojs/core is the foundation of the TopoJS state management library. It models state as a directed graph (nodes + edges) rather than a tree, enabling explicit dependency declarations and automatic propagation between nodes.

API

statespace(name, definition)

Creates a RuntimeStatespace — the main runtime object.

import { statespace, node, derives, requires, influencedBy, triggers } from '@topojs/core';

const CartSpace = statespace('Cart', {
  nodes: {
    items: node({ initial: [] }),
    discount: node({ initial: 0 }),
    total: node({ initial: 0 }),
    canCheckout: node({ initial: false }),
  },
  topology: {
    total: derives(['items', 'discount'], (items, discount) => {
      const sum = (items as number[]).reduce((a, b) => a + b, 0);
      return sum - (discount as number);
    }),
    canCheckout: requires(['total > 0']),
  },
  constraints: {
    noCyclesThrough: ['total'],
  },
});

Edge constructors

| Constructor | Description | | ------------------------------------------ | ----------------------------------------------- | | derives(dependencies, compute, options?) | Sync or async derivation from other nodes | | requires(conditions) | Boolean composition from condition strings | | influencedBy(sources, options?) | Eventual-consistency event (emits influenced) | | triggers(target, effect) | One-way side effect |

node(definition)

Helper to define a node with full type inference.

node({
  initial: 0,
  validate: (v) => v >= 0,
  middleware: [(value, prev) => Math.max(0, value)],
  persist: true,
});

RuntimeStatespace

The object returned by statespace().

space.get<T>(path); // read a value
space.set<T>(path, value); // write and propagate
space.update<T>(path, updater); // functional update
space.subscribe(path, callback); // subscribe to changes (returns unsubscribe)
space.subscribeEvent(type, callback); // subscribe to topology events
space.dependsOn(path); // upstream dependencies
space.affects(path); // downstream dependents
space.updateOrder(path); // topological propagation order
space.getState(); // snapshot of the full state

Topology events

space.subscribeEvent('influenced', ({ path, sources }) => { ... });
space.subscribeEvent('slow-propagation', ({ path, ms }) => { ... });
space.subscribeEvent('cycle-detected', ({ cycle }) => { ... });

Constraints

constraints: {
  noCyclesThrough: ['nodeName'],        // throw if a cycle passes through these nodes
  strongConsistency: ['nodeName'],      // reserved for future use
  maxFanout: { nodeName: 5 },           // max downstream dependents
  maxDepth: 10,                         // max propagation depth
}

Propagation rules

  • derives — recomputes synchronously (or asynchronously via Promise) whenever any dependency changes.
  • requires — evaluates condition strings like 'total > 0' and writes a boolean.
  • influencedBy — emits an influenced event without updating state directly.
  • triggers — calls an effect function; if it returns a value, that value is written to the target node.

Propagation depth is capped at 100 levels to prevent infinite loops.

Requirements

  • Node.js >= 20

License

MIT