Skip to content

feat(types): sync published types with source StoryAPI#135

Merged
rohal12 merged 1 commit intomainfrom
fix/published-types-sync
Mar 26, 2026
Merged

feat(types): sync published types with source StoryAPI#135
rohal12 merged 1 commit intomainfrom
fix/published-types-sync

Conversation

@rohal12
Copy link
Copy Markdown
Owner

@rohal12 rohal12 commented Mar 26, 2026

Summary

  • Add all missing StoryAPI members to types/index.d.ts: on(), deferRender(), ready(), setNobr(), setCSS(), setTransition(), setNextTransition(), defineMacro(), getMacroRegistry(), registerClass(), getActions(), performAction(), waitForActions(), watch(), unwatch(), random(), randomInt(), config, prng, and storage namespaces
  • Add supporting types: StoryEventMap, StoryEvent, StoryEventCallback, TransitionConfig, WatchOptions, StoryAction, StorageInfo, StorageQuota, MacroDefinition, MacroContext, MacroProps, MacroMetadata
  • Fix visited/hasVisited/rendered/hasRendered to accept optional name arg; fix HistoryMoment/SavePayload to include optional prng field
  • Add src/types-drift-check.ts — compile-time check that fails tsc --noEmit if published and source StoryAPI interfaces diverge

Fixes #134

Test Plan

  • npx tsc --noEmit passes (drift check confirms bidirectional compatibility)
  • npx vitest run — all 1059 tests pass
  • Verify types work for consumers: import type { StoryAPI } from '@rohal12/spindle' exposes all new members

🤖 Generated with Claude Code

…ce StoryAPI

Create src/types-drift-check.ts that asserts bidirectional assignability
between the source StoryAPI and published types/index.d.ts, so any drift
is caught by `npx tsc --noEmit`.

Update types/index.d.ts with all missing supporting types (event map,
transitions, watch options, actions, storage info, macro definition types)
and all missing StoryAPI members (registerClass, defineMacro, storage,
actions, events, triggers, transitions, PRNG, config, deferred render).

Fix existing types: add prng field to HistoryMoment and SavePayload,
make visited/hasVisited/rendered/hasRendered name parameter optional,
add getToggle/getList/getRange to SettingsAPI for structural compatibility.

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.42.0 (minor bump from v0.41.0)

@github-actions
Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.28% 2776 / 3546
🔵 Statements 77.28% 3035 / 3927
🔵 Functions 68.67% 502 / 731
🔵 Branches 74.36% 1514 / 2036
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/types-drift-check.ts 0% 100% 100% 0% 13-15
Generated in workflow #208 for commit d14266f by the Vitest Coverage Report Action

@rohal12 rohal12 enabled auto-merge March 26, 2026 17:35
@rohal12 rohal12 merged commit 2ba68c6 into main Mar 26, 2026
5 checks passed
@rohal12 rohal12 deleted the fix/published-types-sync branch March 26, 2026 17:37
rohal12 added a commit that referenced this pull request Mar 27, 2026
…142)

## Summary

- **Published types sync (#135):** Hand-update `types/index.d.ts` with
~17 missing `StoryAPI` members + compile-time drift-detection test
- **Transient variables (#137):** New `%` sigil for reactive variables
excluded from persistence, routed through tokenizer, expression engine,
store, rendering, and published types
- **Computed + for-loop infinite loop (#140):** Memoize
`ForIteration`/`WidgetBody` local state to prevent infinite reactive
loops when `{computed}` reads `@` locals
- **Computed @-target (#140 reopened):** Extend `{computed}` to accept
`@var` targets that write to per-iteration local scope via
`LocalsUpdateContext`, fixing shared values across `{for}` iterations

## Test plan

- [ ] `npx vitest run` — 1087 tests pass
- [ ] `npx tsc --noEmit` — typecheck clean
- [ ] Verify `{computed @cls = @item.status == 'ok' ? 'green' : 'red'}`
inside `{for}` produces per-iteration values
- [ ] Verify `{computed _cls = ...}` inside `{for}` still works
(last-write-wins, no hang)
- [ ] Verify `{computed @cls = ...}` outside a local scope logs an error

🤖 Generated with [Claude Code](https://claude.com/claude-code)
rohal12 added a commit that referenced this pull request Mar 27, 2026
…143) (#144)

## Summary

- **Performance fix for issue #143**: Extend the `renderNodes` fast path
to skip the micromark + innerHTML pipeline when all text nodes contain
only whitespace (indentation, newlines between HTML tags)
- Eliminates ~97 redundant pipeline calls per render in `{for}` loops
over HTML + macro content, addressing 89% of wall time in Chrome CPU
profiles
- Preserves blank-line (`\n\n`) detection to maintain paragraph
separation semantics

## Also includes (prior work on this branch)

- Published types sync (#135)
- Mutation buffer (#136)
- Transient variables (#137, #138)
- Computed @-target in for-loops (#140)

## Test plan

- [x] 3 new correctness baseline tests for the fast path
- [x] Full test suite passes (1090 tests)
- [x] Type check clean (`tsc --noEmit`)
- [ ] Manual verification: re-profile the 23-item for-loop passage in
Chrome to confirm wall time reduction

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

Published types/index.d.ts missing on(), deferRender(), ready()

1 participant