Patterns
Architectural patterns and best practices for building with Commiq.
These are the v1 docs. They are not maintained.
This page is a verbatim snapshot of the commiq 1.x documentation, kept for people still running 1.x. It is not corrected and not tested against any release. Several pages contain claims that were wrong when written: examples that do not run as printed, sealStore described as read-only when it was not, handledEvent presented as a working subscription pattern when it never matched, and effects described as swallowing only AbortError when they swallowed everything.
Do not treat anything here as a statement about how commiq 2.x behaves.
What changed in 2.0 and how to upgrade · Current documentation
Site search only indexes the current docs. Use the sidebar to browse these pages.
Patterns
These patterns address recurring architectural decisions when building with Commiq. Each one is prescriptive — it reflects how the library is designed to be used and what works well in practice.
Use them as starting points. Copy the code, adapt the names, and apply the structure that fits your project.
Store File Structure
How to organize store files for clarity, testability, and scale.
Typed Command Factories
Replace magic strings with typed factory functions for type-safe command dispatch.
Domain Hooks
Encapsulate store interactions in a clean React hook API.
Async Loading States
A standard approach to async commands with loading and error handling.
Event-Driven Side Effects
Trigger notifications, navigation, and analytics from store events without coupling logic to views.
Real-Time Transports
Integrate WebSockets, Socket.IO, and Server-Sent Events with Commiq stores.
Testing Stores and Hooks
Unit test command handlers, event flows, React hooks, and effects.
Multi-Store Coordination
Coordinate independent stores through an event bus without coupling them directly.
Effects and Cancellation
Structured side effects with lifecycle control using the effects plugin and interruptable commands.
Error Handling and Recovery
Handle command errors, detect invalid commands, and implement retry patterns.
Optimistic Updates
Update state immediately for responsiveness and reconcile on async completion.
State Normalization
Structure store state for collections to simplify lookups, selectors, and updates.
Composing Plugins
Wire multiple plugins on the same store with correct initialization order and cleanup.
Command Validation
Validate command data with guards for business rules and assertions for developer invariants.
Dependency Injection
Provide typed dependencies to command handlers for testability and environment flexibility.
Deferred Cleanup
Guarantee resource cleanup in command handlers using ctx.defer, regardless of success or failure.