Skip to content

Commit a7d58e2

Browse files
Merge pull request #23 from zeixcom/feature/linked-graph
Linked List Based Signal Graph
2 parents f0263c0 + 894490d commit a7d58e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+11642
-13352
lines changed

.ai-context.md

Lines changed: 163 additions & 232 deletions
Large diffs are not rendered by default.

.cursorrules

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,64 @@
1-
# Cause & Effect - Reactive State Management Library
1+
# Cause & Effect - Reactive State Management Primitives
22

33
## Project Type
4-
TypeScript/JavaScript reactive state management library using signals pattern
4+
TypeScript reactive state management primitives library using a unified signal graph
55

66
## Core Concepts
7-
- Signals: Base reactive primitives with .get() method
8-
- State: new State() for primitives/simple values
9-
- Ref: new Ref() for external objects (DOM, Map, Set) requiring manual .notify()
10-
- Computed: new Memo() for derived/memoized values and new Task() for asynchronous computations
11-
- Store: createStore() for objects with reactive properties
12-
- List: new List() for arrays with stable keys and reactive items
13-
- Collection: Interface for reactive collections (DerivedCollection, ElementCollection)
14-
- Effects: createEffect() for side effects
7+
- Signals: Reactive primitives with .get() method for dependency tracking
8+
- State: createState() for mutable source values
9+
- Sensor: createSensor() for external input with lazy lifecycle
10+
- Memo: createMemo() for synchronous memoized derivations
11+
- Task: createTask() for asynchronous derivations with cancellation
12+
- Store: createStore() for reactive objects with per-property signals
13+
- List: createList() for reactive arrays with stable keys
14+
- Collection: createCollection() for reactive collections (external source or derived, item-level memoization)
15+
- Effect: createEffect() for side-effect sinks
1516

1617
## Code Style
1718
- Use const for immutable values
1819
- Generic constraints: T extends {} (excludes null/undefined)
1920
- Factory functions: create* prefix
20-
- Type predicates: is* prefix
21+
- Type predicates: is* prefix
2122
- Constants: TYPE_* or UPPER_CASE
2223
- Pure functions marked with /*#__PURE__*/ comment
2324

2425
## Key Patterns
2526
- All signals have .get() method
2627
- Mutable signals have .set(value) and .update(fn)
27-
- Store properties auto-become reactive signals
28-
- Computed callbacks receive oldValue as first parameter for reducer patterns
29-
- Async computed and effect callbacks receive AbortSignal for async cancellation
30-
- Use UNSET symbol for uninitialized states
31-
- Batch updates for performance
32-
- JSDoc comments on all public APIs
28+
- Store properties auto-become reactive signals via Proxy
29+
- Memo callbacks receive previous value as first parameter for reducer patterns
30+
- Task callbacks receive (next, AbortSignal)
31+
- Sensor and Collection use start callbacks for lazy resource management
32+
- Store and List support optional watched callbacks
33+
- batch() for grouping multiple updates
34+
- untrack() for reading signals without creating edges
3335

3436
## File Structure
35-
- src/signal.ts - Base signal types
36-
- src/classes/state.ts - Mutable state signals
37-
- src/classes/ref.ts - Signal wrappers for external objects
38-
- src/classes/store.ts - Object stores
39-
- src/classes/list.ts - Array stores with stable keys
40-
- src/classes/collection.ts - Collection interface and DerivedCollection
41-
- src/classes/computed.ts - Computed signals
42-
- src/effect.ts - Effect system
43-
- src/system.ts - Core reactivity (watchers, batching)
44-
- index.ts - Main exports
45-
46-
## Error Handling
37+
- src/graph.ts - Core reactive engine (nodes, edges, propagation, flush)
38+
- src/nodes/state.ts - Mutable state signals
39+
- src/nodes/sensor.ts - External input tracking
40+
- src/nodes/memo.ts - Synchronous derived signals
41+
- src/nodes/task.ts - Asynchronous derived signals
42+
- src/nodes/effect.ts - Side-effect system
43+
- src/nodes/store.ts - Reactive objects
44+
- src/nodes/list.ts - Reactive arrays with stable keys
45+
- src/nodes/collection.ts - Externally-driven and derived collections
46+
- next.ts - Public API exports
47+
48+
## Error Handling
4749
- Custom error classes in src/errors.ts
48-
- Validate inputs, throw descriptive errors
49-
- Support AbortSignal in async operations
50+
- Validate inputs with validateSignalValue() and validateCallback()
51+
- AbortSignal integration for async cancellation in Task and Collection
5052

5153
## Performance
52-
- Use Set<Watcher> for subscriptions
53-
- Shallow equality with isEqual() utility
54-
- Tree-shaking friendly code
55-
- Minimize effect re-runs
54+
- Linked-list edges for O(1) dependency tracking
55+
- Flag-based dirty checking (CLEAN, CHECK, DIRTY)
56+
- Tree-shaking friendly, zero dependencies
57+
- Minimize effect re-runs via equality checks
58+
59+
## Testing
60+
- bun:test with describe/test/expect
61+
- Test files: test/*.test.ts
5662

5763
## Build
5864
- Bun build tool and runtime

0 commit comments

Comments
 (0)