Skip to content

[O1] Reactive State Container #388

@cjpillsbury

Description

@cjpillsbury

Description

Build the foundational reactive state management system based on the spike implementation. This is a lightweight state container with patch() for updating state, subscribe() for reactive listeners, batched updates via microtask flush, and immutable state snapshots. This is the #1 priority item - everything else depends on it.

Acceptance Criteria

  • createState<T>(initial: T): WritableState<T> factory function
  • WritableState interface with current, patch(), subscribe()
  • State updates are immutable (frozen objects)
  • Subscribers are notified on state changes
  • Updates are batched via microtask (queueMicrotask)
  • Multiple patches in same tick only trigger one notification
  • flush() function for manual batching control
  • Type-safe state access and updates
  • Unit tests with ≥80% coverage

Dependencies

Depends on: None - START DAY 1

Blocks: O2, O3, O5, O6, O7, O8, O9, O12, O13, F1-F16 (40+ items)

Technical Notes

Reference: /Users/cpillsbury/dev/experiments/xstate-concepts-experiments/src/vjs/store/state.ts

Key Implementation:

  • Use Object.freeze() for immutable snapshots
  • Use Object.is() for change detection
  • Use queueMicrotask() for batched flush
  • Use Set<StateChange> for subscriber management

Files: packages/spf/src/core/state/create-state.ts, types.ts, tests/create-state.test.ts

Bundle Size Impact

Target: <1KB minified+gzipped (Core primitive, must be tiny)


Parent Epic: #384

Metadata

Metadata

Assignees

Labels

OrchestrationArchitecture & orchestrationP0Critical - Must have for V1size-M8 story pointsspfStream Processing Frameworkwave-1Wave 1: Foundation (Feb 3-10)weekly-accomplishments:2/16/26

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions