hook.ts 1.1 KB

1234567891011121314151617181920212223242526
  1. /**
  2. * Test-local selector-hook binder: the engine carries no hook since the store
  3. * migration (runtime is React-free); the renderer binds in production, specs
  4. * bind here. Delegates to web-react's bindSnapshotSelector SOURCE (same
  5. * with-selector uSES shim as production, so selector-level render economics —
  6. * a top-level snapshot swap with an unchanged slice does NOT re-render — hold
  7. * in Profiler-count specs). Source-relative import: the package dependency
  8. * edge to web-react is gone (store migration §7); tests reach the sibling
  9. * package the same way they reach their own src internals.
  10. */
  11. import { bindSnapshotSelector } from '../../web-react/src/bind.ts'
  12. /** Minimal observable source (engine stores and scripted fakes both satisfy it). */
  13. export interface HookSource<T> {
  14. getSnapshot(): T
  15. subscribe(fn: () => void): () => void
  16. }
  17. /**
  18. * Bind a selector hook over a snapshot source.
  19. * @param src - the source.
  20. * @returns a SnapshotSelectorHook-shaped hook.
  21. */
  22. export function hookOf<T>(src: HookSource<T>) {
  23. return bindSnapshotSelector<T>(src)
  24. }