Skip to main content

State Overview

WikiOnitViewer maintains the simplest state model among all wiki viewers: just one custom array plus inherited properties from the base class.

Sessions Array

The only state property unique to OnIt:
Example Session:

State Lifecycle

Initialization

Toggle Transition

Refresh Cycle

State Dependencies

Path construction depends on three state properties:

Unidirectional Data Flow

State flows in one direction only:

DOM vs JavaScript State

Clear separation between persistent state and ephemeral UI state: JavaScript State (this.*):
  • sessions: OnitSession[] (source of truth)
  • isWip: boolean
  • settings: ViewerSettings
  • Persists across renders
DOM State (in elements):
  • Accordion expanded/collapsed
  • Content loaded (data-loaded)
  • Arrow rotation
  • Scroll position
  • Lost on re-render
Relationship:
  • JS state is source of truth for data
  • DOM state is ephemeral (recreated on render)
  • Re-render regenerates DOM from JS state
  • No two-way binding

State Reset Pattern

Complete replacement on refresh:

Memory Management

Automatic cleanup via garbage collection: On refresh():
  1. this.sessions = new array → Old array becomes unreachable
  2. Container content replaced → Old DOM nodes removed
  3. JavaScript GC cleans up old arrays
  4. Browser GC cleans up old DOM nodes
  5. Event listeners on old nodes auto-removed
No manual cleanup needed. No memory leaks from orphaned listeners.

Settings Management

User preferences loaded from localStorage:

State Comparison

OnIt has the simplest state model: Minimal state aligns with SMPC: simplicity over complexity.
THE CENTER
Simple state enables predictable behavior

Technical Credibility

Single source of truth pattern. Unidirectional data flow. TypeScript type safety via interfaces. Automatic garbage collection for memory management. No manual listener cleanup required.