Skip to content

feat: centralized event emitter with save/load/navigate hooks (#129)#132

Merged
rohal12 merged 12 commits into
mainfrom
feat/event-emitter-hooks
Mar 26, 2026
Merged

feat: centralized event emitter with save/load/navigate hooks (#129)#132
rohal12 merged 12 commits into
mainfrom
feat/event-emitter-hooks

Conversation

@rohal12

@rohal12 rohal12 commented Mar 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds src/event-emitter.ts — a typed centralized event emitter replacing scattered listener arrays across store.ts, action-registry.ts, and story-api.ts
  • Adds 6 new lifecycle hooks: beforesave, aftersave, beforeload, afterload, beforenavigate, afternavigate — enabling host apps to inject behavior around these operations without monkey-patching
  • Simplifies Story.on() to a type-safe thin wrapper delegating to the emitter

BREAKING CHANGE: Story.on('navigate') removed — use Story.on('afternavigate') (same callback signature). afternavigate only fires from explicit navigation (navigate(), goBack(), goForward()), not from loadFromPayload().

Closes #129

Test plan

  • 9 unit tests for the emitter module (on/emit/unsub/order/unknown events/mid-emit safety)
  • 3 tests for beforesave hooks (argument passing, variable injection, undefined slot)
  • 8 tests for beforenavigate/afternavigate (navigate/goBack/goForward/loadFromPayload exclusion/invalid passage)
  • 2 tests for beforeload/afterload (ordering, state restoration)
  • 2 auto-cleanup integration tests (runtime hooks cleaned on restart, startup hooks survive)
  • Existing event migration parity (storyinit, beforerestart, actionsChanged, variableChanged)
  • Full suite: 1059 tests pass, tsc --noEmit clean

🤖 Generated with Claude Code

clem and others added 12 commits March 26, 2026 23:58
…vigate hooks (#129)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… event (#129)

BREAKING CHANGE: Story.on('navigate') removed — use Story.on('afternavigate')
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ntCallback (#129)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Release preview: merging this PR will publish v0.41.0 (minor bump from v0.40.1)

@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.32% 2776 / 3544
🔵 Statements 77.32% 3035 / 3925
🔵 Functions 68.67% 502 / 731
🔵 Branches 74.36% 1514 / 2036
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/action-registry.ts 100% 100% 100% 100%
src/event-emitter.ts 100% 100% 100% 100%
src/index.tsx 0% 0% 0% 0% 22-220
src/store.ts 80.61% 72.72% 70.78% 82.6% 91, 125, 310-311, 374, 383-386, 420-425, 531, 586, 612-615, 629, 633-636, 648-720
src/story-api.ts 30.4% 16.07% 25% 31.88% 76, 181-204, 212-296, 309-387, 403-420, 447-452, 479-514
Generated in workflow #203 for commit 5a64ef6 by the Vitest Coverage Report Action

@rohal12 rohal12 enabled auto-merge March 26, 2026 16:42
@rohal12 rohal12 merged commit 11421f1 into main Mar 26, 2026
5 checks passed
@rohal12 rohal12 deleted the feat/event-emitter-hooks branch March 26, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save/load/navigate hooks to replace monkey-patching Story methods

1 participant