1.6.24 • Published 4 months ago

dagify v1.6.24

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Dagify Core API

Dagify is a reactive dependency graph library designed for powerful state management and reactive computation. This guide covers the core API for creating and managing reactive nodes, graphs, and composites.

Extensive documentation is coming soon for all the node types that exist. For now check out the tests for advanced stuff.

Installation

npm install dagify

Basic Usage

1. Creating a Node

Use createNode to create a reactive node that can hold and update a value.

Example

import { createNode } from 'dagify';

// Create a simple reactive node
const node = createNode(10);

// Subscribe to changes
node.subscribe(value => {
  console.log('Node value:', value);
});

// Update the node value
node.set(20);

2. Creating a Computed Node

You can create nodes that depend on other nodes and automatically recompute when dependencies change.

Example

import { createNode } from 'dagify';

// Create base nodes
const a = createNode(2);
const b = createNode(3);

// Create a computed node that reacts to changes in `a` and `b`
const sum = createNode(([a, b]) => a + b, [a, b]);

// Subscribe to the computed node
sum.subscribe(value => {
  console.log('Sum:', value);
});

// Change values and trigger recomputation
a.set(5); // Sum will automatically update to 8

3. Creating a Graph

Use createGraph to initialize a reactive dependency graph for managing multiple interconnected nodes.

Example

import { createGraph, createNode } from 'dagify';

// Create a new graph
const graph = createGraph();

// Add nodes to the graph
const nodeA = createNode(10);
const nodeB = createNode(20);
const nodeSum = createNode(([a, b]) => a + b);

graph.addNodes([nodeA, nodeB, nodeSum]);
graph.connect([nodeA, nodeB], nodeSum);

// Subscribe to the sum node
nodeSum.subscribe(value => {
  console.log('Graph sum:', value);
});

// Trigger an update
nodeA.set(30);

4. Creating a Composite

Use createComposite to group multiple nodes together and emit a combined value when any of them change.

Example (Object Mode)

import { createNode, createComposite } from 'dagify';

// Create individual nodes
const width = createNode(100);
const height = createNode(200);

// Create a composite node
const dimensions = createComposite({ width, height });

// Subscribe to composite changes
dimensions.subscribe(({ width, height }) => {
  console.log(`Dimensions: ${width}x${height}`);
});

// Update width
width.set(150);

Example (Array Mode)

const color1 = createNode('red');
const color2 = createNode('blue');

const palette = createComposite([color1, color2]);

palette.subscribe(colors => {
  console.log('Current palette:', colors);
});

// Change a color
color2.set('green');

License

MIT License © 2025 Zachary Griffee

1.6.17

4 months ago

1.6.19

4 months ago

1.6.18

4 months ago

1.6.20

4 months ago

1.6.22

4 months ago

1.6.21

4 months ago

1.6.24

4 months ago

1.6.23

4 months ago

1.6.4

4 months ago

1.6.3

4 months ago

1.6.1

4 months ago

1.6.0

4 months ago

1.6.11

4 months ago

1.6.13

4 months ago

1.6.12

4 months ago

1.6.15

4 months ago

1.6.14

4 months ago

1.6.16

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.6.9

4 months ago

1.6.8

4 months ago

1.6.7

4 months ago

1.6.6

4 months ago

1.6.5

4 months ago

1.4.6

4 months ago

1.4.5

4 months ago

1.4.4

4 months ago

1.2.6

5 months ago

1.4.3

4 months ago

1.2.5

5 months ago

1.4.2

4 months ago

1.4.1

4 months ago

1.4.0

4 months ago

1.3.0

5 months ago

1.4.7

4 months ago

1.2.0

5 months ago

1.1.9

5 months ago

1.2.3

5 months ago

1.2.1

5 months ago

1.1.12

5 months ago

1.1.11

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.13

5 months ago

1.1.19

5 months ago

1.1.17

5 months ago

1.1.20

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago