Installation
Package Information
- Version: 0.1.3
- License: MIT OR Apache-2.0
- Repository: github:moq-dev/moq
- Dependencies:
dequal(for deep equality checks)
Overview
Signals provide a reactive programming model where state changes automatically trigger dependent computations and side effects.Key Features
- Reactive: Automatically track dependencies and rerun effects
- Safe: Prevents common pitfalls like infinite loops
- Efficient: Uses microtasks and deep equality checks
- Type-safe: Full TypeScript support
- Framework adapters: React and Solid.js integrations
Core Concepts
Signal
ASignal is a container for a reactive value:
Effect
AnEffect automatically reruns when signals it depends on change:
Signal API
Creating Signals
Reading Values
Setting Values
Subscribing to Changes
One-time Notifications
Watch (Subscribe + Initial Value)
Racing Signals
Effect API
Creating Effects
Reading Signals
Setting Signals
Cleanup Functions
Nested Effects
Async Operations
Timers
Event Listeners
Animation Frames
Advanced Patterns
Computed Values
Conditional Dependencies
Multiple Signal Dependencies
Framework Integrations
React
Solid.js
Best Practices
Always Clean Up
Avoid Infinite Loops
Use Mutations for Objects
Next Steps
@moq/lite
See signals used in the MoQ protocol
@moq/watch
Signals power the watch component
@moq/publish
Signals power the publish component
Examples
See more examples in the repository