Skip to content

feat: add beforerestart event hook#125

Merged
rohal12 merged 1 commit into
mainfrom
feat/124-beforerestart-event
Mar 26, 2026
Merged

feat: add beforerestart event hook#125
rohal12 merged 1 commit into
mainfrom
feat/124-beforerestart-event

Conversation

@rohal12

@rohal12 rohal12 commented Mar 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a beforerestart event that fires at the top of restart() before any state reset (variables, PRNG, session, etc.)
  • Host applications can use Story.on('beforerestart', cb) to clean up persistent state (e.g. sessionStorage, IndexedDB) while pre-restart variables are still accessible
  • Follows the existing onStoryInit callback registry pattern

Closes #124

Test plan

  • Callback fires on restart
  • Fires before storyinit (ordering test)
  • Pre-restart variables readable inside callback
  • Fires on every restart
  • Unsubscribe stops future callbacks
  • All 1024 existing tests pass
  • TypeScript compiles clean

🤖 Generated with Claude Code

Fire a `beforerestart` event at the top of restart() before any state
reset, so host applications can clean up persistent state (sessionStorage,
IndexedDB) while pre-restart variables are still accessible.

Usage: Story.on('beforerestart', () => { /* cleanup */ })

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.39.0 (minor bump from v0.38.1)

@rohal12 rohal12 enabled auto-merge March 26, 2026 09:13
@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 77.45% 2721 / 3513
🔵 Statements 76.55% 2982 / 3895
🔵 Functions 68.16% 499 / 732
🔵 Branches 73.76% 1499 / 2032
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/store.ts 79.47% 71.57% 71.73% 81.29% 90, 124, 313-314, 377, 386-389, 420-425, 517, 554, 577-580, 594, 598-601, 613-685
src/story-api.ts 18.83% 9.37% 21.05% 19.31% 162-277, 290-368, 373-378, 391-438, 465-470, 497-532
Generated in workflow #195 for commit fe0866d by the Vitest Coverage Report Action

@rohal12 rohal12 merged commit 6a3fdfe into main Mar 26, 2026
5 checks passed
@rohal12 rohal12 deleted the feat/124-beforerestart-event branch March 26, 2026 09:15
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.

Feature request: beforerestart event hook

1 participant