Christopher R. Bilger
January 14th, 2026
| Observer | Purpose | Trigger |
|---|---|---|
| FreshpaintAnalyticsObserver | Track screen views and terminations | Every navigation |
| DatadogObserver | RUM tracking and performance monitoring | Every navigation |
| ConsoleLogObserver | Development debugging (non-prod only) | Every navigation |
| ReduxPersistorObserver | Control state persistence timing | Specific screens |
| ProgressObserver | Calculate and track assessment progress | Step screens |
| DocumentUpdateObserver | Update database on termination | Terminations |
Flow: User Action → Context → State → Strategy → Handlers → Observers → Result
Manages flow behavior (Normal, Interrupted, Terminal)
Screen-specific navigation logic
Composable validation handlers
Decoupled side effects (analytics, logging)
Result: Behavior changes without conditionals, isolated testable components
abstract class BaseNavigationHandler {
private nextHandler: INavigationHandler | null = null;
setNext(handler: INavigationHandler) { this.nextHandler = handler; }
protected next(context) { return this.nextHandler?.handle(context); }
}
class AgeValidationHandler extends BaseNavigationHandler {
handle(context: NavigationContext) {
if (isUnder18 && context.isGuardian === false) {
return this.terminate(Screens.MinorTermination);
}
return this.next(context); // Continue chain
}
}
// Chain handlers together
new AgeValidationHandler()
.setNext(new StateValidationHandler())
.setNext(new GuardianRequirementHandler())
.setNext(new SuicideRiskCheckHandler());
New Screen: Create strategy + register
registry.set(Screens.NewScreen, new NewScreenStrategy());
New Validation: Create handler + chain
chain.setNext(new CustomValidationHandler());
New Side Effect: Create observer + register
stateMachine.addObserver(new CustomObserver());
Analytics, logging, persistence handled automatically
Result: ~98% test coverage of all state machine code
A maintainable, extensible, testable architecture
~98% overall
State machine unit test coverage
+42% assessment
Unit test coverage increase
~75%
Shared between assessments
Zero
Since implementation
Task: Add guardian consent flow for minors
~80% reduction in development time
Four patterns working together created powerful synergy
Migrated screen-by-screen without disruption
Comprehensive tests enabled confident refactoring
Architecture reviews and pair programming accelerated adoption