This document outlines planned improvements and potential features for the FluentState library.
Dependencies: None
Extend the AutoTransitionConfig interface with more control over transition behavior:
interface AutoTransitionConfig<TContext = unknown> {
condition: (state: State, context: TContext) => boolean | Promise<boolean>;
targetState: string;
// New properties:
priority?: number; // Higher priority transitions are evaluated first
debounce?: number; // Delay evaluation by specified milliseconds
retryConfig?: { // Retry failed transitions
maxAttempts: number;
delay: number;
};
}Benefits:
- Better control over transition order and timing
- Improved handling of race conditions
- Automatic retry for transient failures
User Story: As a developer using FluentState in a complex application, I want to have fine-grained control over how auto-transitions are evaluated and executed, So that I can handle race conditions, prioritize certain transitions, and make my state machine more resilient to transient failures.
Acceptance Criteria:
-
Priority-based Transitions
- When multiple auto-transitions are possible from a state, they are evaluated in order of priority (highest to lowest)
- Transitions with the same priority are evaluated in the order they were defined
- Transitions without a priority value default to priority 0
- Only the first successful transition (highest priority) is executed
-
Debounced Transitions
- When a debounce value is set, the transition evaluation waits for the specified milliseconds after the last context update
- If another context update occurs during the debounce period, the timer resets
- Debounced transitions maintain their priority order when evaluated
- Resources (timers) are properly cleaned up when the state changes or the state machine is destroyed
-
Retry Configuration
- Failed transition attempts (where condition throws an error) are retried up to maxAttempts times
- Each retry attempt waits for the specified delay in milliseconds
- Retries stop immediately if the condition returns false (vs throwing an error)
- Retry attempts are logged for debugging purposes
- The state machine remains responsive to other transitions during retry delays
Example Usage:
// Priority example
fs.from("reviewing")
.to<Document>("approved", {
condition: (_, doc) => doc.approvals >= 2,
priority: 2 // Checked first
})
.to<Document>("rejected", {
condition: (_, doc) => doc.rejections >= 1,
priority: 1 // Checked second
});
// Debounce example
fs.from("typing")
.to<SearchState>("searching", {
condition: (_, state) => state.query.length >= 3,
debounce: 300 // Wait 300ms after last keystroke
});
// Retry example
fs.from("connecting")
.to<ApiState>("connected", {
condition: async (_, state) => {
const response = await checkConnection(state.endpoint);
return response.isConnected;
},
retryConfig: {
maxAttempts: 3,
delay: 1000 // Wait 1 second between attempts
}
});Dependencies: None
Add a system for tracking and querying transition history:
class TransitionHistory {
private history: Array<{
from: string;
to: string;
timestamp: number;
context: unknown;
success: boolean;
}> = [];
add(entry: TransitionHistoryEntry): void;
getLastTransition(): TransitionHistoryEntry | null;
getTransitionsForState(stateName: string): TransitionHistoryEntry[];
clear(): void;
}Benefits:
- Debug complex state flows
- Audit state changes
- Time travel debugging capabilities
- Analytics and monitoring
User Story: As a developer working with complex state machines in FluentState, I want to track and query the history of state transitions, So that I can debug issues, audit state changes, implement time travel debugging, and gather analytics about my application's state flow.
Acceptance Criteria:
-
Transition Recording
- All state transitions are recorded with their source state, target state, timestamp, context data, and success status
- Transitions are stored in chronological order
- Failed transition attempts are also recorded with appropriate success status
- The history can be configured to have a maximum size limit to prevent memory issues
- When the size limit is reached, oldest entries are removed first
-
History Querying
- Developers can retrieve the most recent transition with getLastTransition()
- Developers can query transitions related to a specific state with getTransitionsForState()
- Query results maintain the chronological order of transitions
- The API provides a way to clear the history when needed
-
Integration with State Machine
- Transition history recording is optional and can be enabled/disabled
- History recording has minimal performance impact on the state machine
- The history is accessible through the state machine instance
- History is properly maintained even during complex transition scenarios (e.g., auto-transitions, conditional transitions)
-
Serialization Support
- Transition history can be serialized to JSON for storage or transmission
- Sensitive context data can be filtered during serialization
- Serialized history can be imported back into a TransitionHistory instance
Example Usage:
// Enable history tracking
const machine = new FluentState({
initialState: "idle",
enableHistory: true,
historyOptions: {
maxSize: 100,
includeContext: true
}
});
// Later, query the history
const lastTransition = machine.history.getLastTransition();
console.log(`Last transition: ${lastTransition.from} -> ${lastTransition.to}`);
// Get all transitions involving the "processing" state
const processingTransitions = machine.history.getTransitionsForState("processing");
console.log(`Processing state was involved in ${processingTransitions.length} transitions`);
// Export history for debugging
const serializedHistory = JSON.stringify(machine.history);Dependencies:
- Enhanced Auto-transition Configuration (for proper handling of debounced transitions during batch updates)
- State Manager Performance Optimizations (for batching configuration)
Add support for batching multiple context updates:
// In State class
async batchUpdate<T>(updates: Partial<T>[], options?: {
// Only trigger auto-transitions after all updates are applied
evaluateAfterComplete?: boolean;
// Abort batch if any update fails
atomic?: boolean;
}): Promise<boolean>;Benefits:
- Improved performance for multiple updates
- Atomic updates when needed
- Reduced unnecessary transition evaluations
User Story: As a developer working with FluentState in a performance-sensitive application, I want to batch multiple related context updates together, So that I can optimize state machine performance, ensure atomic operations, and reduce unnecessary state transition evaluations.
Acceptance Criteria:
-
Batch Update API
- The State class provides a
batchUpdatemethod that accepts an array of partial context updates - The method returns a Promise that resolves to a boolean indicating success or failure
- The API maintains type safety with the context type parameter
- Updates are processed in the order they are provided in the array
- The method supports empty update arrays (no-op) and returns true
- The State class provides a
-
Transition Evaluation Control
- When
evaluateAfterCompleteis true, auto-transitions are only evaluated after all updates are applied - When
evaluateAfterCompleteis false (default), auto-transitions are evaluated after each update - During batch updates with
evaluateAfterComplete: true, the state machine remains responsive to manual transitions - If auto-transitions are triggered during batch processing, they respect transition priorities and debounce settings
- When
-
Atomic Update Support
- When
atomicis true, the entire batch fails if any single update fails - When
atomicis true and an update fails, any previously applied updates in the batch are reverted - When
atomicis false (default), updates are applied independently and the method returns true if any updates succeeded - The batch process properly handles errors and provides meaningful error information
- Atomic operations properly clean up any resources used during the process
- When
-
Integration with Existing Features
- Batch updates are properly recorded in transition history when history tracking is enabled
- Batch updates work seamlessly with debounced transitions
- Batch updates respect transition group configurations
- The batching mechanism works with custom equality checking functions
- Performance metrics are available when debugging features are enabled
Example Usage:
// Basic batch update
await machine.currentState.batchUpdate([
{ counter: 1 },
{ status: 'processing' },
{ progress: 0.5 }
]);
// Atomic batch update with evaluation after completion
try {
const success = await machine.currentState.batchUpdate(
[
{ step1: 'complete' },
{ step2: 'complete' },
{ step3: 'complete' }
],
{
evaluateAfterComplete: true,
atomic: true
}
);
if (success) {
console.log('All steps completed successfully');
}
} catch (error) {
console.error('Failed to complete all steps:', error);
}Dependencies:
- Enhanced Auto-transition Configuration (for priority and timing control)
More granular control over when auto-transitions are evaluated:
interface AutoTransitionEvaluationConfig {
// Only evaluate when these context properties change
watchProperties?: string[];
// Skip evaluation if these conditions are met
skipIf?: (context: unknown) => boolean;
// Custom evaluation timing
evaluationStrategy?: 'immediate' | 'nextTick' | 'idle';
}Benefits:
- Better performance through selective evaluation
- More predictable transition behavior
- Optimized for different use cases
User Story: As a developer working with complex state machines in FluentState, I want fine-grained control over when auto-transitions are evaluated, So that I can optimize performance, reduce unnecessary evaluations, and create more predictable state transition behavior.
Acceptance Criteria:
-
Property-based Evaluation Triggering
- Transitions with
watchPropertiesdefined are only evaluated when those specific properties change - Support for deep property paths using dot notation (e.g., 'user.profile.name')
- Support for array notation for indexed properties (e.g., 'items[0].status')
- Proper handling of property additions/deletions, not just value changes
- Performance improvement when many properties exist but only few trigger transitions
- Transitions with
-
Conditional Evaluation Skipping
- When
skipIfreturns true, auto-transition evaluation is completely bypassed - The
skipIffunction receives the full context object for decision making - Skip conditions are evaluated before any transition conditions to avoid unnecessary work
- Skip conditions do not affect manual transitions, only auto-transitions
- Support for multiple skip conditions with composable functions
- When
-
Evaluation Timing Strategies
- 'immediate' strategy evaluates transitions synchronously after context changes (default)
- 'nextTick' strategy defers evaluation to the next event loop tick
- 'idle' strategy uses requestIdleCallback (or polyfill) to evaluate during idle periods
- Strategy selection affects all transitions or can be configured per transition/group
- Appropriate fallbacks for environments without certain timing capabilities
-
Integration with Existing Features
- Compatible with transition priorities from Enhanced Auto-transition Configuration
- Works correctly with debounce settings and properly combines timing effects
- Integrates with transition groups for group-level evaluation configuration
- Evaluation strategies properly reflected in transition history
- Evaluation control properly respects batch update configurations
Example Usage:
// Only evaluate when specific properties change
fs.from("form")
.to<FormState>("valid", {
condition: (_, form) => form.isValid,
evaluationConfig: {
watchProperties: ['values.email', 'values.password']
}
});
// Skip evaluation based on application state
fs.from("idle")
.to<AppState>("loading", {
condition: (_, state) => state.hasQueuedActions,
evaluationConfig: {
skipIf: (state) => state.isOffline || state.isBatteryLow
}
});
// Use idle time for non-critical transitions
fs.from("data")
.to<DataState>("analyzed", {
condition: (_, data) => data.needsAnalysis,
evaluationConfig: {
evaluationStrategy: 'idle' // Process during browser idle time
}
});Dependencies:
- Enhanced Auto-transition Configuration (for group-level configuration inheritance)
Organize related transitions into manageable groups:
class TransitionGroup {
constructor(name: string);
addTransition(from: string, to: string, config?: AutoTransitionConfig): void;
enable(): void;
disable(): void;
isEnabled(): boolean;
}
// Usage example
const uploadFlow = new TransitionGroup('upload');
uploadFlow.addTransition('idle', 'uploading', { /* config */ });
uploadFlow.addTransition('uploading', 'processing', { /* config */ });
fs.addGroup(uploadFlow);Benefits:
- Better organization of complex state machines
- Ability to enable/disable groups of transitions
- Improved maintainability
User Story: As a developer working with complex state machines in FluentState, I want to organize related transitions into logical groups that can be managed collectively, So that I can better structure my application's state flow, enable/disable sets of transitions as a unit, and improve the maintainability of my state machine.
Acceptance Criteria:
-
Group Creation and Management
- ✅ Developers can create transition groups using a fluent API:
fluentState.createGroup('groupName') - ✅ Groups can be chained with additional configuration:
fluentState.createGroup('groupName').withConfig({ priority: 2 }) - ✅ Groups can be retrieved using a fluent method:
fluentState.group('groupName') - ✅ Return
nullor throw a specific error when a group is not found - ✅ The API prevents duplicate group names within the same state machine
- ✅ Groups can be removed using a fluent method:
fluentState.removeGroup('groupName') - ✅ Provide a mechanism to list all available groups:
fluentState.getAllGroups() - ✅ Support for group namespaces or categories (e.g.,
authentication:login,authentication:register) - ✅ Option to initialize groups from a serialized configuration object
- ✅ Developers can create transition groups using a fluent API:
-
Transition Definition and Organization
- ✅ Transitions can be added to a group using a fluent syntax:
group.from('stateA').to('stateB', config) - ✅ Multiple transitions can be chained:
group.from('stateA').to('stateB').or('stateC') - ✅ The group maintains direct references to the original Transition objects rather than recreating them
- ✅ Transitions in a group are properly registered with the FluentState instance
- ✅ Transitions can be removed using a fluent method:
group.removeTransition('stateA', 'stateB') - ✅ When a state is removed from the state machine, any transitions involving that state are automatically removed from all groups
- ✅ Method to check if a specific transition belongs to a group:
group.hasTransition('stateA', 'stateB') - ✅ Support for transition tagging within groups for sub-categorization
- ✅ Transitions can be added to a group using a fluent syntax:
-
Group-level Configuration
- ✅ Group-level configuration can be set using a fluent API:
group.withConfig({ priority: 2, debounce: 300 }) - ✅ Individual transition configurations override group-level configurations when both are specified
- ✅ Configuration options include:
- ✅ Priority levels for all transitions in the group
- ✅ Debounce settings for all transitions in the group
- ✅ Retry configuration for all transitions in the group
- ✅ Support for configuration inheritance between related groups
- ✅ Provide a method to get the effective configuration for a transition:
group.getEffectiveConfig('stateA', 'stateB') - ✅ Support for dynamic configuration that can change based on application state
- ✅ Group-level configuration can be set using a fluent API:
-
Group Enabling/Disabling
- ✅ Groups can be enabled or disabled using fluent methods:
group.enable()andgroup.disable() - ✅ The enabled state can be queried:
group.isEnabled() - ✅ When a group is disabled, none of its transitions are evaluated during auto-transition evaluation
- ✅ When a group is disabled, manual transitions within the group are still possible (unless explicitly prevented)
- ✅ Add an option to also prevent manual transitions when a group is disabled
- ✅ Enabling a previously disabled group immediately makes its transitions available for evaluation
- ✅ The API provides a fluent way to temporarily disable a group:
group.disableTemporarily(duration) - ✅ Provide a restoration callback for when a temporarily disabled group is re-enabled
- ✅ Support for conditionally enabled groups based on a predicate function
- ✅ Groups can be enabled or disabled using fluent methods:
-
Event Handling
- ✅ Groups can have event handlers attached using a fluent API:
- ✅
group.onTransition((from, to) => { /* handler */ }) - ✅
group.onEnable(() => { /* handler */ }) - ✅
group.onDisable(() => { /* handler */ })
- ✅
- ✅ Event handlers receive relevant context about the event (states involved, transition configuration, etc.)
- ✅ Multiple handlers can be chained:
group.onTransition(handler1).onTransition(handler2) - ✅ Add support for removing event handlers:
group.offTransition(handler) - ✅ Add support for one-time event handlers:
group.onceTransition(handler) - ✅ Support for event bubbling between nested groups
- ✅ Add group-level middleware that can intercept and modify transitions
- ✅ Groups can have event handlers attached using a fluent API:
-
Integration with Existing Features
- ✅ Transition groups work seamlessly with the existing transition history feature
- ✅ History entries include the group name for transitions that belong to a group
- ✅ Transition groups are compatible with the debugging and visualization tools
- ✅ Groups can be visualized as clusters in state machine diagrams
- ✅ Support for serialization and deserialization of group definitions
- ✅ Integration with the proposed logging system to provide group-specific logging
-
Nested Groups and Composition
- ✅ Support for defining groups within groups for hierarchical organization
- ✅ Child groups inherit configuration from parent groups unless overridden
- ✅ Enable/disable operations cascade to child groups
- ✅ Provide methods to navigate the group hierarchy:
group.parent(),group.children() - ✅ Support for composition patterns to reuse group definitions across state machines
-
Testing and Debugging Support
- ✅ Provide snapshot capabilities for group state:
group.createSnapshot() - ✅ Provide metrics on group transition frequency and performance
- ✅ Provide snapshot capabilities for group state:
Example Usage:
// Create a group for user authentication flow with fluent API
const authFlow = fluentState.createGroup('authentication')
.withConfig({
priority: 2,
retryConfig: {
maxAttempts: 3,
delay: 1000
}
});
// Add transitions to the group with fluent syntax
authFlow
.from('loggedOut').to('authenticating', {
condition: (_, context) => context.credentials !== null
})
.from('authenticating').to('loggedIn', {
condition: (_, context) => context.isAuthenticated
})
.or('error', {
condition: (_, context) => context.authError !== null
});
// Add event handlers with fluent API
authFlow
.onTransition((from, to) => console.log(`Auth transition: ${from} -> ${to}`))
.onEnable(() => console.log('Auth flow enabled'))
.onDisable(() => console.log('Auth flow disabled'));
// Later, disable the entire authentication flow
fluentState.group('authentication').disable();
// Enable it again when needed
fluentState.group('authentication').enable();
// Temporarily disable for 5 minutes
fluentState.group('authentication').disableTemporarily(5 * 60 * 1000);
// Check if the group is currently enabled
const isAuthFlowEnabled = fluentState.group('authentication').isEnabled();Dependencies: None
Configuration options for optimizing state manager performance:
interface StateManagerConfig<T> {
// Batch multiple rapid state updates
batchUpdates?: boolean;
batchTimeWindow?: number;
// Memoize computed values from state
enableMemoization?: boolean;
// Custom equality function for state updates
areEqual?: (prev: T, next: T) => boolean;
// Performance metrics collection
metrics?: {
enabled: boolean;
// Track update frequency and timing
measureUpdates?: boolean;
// Track memory usage of state
measureMemory?: boolean;
// Track computation time of state derivations
measureComputations?: boolean;
// Callback for metrics reporting
onMetrics?: (metrics: StateManagerMetrics) => void;
};
}
interface StateManagerMetrics {
// Average time between updates
updateFrequency: number;
// Time spent processing updates
updateDuration: number;
// Number of updates in the current time window
updateCount: number;
// Memory usage statistics
memoryUsage?: {
stateSize: number;
memoizedSize: number;
};
// Computation timing
computationDuration?: {
equality: number;
memoization: number;
derivations: number;
};
}Benefits:
- Improved performance for rapid updates
- Memory optimization through memoization
- Custom update detection
- Performance monitoring and optimization insights
- Real-time metrics for debugging and profiling
User Story: As a developer building a performance-critical application with FluentState, I want to optimize how state updates are processed and monitored, So that I can minimize performance bottlenecks, reduce unnecessary re-renders, and gain insights into my application's state management behavior.
Acceptance Criteria:
-
Batched Updates
- Multiple state updates occurring within the configured time window are batched into a single update
- The batchTimeWindow parameter controls how long to wait before processing batched updates
- Batching can be enabled/disabled globally via the batchUpdates configuration option
- Batched updates maintain the same final state as if updates were processed individually
-
Memoization Support
- When enableMemoization is true, derived values from state are cached and only recalculated when dependencies change
- Memoization works with both simple and complex state structures
- Memoized values are properly invalidated when their dependencies change
- Memory usage is optimized by clearing unused memoized values
-
Custom Equality Checking
- Developers can provide a custom areEqual function to determine if state has actually changed
- The custom equality function is used to prevent unnecessary updates when state is structurally equivalent
- Default equality checking uses a shallow comparison for objects and arrays
- Custom equality checking works with all state update methods
-
Performance Metrics
- When metrics.enabled is true, the state manager collects performance data
- Update frequency, duration, and count are tracked when measureUpdates is true
- Memory usage statistics are collected when measureMemory is true
- Computation timing for equality checks, memoization, and derivations is measured when measureComputations is true
- Metrics are provided to the onMetrics callback for custom reporting or visualization
- Metrics collection has minimal impact on overall performance
Example Usage:
// Configure performance optimizations
const machine = new FluentState({
initialState: "idle",
stateManagerConfig: {
batchUpdates: true,
batchTimeWindow: 50, // 50ms batching window
enableMemoization: true,
areEqual: (prev, next) => _.isEqual(prev, next), // Deep equality check
metrics: {
enabled: true,
measureUpdates: true,
measureMemory: process.env.NODE_ENV === 'development',
measureComputations: process.env.NODE_ENV === 'development',
onMetrics: (metrics) => {
console.log('State Manager Metrics:', metrics);
if (metrics.updateFrequency < 16) { // Less than 60fps
console.warn('Performance warning: High update frequency detected');
}
}
}
}
});Dependencies:
- Transition History (for comprehensive debugging capabilities)
- State Manager Performance Optimizations (for performance metrics collection and reporting)
- Transition Groups (for complete state machine visualization)
Comprehensive debugging and development tools:
interface DebugConfig {
// Log detailed transition information
logLevel: 'none' | 'error' | 'warn' | 'info' | 'debug';
// Track performance metrics
measurePerformance?: boolean;
// Save transition history
keepHistory?: boolean;
historySize?: number;
// Export state machine configuration
exportConfig?: () => string;
// Visualize state machine (requires Transition Groups for complete visualization)
generateGraph?: {
format: 'mermaid' | 'dot' | 'svg';
options?: {
// Include transition conditions in the graph
showConditions?: boolean;
// Show transition groups as clusters
groupClusters?: boolean;
// Include state metadata
showMetadata?: boolean;
// Highlight current state
highlightCurrent?: boolean;
// Show transition history
showHistory?: boolean;
// Custom styling
styles?: {
groups?: Record<string, string>;
states?: Record<string, string>;
transitions?: Record<string, string>;
};
};
};
}
// Example visualization output (Mermaid format):
/*
stateDiagram-v2
%% Upload Flow Group
state "Upload Flow" as UploadFlow {
[*] --> idle
idle --> uploading: files.length > 0
uploading --> processing: progress === 100
processing --> complete: isValid
processing --> error: !isValid
}
%% Auth Flow Group
state "Auth Flow" as AuthFlow {
[*] --> login
login --> loading: credentials
loading --> dashboard: validated
loading --> error: !validated
}
*/Benefits:
- Easier debugging of complex state machines
- Performance monitoring
- Better development experience
- Visual state machine representation with:
- Grouped states and transitions
- Transition conditions
- Current state highlighting
- Historical transitions
- Custom styling options
User Story: As a developer building and maintaining complex state machines with FluentState, I want comprehensive debugging and visualization tools, So that I can easily troubleshoot issues, understand state flow, gain performance insights, and communicate state machine architecture to my team.
Acceptance Criteria:
-
Logging and Monitoring
- ✅ Different log levels ('none', 'error', 'warn', 'info', 'debug') can be configured through the logLevel property
- ✅ Detailed information about state transitions, conditions, and context changes are logged at appropriate levels
- ✅ Logs include timestamps, state information, and relevant context data
- ✅ Performance metrics are collected when measurePerformance is enabled
- ✅ Performance data includes transition evaluation time, condition execution time, and context update time
- ✅ Logs can be directed to custom output channels (console, file, custom logger)
- ✅ Log format is customizable to integrate with existing logging systems
-
History Tracking
- ✅ Complete transition history is maintained when keepHistory is enabled
- ✅ History size is configurable through historySize to prevent memory issues
- ✅ History includes source state, target state, timestamp, context data, and metadata
- ✅ History can be queried and filtered by state, time range, or metadata
- ✅ Export functionality for history data in JSON format for external analysis
- ✅ Clear separation between current state management and history tracking to minimize performance impact
-
Configuration Export
- ✅ The exportConfig function produces a complete serialized representation of the state machine
- ✅ Export format includes states, transitions, groups, and configuration settings
- ✅ Exported configuration can be used to recreate an identical state machine
- ✅ Configuration export supports redaction of sensitive information
- ✅ Export function is extensible to support different output formats
-
State Machine Visualization
- ✅ The generateGraph function creates visual representations of the state machine
- ✅ Supported output formats include Mermaid, DOT, and SVG
- ✅ Visualization shows all states, transitions, and their relationships
- ✅ Transition groups are represented as clusters when groupClusters is enabled
- ✅ Transition conditions are displayed when showConditions is enabled
- ✅ Current state is highlighted when highlightCurrent is enabled
- ✅ Historical transitions can be shown when showHistory is enabled
- ✅ State metadata is included when showMetadata is enabled
- ✅ Custom styling can be applied through the styles configuration for groups, states, and transitions
- ✅ Generated visualizations can be used in documentation, presentations, or development tools
-
Developer Experience
- ✅ All debugging features have minimal impact on production performance when disabled
- ✅ Time-travel debugging support through integration with transition history
- ✅ Warning system for potential issues such as unreachable states or conflicting transitions
Example Usage:
// Configure debugging tools
fluentState.debugConfig(config: DebugConfig);
// or
const fs = new FluentState({
initialState: "idle",
debug: {
logLevel: process.env.NODE_ENV === 'development' ? 'debug' : 'error',
measurePerformance: true,
keepHistory: true,
historySize: 100,
exportConfig: () => JSON.stringify(machine.config, null, 2),
generateGraph: {
format: 'mermaid',
options: {
showConditions: true,
groupClusters: true,
highlightCurrent: true,
showHistory: true,
styles: {
groups: {
'authentication': 'fill:#f9f,stroke:#333,stroke-width:2px',
'upload': 'fill:#bbf,stroke:#333,stroke-width:2px'
}
}
}
}
}
});
// Later, generate visualization for documentation
const diagram = fs.debug.generateGraph();
fs.writeFileSync('state-machine.md', diagram);
// Export current configuration
const config = fs.debug.exportConfig();
localStorage.setItem('savedStateMachine', config);
// Analyze transition history
const authFailures = fs.debug.history.filter(entry =>
entry.from === 'authenticating' && entry.to === 'error'
);
console.log(`Auth failures: ${authFailures.length}`);Given the dependencies, here's the revised implementation order:
-
✅ Enhanced Auto-transition Configuration (High)
- Most immediately useful for existing users
- Builds on current functionality
- Required by multiple other features
-
✅ State Manager Performance Optimizations (High)
- Important for applications with frequent updates
- Performance improvements benefit all users
- Required for batch updates
-
✅ Transition History (Medium)
- Required for comprehensive debugging tools
- Foundation for monitoring and analytics
-
✅ Transition Groups (Medium)
- Moved up in priority as it's required for complete debugging tools
- Organizational improvement
- Required for state machine visualization
- Requires enhanced auto-transition configuration
-
✅ Debugging and Development Tools (Medium)
- Critical for adoption and maintenance
- Helps users understand and debug their state machines
- Builds on transition history and groups
- Complete visualization support
- ✅ Batch Context Updates (Medium)
- Performance optimization for specific use cases
- Requires auto-transition configuration and state manager optimizations
- ✅ Conditional Auto-transition Evaluation (Low)
- Advanced optimization
- Requires enhanced auto-transition configuration
All proposed features will:
- Maintain backward compatibility
- Be optional/opt-in
- Build upon existing plugin system
- Follow current API patterns
We welcome contributions to any of these features. Please:
- Open an issue to discuss implementation details
- Follow existing code style and patterns
- Include tests and documentation
- Consider backward compatibility