Skip to content

Patterns

This section contains comprehensive code patterns and implementation guides for the Context-Action framework.

Core Framework Patterns

Action Patterns

Store Patterns

  • Store Patterns - Type-safe state management (Recommended)
    • Basic Usage - Fundamental Store Only pattern with type inference
    • HOC Pattern - Higher-Order Component pattern for automatic Provider wrapping
    • Advanced Config - Performance optimization and custom comparison strategies

Ref Patterns

  • Ref Patterns - Direct DOM manipulation with zero re-renders and context singleton management
    • Basic Usage - Fundamental RefContext pattern with type-safe ref management
    • Context Singleton Handling - Managing context singletons and external resources with lazy evaluation
    • Multi-Context - Multiple RefContext composition for complex applications
    • Performance - Hardware acceleration and performance optimization

Architecture Patterns

Async Patterns

Performance Patterns

Debug Patterns

Quick Start Guide

PatternUse CaseImportBest For
🎯 Action OnlyAction dispatching with memory managementcreateActionContextEvent systems, command patterns, large applications
🏪 Store OnlyState management without actionscreateStoreContextPure state management, data layers
🔧 Ref Context (Advanced)Direct DOM manipulation and singleton object managementcreateRefContextHigh-performance UI, animations, external services

Note: For complex applications, compose patterns together for maximum flexibility and separation of concerns.

Usage Guidelines

Each pattern includes:

  • Best practices with working examples
  • Common pitfalls to avoid
  • 🎯 Use cases for when to apply the pattern
  • Performance considerations and optimization tips

Architecture Decision Guide

Single Domain Applications

  1. Simple Apps: Start with Store Only Pattern
  2. Interactive Apps: Add Action Only Pattern for business logic
  3. High-Performance Apps: Add RefContext Pattern (Advanced) for animations
  4. Complex Apps: Use MVVM Architecture for perfect layer separation

Multi-Domain Applications

  1. Team Boundaries: Use Domain Context Architecture for business separation
  2. Combined Approach: Apply MVVM Architecture within each business domain
  3. Enterprise Scale: Combine all patterns with proper domain isolation

Pattern Integration

These patterns can be combined for complex scenarios:

  • Action Only + Store Only for complete business logic separation
  • RefContext + Store Only for high-performance state-driven animations
  • Core + Advanced Patterns + Domain Architecture for enterprise applications
  • MVVM Architecture for perfect architectural layer separation

Released under the Apache-2.0 License.