Skip to content

Refactor element state model to support reactive framework integration#85

Merged
spaansba merged 13 commits intomainfrom
refactor-reactive-api
Apr 26, 2026
Merged

Refactor element state model to support reactive framework integration#85
spaansba merged 13 commits intomainfrom
refactor-reactive-api

Conversation

@spaansba
Copy link
Copy Markdown
Owner

@spaansba spaansba commented Apr 25, 2026

Summary

  • Replaces mutable ForesightElementData with an immutable ForesightElementState snapshot that is swapped on every change, enabling compatibility with React's useSyncExternalStore and Vue's shallowRef
  • Introduces subscribe / getSnapshot on ForesightRegisterResult so framework adapters can reactively bind to element state without polling or manual event wiring
  • Splits internal bookkeeping (ForesightElementInternal) from the public state surface, using a DerivedMapView to prevent leaking internals through registeredElements
  • Flattens the nested callbackInfo object into top-level state fields (isPredicted, isCallbackRunning, hitCount, durationMs, status, error, etc.)
  • Updates devtools, demo pages, and existing hooks (useForesight) to consume the new state shape
  • Adds tests for subscribe/getSnapshot lifecycle, DerivedMapView, re-registration, and related edge cases

This is the first step towards creating pre-made framework adaptors

@spaansba spaansba changed the title Refactor api to make framework adoption easier Refactor element state model to support reactive framework integration Apr 26, 2026
@spaansba spaansba marked this pull request as ready for review April 26, 2026 14:40
@spaansba spaansba merged commit 8c2d210 into main Apr 26, 2026
4 checks passed
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.

1 participant