@expressive/react 0.94.2 → 0.94.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/adapter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Runtime } from "./chunk-state.get-Buie72pM.js";
1
+ import { r as Runtime } from "./chunk-state.get-DlBih7tL.js";
2
2
  import { Model } from "@expressive/mvc";
3
3
 
4
4
  export { Model, Runtime };
@@ -274,12 +274,23 @@ function render(from, context) {
274
274
  };
275
275
  return () => createElement(Component);
276
276
  }
277
- /** Rewrite each own capitalized function on `target` into a subcomponent. */
277
+ function wrappable(value) {
278
+ return typeof value == "function" && Object.getOwnPropertyDescriptor(value, "prototype")?.writable !== false;
279
+ }
280
+ function assign(target, key, value) {
281
+ Object.defineProperty(target, key, {
282
+ value,
283
+ writable: true,
284
+ enumerable: true,
285
+ configurable: true
286
+ });
287
+ }
288
+ /** Rewrite each own capitalized function on `target` into a subcomponent; a class renders as itself. */
278
289
  function subcomponents(target) {
279
290
  for (const key of Object.getOwnPropertyNames(target)) {
280
291
  if (!/^[A-Z]/.test(key)) continue;
281
292
  const { value } = Object.getOwnPropertyDescriptor(target, key);
282
- if (typeof value != "function") continue;
293
+ if (!wrappable(value)) continue;
283
294
  Object.defineProperty(target, key, {
284
295
  configurable: true,
285
296
  get() {
@@ -290,18 +301,14 @@ function subcomponents(target) {
290
301
  configurable: true,
291
302
  get: () => Component,
292
303
  set(fn) {
293
- render = fn;
304
+ if (wrappable(fn)) render = fn;
305
+ else assign(owner, key, fn);
294
306
  }
295
307
  });
296
308
  return Component;
297
309
  },
298
310
  set(value) {
299
- Object.defineProperty(this, key, {
300
- value,
301
- writable: true,
302
- enumerable: true,
303
- configurable: true
304
- });
311
+ assign(this, key, value);
305
312
  subcomponents(this);
306
313
  }
307
314
  });
@@ -402,4 +409,4 @@ function use(local, compute) {
402
409
 
403
410
  //#endregion
404
411
  export { useWatch as a, useFactory as i, useAmbient as n, weak as o, Runtime as r, createFrame as t };
405
- //# sourceMappingURL=chunk-state.get-Buie72pM.js.map
412
+ //# sourceMappingURL=chunk-state.get-DlBih7tL.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chunk-state.get-Buie72pM.js","names":[],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts","../src/state.get.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */\n idle(): boolean | undefined;\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nexport { Context, createProvider, useAmbient };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface Component {\n /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nconst PLACING = new WeakMap<Component, { placed: Promise<void>; place(): void }>();\n\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\n/**\n * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n return PLACING.get(self)?.placed;\n }\n});\n\nfunction bootstrap(this: Component, parent: Context){\n const placing = {} as { placed: Promise<void>; place(): void };\n\n placing.placed = new Promise((resolve) => (placing.place = resolve));\n PLACING.set(this, placing);\n\n const context = parent.push(this, () => this.set(null));\n\n Object.defineProperties(this, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: render(this, context)\n }\n });\n\n this.set(null, () => {\n Object.defineProperty(this, 'props', {\n value: this.props,\n writable: true\n });\n })\n}\n\n/**\n * Wrap a content element in its context provider, a Suspense boundary (unless\n * `fallback` is `false`) and, when `catch` is set, the host error boundary.\n */\nfunction createFrame(from: Component, context: Context, children: unknown) {\n const { createElement } = Runtime;\n\n if(from.fallback !== false)\n children = createElement(\n Runtime.Suspense,\n { fallback: from.fallback, name: String(from) },\n children\n )\n\n children = createProvider(context, children);\n\n return from.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n PLACING.get(owner)!.place();\n attempt?.commit();\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (typeof value != 'function') continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: Function) {\n render = fn;\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n Object.defineProperty(this, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n","import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { resolver } from '@expressive/mvc/jsx-runtime';\nimport { useAmbient } from './context';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } from './runtime';\n\nconst normal = resolver((Type, compute) => {\n const idle = Runtime.idle();\n\n if (idle) return normal(Type, compute);\n\n let ambient: Context;\n\n if (idle === undefined)\n try {\n ambient = useAmbient();\n } catch {\n return normal(Type, compute);\n }\n else ambient = useAmbient();\n\n return Type ? use(ambient, compute) : compute(ambient);\n});\n\nfunction use(local: Context, compute: (context: Context) => unknown) {\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const dispatch = useWeak(next);\n const render = useFactory(() => {\n let latest = compute;\n let mounted = false;\n let pending = false;\n let force!: () => void;\n let target: unknown;\n let value: unknown;\n let unwatch: (() => void) | undefined;\n let thrown: [unknown] | undefined;\n\n function update() {\n pending = false;\n dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function follow(found: unknown) {\n if (found === target) return;\n\n unwatch?.();\n unwatch = undefined;\n target = value = found;\n\n if (found instanceof Model && observer(found) !== null) {\n let first = true;\n\n unwatch = watch(\n found,\n (current) => {\n value = current;\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n false,\n Runtime.startTransition\n );\n }\n\n return true;\n }\n\n function release() {\n unfollow();\n unwatch?.();\n unwatch = target = undefined;\n }\n\n let first = true;\n\n const unfollow = watch(local, (ctx) => {\n try {\n if (follow(latest(ctx)) && !first) observed();\n } catch (error) {\n thrown = [error];\n if (!first) observed();\n }\n }, false);\n\n first = false;\n\n if (thrown) {\n unfollow();\n throw thrown[0];\n }\n\n let fresh = true;\n\n return (next: typeof compute) => {\n pending = false;\n useSetup((_self, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n\n if (!fresh) follow((latest = next)(local));\n\n fresh = false;\n\n return value;\n };\n });\n\n return render(compute);\n}\n"],"mappings":";;;;;AAiCA,MAAa,UAAU,EAAE;AA4BzB,MAAM,mBAAmB;AAEzB,SAAgB,WAA6B,SAAkB;CAC7D,MAAM,MAAM,QAAQ,OAAiB,KAAK;AAC1C,QAAO,IAAI,YAAY,IAAI,UAAU,SAAS;;;;;;;;AAShD,SAAgB,UAAU,MAAc;CACtC,MAAM,MAAM,QAAQ,OAAsB,KAAK;CAC/C,MAAM,SAAS,IAAI,YAAY,IAAI,UAAU;EAC3C,QAAQ;GACN,MAAM,OAAO,SAAS;AAEtB,OAAI,KAAM,EAAC,OAAO,YAAY,EAAE,EAAE,KAAK,KAAK;;EAE9C,UAAU;GACR,MAAM,EAAE,YAAY;AAEpB,OAAI,CAAC,QAAS;AACd,UAAO,UAAU;AAEjB,QAAK,MAAM,QAAQ,QAAS,OAAM;;EAErC;AAED,SAAQ,gBAAgB;AACtB,SAAO,SAAS;AAChB,SAAO,OAAO;IACb,CAAC,KAAK,CAAC;AAEV,QAAO,OAAO;;;;;;;;;;;;AAahB,SAAgB,SACd,MACA,UACA;CACA,MAAM,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V,cAAW;AACX,aAAU,SAAS;;EAGrB,IAAI,QAAQ;EAEZ,MAAM,WAAW,MAAM,QAAQ,QAAQ;AACrC,OAAI;AACF,QAAI,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,MAAO,WAAU;YACtC,OAAO;AACd,aAAS,CAAC,MAAM;AAChB,QAAI,CAAC,MAAO,WAAU;;KAEvB,MAAM;AAET,UAAQ;AAER,MAAI,QAAQ;AACV,aAAU;AACV,SAAM,OAAO;;EAGf,IAAI,QAAQ;AAEZ,UAAQ,SAAyB;AAC/B,aAAU;AACV,aAAU,OAAO,UAAU;AACzB,YAAQ;AAER,iBAAa;AACX,eAAU;AACV,SAAI,QAAS,SAAQ;AACrB,YAAO;;KAET;AAEF,OAAI,CAAC,MAAO,SAAQ,SAAS,MAAM,MAAM,CAAC;AAE1C,WAAQ;AAER,UAAO;;GAET,CAEY,QAAQ"}
1
+ {"version":3,"file":"chunk-state.get-DlBih7tL.js","names":[],"sources":["../src/runtime.ts","../src/context.ts","../src/component.ts","../src/state.get.ts"],"sourcesContent":["import type { Component } from '@expressive/mvc';\nimport { watch } from '@expressive/mvc/observable';\nimport { pending } from '@expressive/mvc';\nimport type { Context } from './context';\n\ninterface Settle {\n waiting?: (() => void)[];\n claim(): void;\n release(): void;\n}\n\ninterface Setup {\n rendered: number;\n revision: number;\n mounted?: boolean;\n fresh?: boolean;\n getRevision?: () => number;\n lapsed?: boolean;\n commit?: () => (() => void) | void;\n release?: (() => void) | void;\n teardown?: () => void;\n}\n\ninterface Hook<T> extends Setup {\n queued?: boolean;\n update?: Weak<(next: (previous: number) => number) => void>;\n output: T;\n}\n\ninterface Weak<T> {\n deref(): T | undefined;\n}\n\nexport const Runtime = {} as {\n /** Host own-property keys to trap out of observed state; assigned by each adapter. */\n ignore: string[];\n createElement(type: any, props?: any, ...children: any[]): any;\n createContext<T>(value: T): any;\n useContext(context: any): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n /** Non-urgent bracket a subscriber replays through; absent where the host\n * cannot defer, which keeps normal timing. */\n startTransition?(work: () => void): void;\n /** Consumed for pre-commit revision validation; absent where commits\n * cannot interleave with writes. */\n useSyncExternalStore?(\n subscribe: (notify: () => void) => () => void,\n getSnapshot: () => number,\n getServerSnapshot?: () => number\n ): number;\n /** Per-render-attempt lifecycle; absent where render attempts do not stack. */\n dedupe?(from: Component, context: Context): { commit(): void; remove(): void };\n /** Whether the host is certainly not rendering, so a hook probe would only throw - and may log. `undefined` when the host cannot tell. */\n idle(): boolean | undefined;\n /** Host error-boundary component, wrapping a Component whose `catch` is set. */\n ErrorBoundary: unknown;\n Suspense: any;\n};\n\nconst noop = () => () => {};\n\nexport function useFactory<T extends object>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\n/**\n * Returns a claim on the update being replayed, held until this hook commits\n * carrying it - or until unmount, where it never will. Keyed on `tick` so an\n * urgent commit in the meantime, which leaves the deferred update queued, does\n * not release it.\n */\nexport function useSettle(tick: number) {\n const ref = Runtime.useRef<Settle | null>(null);\n const settle = ref.current || (ref.current = {\n claim() {\n const held = pending();\n\n if (held) (settle.waiting ||= []).push(held);\n },\n release() {\n const { waiting } = settle;\n\n if (!waiting) return;\n settle.waiting = undefined;\n\n for (const held of waiting) held();\n }\n });\n\n Runtime.useEffect(() => {\n settle.release();\n return settle.release;\n }, [tick]);\n\n return settle.claim;\n}\n\n/**\n * Run `init` once for the life of a hook and clean up when it unmounts, safe\n * under React StrictMode - a remount shares the render counter, so neither the\n * setup nor its cleanup repeats. A cleanup following a render not yet committed\n * - Fast Refresh re-running effects - defers a microtask, and is dropped if the\n * effect runs again. `reset` invalidates the rendered value so in-flight render\n * attempts revalidate.\n *\n * @returns The hook's own record, plus the render counter and its setter.\n */\nexport function useSetup<T extends Setup>(\n init: (self: T, reset: () => void) => () => (() => void) | void,\n teardown?: () => void\n) {\n const { current } = Runtime.useRef({ rendered: 0, revision: 0 } as T);\n\n const [tick, update] = Runtime.useState(() => {\n if (!current.rendered)\n current.commit = init(current, () => {\n current.revision++;\n });\n\n return current.rendered++;\n });\n\n useReap(current, teardown);\n\n const getRevision = (current.getRevision ||= () => current.revision);\n\n current.fresh = true;\n\n Runtime.useSyncExternalStore?.(noop, getRevision, getRevision);\n\n Runtime.useEffect(() => {\n current.fresh = false;\n });\n\n Runtime.useEffect(() => {\n current.mounted = true;\n current.lapsed = false;\n\n if (current.commit) {\n current.release = current.commit();\n current.commit = undefined;\n }\n\n return () => {\n if (!current.fresh) {\n if (--current.rendered <= 0) release(current);\n return;\n }\n\n current.lapsed = true;\n\n queueMicrotask(() => {\n if (current.lapsed) release(current);\n });\n }\n }, []);\n\n return [current, tick, update] as const;\n}\n\nfunction release(setup: Setup) {\n setup.release?.();\n setup.teardown?.();\n}\n\nlet reaper: FinalizationRegistry<Setup> | null | undefined;\n\nfunction useReap(setup: Setup, teardown?: () => void) {\n const token = Runtime.useRef<object | null>(null);\n\n if (!teardown || setup.teardown) return;\n\n setup.teardown = teardown;\n\n if (reaper === undefined)\n reaper = typeof FinalizationRegistry == 'function'\n ? new FinalizationRegistry((setup) => setup.mounted || setup.teardown!())\n : null;\n\n reaper?.register((token.current = {}), setup);\n}\n\nexport function weak<T extends object>(value: T): Weak<T> {\n return typeof WeakRef == 'function' ? new WeakRef(value) : { deref: () => value };\n}\n\nexport function useWeak<T extends object>(value: T) {\n const ref = Runtime.useRef<Weak<T> | null>(null);\n return (ref.current ||= weak(value));\n}\n\n/**\n * Mount-effect with a refreshable return value. Publishing a value before mount\n * defers the update to it, and one published after claims the update being\n * replayed until this hook commits carrying it.\n *\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (\n refresh: (next: T) => void,\n reset: () => void\n ) => () => (() => void) | void,\n teardown?: () => void\n) {\n const [current, tick, update] = useSetup<Hook<T>>((self, reset) => {\n const mount = callback((next) => {\n self.output = next;\n\n if (self.mounted) {\n claim();\n self.update?.deref()!((x) => x + 1);\n }\n else if (self.update) self.queued = true;\n }, reset);\n\n return () => {\n const cleanup = mount();\n\n if (self.queued) {\n self.queued = false;\n self.update!.deref()!((x) => x + 1);\n }\n\n return cleanup;\n };\n }, teardown);\n\n const claim = useSettle(tick);\n\n current.update ||= weak(update);\n\n return current.output;\n}\n\nexport function useWatch<T extends object>(\n from: T,\n mount?: () => (() => void) | void,\n teardown?: () => void\n) {\n return useHook<T>((refresh, reset) => {\n const release = watch(from, (current) => {\n refresh(current);\n\n return (update) => {\n if (update === true) reset();\n };\n }, undefined, Runtime.startTransition);\n\n return () => {\n const cleanup = mount?.();\n\n return () => {\n release();\n if (typeof cleanup == 'function') cleanup();\n };\n };\n }, teardown) ?? from;\n}\n","import { Context, Component } from '@expressive/mvc';\nimport { Runtime } from './runtime';\n\nlet shared: any;\n\n/**\n * Lazily-created context carrying the active {@link Context} down the tree.\n * Lazy because the framework's `createContext` arrives via {@link Runtime},\n * which an adapter's entry populates at load - after this module evaluates.\n */\nfunction Layers() {\n return shared || (shared = Runtime.createContext(Context.root));\n}\n\n/** Read the ambient {@link Context} from the nearest Layers provider. */\nfunction useAmbient() {\n return Runtime.useContext(Layers());\n}\n\n/** Wrap `children` in a {@link Layers} provider carrying `context` down the tree. */\nfunction createProvider(context: Context, children: any) {\n return Runtime.createElement(Layers().Provider, { value: context, children });\n}\n\n// Class components consume the active Context through the host's `contextType`\nObject.defineProperty(Component, 'contextType', { configurable: true, get: Layers });\n\nexport { Context, createProvider, useAmbient };\n","import { Component, unbind } from '@expressive/mvc';\nimport { createProvider, type Context } from './context';\nimport { Runtime, useWatch } from './runtime';\n\ndeclare module '@expressive/mvc' {\n interface Component {\n /** @deprecated Only to satisfy host JSX. Use `this.get(Model)` instead. */\n readonly context: Context;\n /** @deprecated Only to satisfy host JSX. Use `this.get()` instead. */\n readonly state: {};\n /** @deprecated Only to satisfy host JSX. Use `this.set({})` instead. */\n setState: (state: any, callback?: () => void) => void;\n /** @deprecated Only to satisfy host JSX. Use `this.set(key)` instead. */\n forceUpdate: (callback?: () => void) => void;\n }\n}\n\n// Host-agnostic seams: `state` is a read-only values bag; `context`'s setter\n// pushes a child context, registers the instance for teardown, and installs its\n// per-instance render host. Host-specific descriptors stay in each adapter.\nconst PLACING = new WeakMap<Component, { placed: Promise<void>; place(): void }>();\n\nObject.defineProperties(Component.prototype, {\n state: {\n set() {},\n get: Component.prototype.get\n },\n context: {\n set: bootstrap\n }\n});\n\n/**\n * On the root Component, host own-property keys are trapped so each lands as a\n * plain own property (out of observed state); each adapter assigns its own set.\n */\nComponent.on({\n type(type) {\n const render = Object.getOwnPropertyDescriptor(type.prototype, 'render');\n\n if (typeof render?.value == 'function')\n Object.defineProperty(type.prototype, 'render', { ...render, configurable: false });\n\n if (type === Component)\n for (const key of Runtime.ignore)\n Object.defineProperty(Component.prototype, key, {\n set(value) {\n Object.defineProperty(this, key, { value, writable: true });\n }\n });\n\n subcomponents(type.prototype);\n },\n setup(self) {\n subcomponents(self);\n return PLACING.get(self)?.placed;\n }\n});\n\nfunction bootstrap(this: Component, parent: Context){\n const placing = {} as { placed: Promise<void>; place(): void };\n\n placing.placed = new Promise((resolve) => (placing.place = resolve));\n PLACING.set(this, placing);\n\n const context = parent.push(this, () => this.set(null));\n\n Object.defineProperties(this, {\n context: {\n get: () => context,\n set() {}\n },\n render: {\n value: render(this, context)\n }\n });\n\n this.set(null, () => {\n Object.defineProperty(this, 'props', {\n value: this.props,\n writable: true\n });\n })\n}\n\n/**\n * Wrap a content element in its context provider, a Suspense boundary (unless\n * `fallback` is `false`) and, when `catch` is set, the host error boundary.\n */\nfunction createFrame(from: Component, context: Context, children: unknown) {\n const { createElement } = Runtime;\n\n if(from.fallback !== false)\n children = createElement(\n Runtime.Suspense,\n { fallback: from.fallback, name: String(from) },\n children\n )\n\n children = createProvider(context, children);\n\n return from.props.catch || from.catch\n ? createElement(Runtime.ErrorBoundary, { self: from, children })\n : children;\n}\n\n/**\n * Ownership host for `<Component/>`: React owns the instance, so its render\n * threads the bootstrap-pushed context through `Runtime.dedupe` (React stacks\n * render attempts) and tears that context down - destroying the instance - on\n * unmount.\n */\nfunction render(from: Component, context: Context) {\n const { createElement, dedupe } = Runtime;\n const attempt = dedupe?.(from, context);\n const { is: owner } = from;\n // Read before bootstrap shadows an instance `render` with this host.\n const own = Object.prototype.hasOwnProperty.call(owner, 'render') && owner.render;\n const teardown = () => {\n attempt?.remove();\n context.pop();\n };\n\n const Render = () => (own || Object.getPrototypeOf(owner).render).call(from, from.props);\n const Component = () => {\n from = useWatch(from, () => {\n PLACING.get(owner)!.place();\n attempt?.commit();\n }, teardown);\n\n return createFrame(from, context, createElement(Render));\n };\n\n return () => createElement(Component);\n}\n\nfunction wrappable(value: unknown): value is Function {\n return typeof value == 'function' && Object.getOwnPropertyDescriptor(value, 'prototype')?.writable !== false;\n}\n\nfunction assign(target: object, key: string, value: unknown) {\n Object.defineProperty(target, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true\n });\n}\n\n/** Rewrite each own capitalized function on `target` into a subcomponent; a class renders as itself. */\nfunction subcomponents(target: object) {\n for (const key of Object.getOwnPropertyNames(target)) {\n if (!/^[A-Z]/.test(key)) continue;\n const { value } = Object.getOwnPropertyDescriptor(target, key)!;\n if (!wrappable(value)) continue;\n Object.defineProperty(target, key, {\n configurable: true,\n get(this: Component) {\n const owner = this.is;\n let render = unbind(value);\n const Component = (props: unknown) =>\n render.call(useWatch(owner), props);\n\n Object.defineProperty(owner, key, {\n configurable: true,\n get: () => Component,\n set(fn: unknown) {\n if (wrappable(fn)) render = fn;\n else assign(owner, key, fn);\n }\n });\n\n return Component;\n },\n set(this: Component, value: unknown) {\n assign(this, key, value);\n subcomponents(this);\n }\n });\n }\n}\n\nexport { createFrame };\n","import { Model, Context } from '@expressive/mvc';\nimport { observer, watch } from '@expressive/mvc/observable';\nimport { resolver } from '@expressive/mvc/jsx-runtime';\nimport { useAmbient } from './context';\nimport { Runtime, useFactory, useSettle, useSetup, useWeak } from './runtime';\n\nconst normal = resolver((Type, compute) => {\n const idle = Runtime.idle();\n\n if (idle) return normal(Type, compute);\n\n let ambient: Context;\n\n if (idle === undefined)\n try {\n ambient = useAmbient();\n } catch {\n return normal(Type, compute);\n }\n else ambient = useAmbient();\n\n return Type ? use(ambient, compute) : compute(ambient);\n});\n\nfunction use(local: Context, compute: (context: Context) => unknown) {\n const [tick, next] = Runtime.useState(0);\n const claim = useSettle(tick);\n const dispatch = useWeak(next);\n const render = useFactory(() => {\n let latest = compute;\n let mounted = false;\n let pending = false;\n let force!: () => void;\n let target: unknown;\n let value: unknown;\n let unwatch: (() => void) | undefined;\n let thrown: [unknown] | undefined;\n\n function update() {\n pending = false;\n dispatch.deref()!((x) => x + 1);\n }\n\n function observed() {\n if (mounted) {\n claim();\n update();\n }\n else pending = true;\n }\n\n function follow(found: unknown) {\n if (found === target) return;\n\n unwatch?.();\n unwatch = undefined;\n target = value = found;\n\n if (found instanceof Model && observer(found) !== null) {\n let first = true;\n\n unwatch = watch(\n found,\n (current) => {\n value = current;\n\n if (!first) observed();\n first = false;\n\n return (update) => {\n if (update === true) force();\n };\n },\n false,\n Runtime.startTransition\n );\n }\n\n return true;\n }\n\n function release() {\n unfollow();\n unwatch?.();\n unwatch = target = undefined;\n }\n\n let first = true;\n\n const unfollow = watch(local, (ctx) => {\n try {\n if (follow(latest(ctx)) && !first) observed();\n } catch (error) {\n thrown = [error];\n if (!first) observed();\n }\n }, false);\n\n first = false;\n\n if (thrown) {\n unfollow();\n throw thrown[0];\n }\n\n let fresh = true;\n\n return (next: typeof compute) => {\n pending = false;\n useSetup((_self, reset) => {\n force = reset;\n\n return () => {\n mounted = true;\n if (pending) update();\n return release;\n };\n });\n\n if (!fresh) follow((latest = next)(local));\n\n fresh = false;\n\n return value;\n };\n });\n\n return render(compute);\n}\n"],"mappings":";;;;;AAiCA,MAAa,UAAU,EAAE;AA4BzB,M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iBAAa;AACX,eAAU;AACV,SAAI,QAAS,SAAQ;AACrB,YAAO;;KAET;AAEF,OAAI,CAAC,MAAO,SAAQ,SAAS,MAAM,MAAM,CAAC;AAE1C,WAAQ;AAER,UAAO;;GAET,CAEY,QAAQ"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as useWatch, i as useFactory, n as useAmbient, o as weak, r as Runtime, t as createFrame } from "./chunk-state.get-Buie72pM.js";
1
+ import { a as useWatch, i as useFactory, n as useAmbient, o as weak, r as Runtime, t as createFrame } from "./chunk-state.get-DlBih7tL.js";
2
2
  import "./adapter.js";
3
3
  import { Component } from "@expressive/mvc";
4
4
  import * as React$1 from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressive/react",
3
- "version": "0.94.2",
3
+ "version": "0.94.4",
4
4
  "description": "Class-based reactive state for React. Define state and logic as plain classes; components update when the values they read change.",
5
5
  "keywords": [
6
6
  "expressive",
@@ -64,7 +64,7 @@
64
64
  "test": "bun run typecheck && bun run coverage"
65
65
  },
66
66
  "devDependencies": {
67
- "@expressive/mvc": "^0.94.2",
67
+ "@expressive/mvc": "^0.94.4",
68
68
  "@testing-library/react": "^16.3.0",
69
69
  "@types/react": "^19",
70
70
  "@types/react-dom": "^19",
@@ -76,7 +76,7 @@
76
76
  "vite": "^7.3.1"
77
77
  },
78
78
  "peerDependencies": {
79
- "@expressive/mvc": "^0.94.2",
79
+ "@expressive/mvc": "^0.94.4",
80
80
  "react": ">=16.14.0 <20.0.0",
81
81
  "vite": ">=5"
82
82
  },
@@ -5,10 +5,10 @@ description: React host for Expressive MVC (@expressive/react) - Component class
5
5
 
6
6
  # Expressive MVC - React
7
7
 
8
- `@expressive/react` is the React host. Ownership decisions, the golden-path summary and the core API are in [expressive-mvc](../expressive-mvc/SKILL.md) - read it first. **Read [refactor.md](refactor.md) in full before any hook-migration or refactor task.**
8
+ `@expressive/react` is the React host. Ownership decisions, the golden-path summary and the core API are in `expressive-mvc` - read it first. **Read [refactor.md](refactor.md) in full before any hook-migration or refactor task.**
9
9
 
10
10
  - [refactor.md](refactor.md) - the refactor algorithm expanded: ownership triage, mechanical-setter and prop-drilling anti-patterns, single-consumer getters, dependency snapshots and conditional subscriptions, presence boundaries, restrained `is`, subcomponent overuse, extract-then-consolidate, review checklist
11
- - [expressive-mvc/style.md](../expressive-mvc/style.md) - style profile: snapshot formatting, affirmative conditions, render fallthrough vs operational guards
11
+ - `expressive-mvc/style.md` - style profile: snapshot formatting, affirmative conditions, render fallthrough vs operational guards
12
12
  - [react.md](react.md) - Model.get() (optional lookup, presence boundaries, custom lookup), effects at commit, providing state, transparent writes, SSR, React Native, Vite hot reload
13
- - [expressive-mvc/component.md](../expressive-mvc/component.md) - Component class, props, children, extending a base, subcomponent extension points, Suspense, transitions, error boundaries
13
+ - `expressive-mvc/component.md` - Component class, props, children, extending a base, subcomponent extension points, Suspense, transitions, error boundaries
14
14
  - [patterns.md](patterns.md) - Recipes: forms, async, domain-row and form-chip pools, region controls, router bridge, host-agnostic domain model + view adapter, presence boundary, contextual children, debounce, async effects, awaiting a pending value, effects
@@ -91,7 +91,7 @@ class Profile extends Component {
91
91
  }
92
92
  ```
93
93
 
94
- Suspense fits load-once data the view cannot render without. Keep explicit `loading` / `error` fields when the fetch is user-initiated, stale content stays visible during refresh, or errors render inline - see [expressive-mvc/field/set.md](../expressive-mvc/field/set.md).
94
+ Suspense fits load-once data the view cannot render without. Keep explicit `loading` / `error` fields when the fetch is user-initiated, stale content stays visible during refresh, or errors render inline - see `expressive-mvc/field/set.md`.
95
95
 
96
96
  ## Domain Rows in a Pool
97
97
 
@@ -324,7 +324,7 @@ Session.on({
324
324
  });
325
325
  ```
326
326
 
327
- Construction stays with the consumer - `session = new Session()` on the owning Component. No subclass (`class ViewSession extends Session`), no `Session.new()` in the adapter. Inbound snapshots land with `set(values)` - a superset payload is fine, extra keys drop ([expressive-mvc/state/set.md](../expressive-mvc/state/set.md)).
327
+ Construction stays with the consumer - `session = new Session()` on the owning Component. No subclass (`class ViewSession extends Session`), no `Session.new()` in the adapter. Inbound snapshots land with `set(values)` - a superset payload is fine, extra keys drop (`expressive-mvc/state/set.md`).
328
328
 
329
329
  ## Context Sharing
330
330
 
@@ -576,7 +576,7 @@ class Canvas extends Component {
576
576
  }
577
577
  ```
578
578
 
579
- Each rendered `Layer` is owned by the `Canvas` rendering it, so the callback runs as it mounts and the cleanup when it unmounts. Downstream `get(Layer, true)` would also find them, but through context - it needs the type, and would include Layers a nested Component owns. Ownership stays one level deep. The other direction, a reusable child finding whoever constructed it without naming the type, is `get(Model)` - see [expressive-mvc/state/context.md](../expressive-mvc/state/context.md#ownership-vs-context).
579
+ Each rendered `Layer` is owned by the `Canvas` rendering it, so the callback runs as it mounts and the cleanup when it unmounts. Downstream `get(Layer, true)` would also find them, but through context - it needs the type, and would include Layers a nested Component owns. Ownership stays one level deep. The other direction, a reusable child finding whoever constructed it without naming the type, is `get(Model)` - see `expressive-mvc/state/context.md#ownership-vs-context`.
580
580
 
581
581
  ## Refactoring Hooks Into a Class
582
582
 
@@ -70,7 +70,7 @@ Commit is an **ownership** signal - it reaches an instance where a component cre
70
70
 
71
71
  The excluded paths are *many-to-one*: any number of components can `.get()` one instance or place it as `{instance}`, each for less time than the instance lives. To react to an instance a component does not own, subscribe with `Model.get()` or an event.
72
72
 
73
- Nothing commits during server render, so these effects never run there. Children owned as fields follow their root ([expressive-mvc/state/lifecycle.md](../expressive-mvc/state/lifecycle.md#the-new-hook)).
73
+ Nothing commits during server render, so these effects never run there. Children owned as fields follow their root (`expressive-mvc/state/lifecycle.md#the-new-hook`).
74
74
 
75
75
  The effect is tracked: a read of `$` subscribes, and each change re-runs it after its cleanup - a socket opened on `$.url` reopens per change. A one-shot resource reads `this`, which is untracked, and runs once.
76
76
 
@@ -85,11 +85,18 @@ React can discard a render before committing it - a suspended first mount, a dro
85
85
 
86
86
  ## Server render (SSR / RSC)
87
87
 
88
- Expressive components render on the server - `renderToString`, and the SSR pass of an RSC app (they are client components) - without touching the DOM. Nothing commits, so for a host-owned Component and the children it owns, effects declared in `new()` never run, `on({ ready })` never fires and `await state.get(() => {})` never resolves; the `new()` body does. Request-safety rules:
88
+ Expressive components render on the server - `renderToString`, and the SSR pass of an RSC app (they are client components) - without touching the DOM. Nothing commits, so for a host-owned Component and the children it owns, effects declared in `new()` never run, `on({ ready })` never fires and `await state.get(() => {})` stays pending; the `new()` body does. Request-safety rules:
89
89
 
90
90
  - **Request state goes in a `<Component for>`.** Each render builds its own context, so provided instances are isolated per request.
91
91
  - **An instance held in `Context.root` is process-wide, *shared across requests* on the server** - fit for config, flags or a warmed cache. Keep per-request data out; provide it with `<Component for>`.
92
- - **Resources belong in an effect or the request handler, never the `new()` body.** The body runs on the server but its returned teardown does not (no unmount), so a socket or handle opened there leaks. An effect is client-only; server-side resources are the framework's request scope to open and close.
92
+ - **Resources belong in an effect or the request handler, never the `new()` body.** The body runs on the server, but nothing unmounts there - its teardown waits for the request to end, so a socket or handle opened there outlives the response. An effect is client-only; server-side resources are the framework's request scope to open and close.
93
+ - **End a request by popping its root's context.** It destroys every instance the host built beneath the root: teardowns run, children first, and a pending readiness await rejects `is destroyed.`. Without it they go at garbage collection. A root that is not a Component wraps in a bare `<Component is={…}>`:
94
+
95
+ ```tsx
96
+ let app!: App;
97
+ const html = renderToString(<App is={(a) => void (app = a)} />);
98
+ Context.get(app)!.pop();
99
+ ```
93
100
 
94
101
  To render a specific request's data (a path, a session), provide it per request: `<Component for={Session} …>`. Each render's `Router` is its own, so paths never bleed between requests; provide `<Component for={Router} path={…}>` to render a request's path.
95
102
 
@@ -118,7 +125,7 @@ import expressive from '@expressive/react/vite';
118
125
  export default defineConfig({ plugins: [react(), expressive()] });
119
126
  ```
120
127
 
121
- Editing a `Model` or `Component` class patches it in place - instances keep their values and re-render with the new methods, getters, `render` and subcomponents. React Refresh keeps function components. A field, constructor or `new()` change reloads the page, as does any edit to a module declaring a class with `#` private members ([expressive-mvc/state/lifecycle.md](../expressive-mvc/state/lifecycle.md#hot-patching)). Dev server only.
128
+ Editing a `Model` or `Component` class patches it in place - instances keep their values and re-render with the new methods, getters, `render` and subcomponents. React Refresh keeps function components. A field, constructor or `new()` change reloads the page, as does any edit to a module declaring a class with `#` private members (`expressive-mvc/state/lifecycle.md#hot-patching`). Dev server only.
122
129
 
123
130
  A class must be top-level `class X` or `let X = class` - a `const` binding cannot be patched. `export default X;` exports a snapshot, so its importers are not checked for staleness - prefer `export default class X` or `export { X as default }`; likewise an anonymous `export default`.
124
131
 
@@ -181,7 +188,7 @@ function SettingsEditor() {
181
188
 
182
189
  ### Derived values and effects
183
190
 
184
- Derive from the snapshot in render, or declare a getter on the Model ([expressive-mvc/state/computed.md](../expressive-mvc/state/computed.md)); side effects belong in an instance effect (`state.get(effect)`), declared in `new()`.
191
+ Derive from the snapshot in render, or declare a getter on the Model (`expressive-mvc/state/computed.md`); side effects belong in an instance effect (`state.get(effect)`), declared in `new()`.
185
192
 
186
193
  ```tsx
187
194
  function Greeting() {
@@ -192,7 +199,7 @@ function Greeting() {
192
199
 
193
200
  ### Custom lookup
194
201
 
195
- A class overriding static `get` keeps context and render tracking - `User.get(id)` subscribes like `User.get()`. See [expressive-mvc/state/get.md](../expressive-mvc/state/get.md#static-get).
202
+ A class overriding static `get` keeps context and render tracking - `User.get(id)` subscribes like `User.get()`. See `expressive-mvc/state/get.md#static-get`.
196
203
 
197
204
  Bare `Context.get()` returns the render's context in a render, else root - safe anywhere. `state.get(Type)` runs no hooks and does not subscribe the component.
198
205
 
@@ -251,7 +258,7 @@ Do not alias `is` merely because something will be written - writes never need t
251
258
 
252
259
  ## Component Class
253
260
 
254
- `Component` extends `Model` and renders as a React class component. The class contract - props, `render()`, subcomponents, `fallback`, `catch`, `pending()` - is [expressive-mvc/component.md](../expressive-mvc/component.md). Under React:
261
+ `Component` extends `Model` and renders as a React class component. The class contract - props, `render()`, subcomponents, `fallback`, `catch`, `pending()` - is `expressive-mvc/component.md`. Under React:
255
262
 
256
263
  - `ref` receives the instance after mount and clears to `null` on unmount: `<ChatRoom ref={chatRef} />`. Use it for post-mount imperative access; `is` for construction time.
257
264
  - The instance also carries React's class members (`state`, `context`, `setState`, `forceUpdate`).
@@ -262,7 +269,7 @@ Do not alias `is` merely because something will be written - writes never need t
262
269
 
263
270
  ## Providing state
264
271
 
265
- `<Component for={AppState}>` provides one instance to its children, with no boundary unless `fallback` or `catch` is passed - contract in [expressive-mvc/state/context.md](../expressive-mvc/state/context.md#providing-with-component); commit timing in [Effects run once committed](#effects-run-once-committed). For a render-prop read, write an FC calling `AppState.get()`.
272
+ `<Component for={AppState}>` provides one instance to its children, with no boundary unless `fallback` or `catch` is passed - contract in `expressive-mvc/state/context.md#providing-with-component`; commit timing in [Effects run once committed](#effects-run-once-committed). For a render-prop read, write an FC calling `AppState.get()`.
266
273
 
267
274
  `Provider` was removed - replace `<Provider for={X}>` with `<Component for={X}>`.
268
275
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Read in full before converting hook-based React code. The common failure is translating hooks one-for-one - setter methods, drilled props, over-promoted getters mirroring the old architecture. Ownership first, translation second; the checklist at the end audits the result.
4
4
 
5
- Examples follow the conventions in [expressive-mvc/style.md](../expressive-mvc/style.md).
5
+ Examples follow the conventions in `expressive-mvc/style.md`.
6
6
 
7
7
  **Large apps:** convert route/page controls and their domain pools first; leave mature leaf widgets (inputs, menus) on hooks until the parent domain is stable. Coexistence is fine mid-migration.
8
8
 
@@ -97,7 +97,7 @@ The forms, by role:
97
97
 
98
98
  `new X()` on a parent is for Models and pool members. A nested `new Component()` that is not a pool member or hot-swap either paints - mount it - or is a Model's job wearing paint. Don't wrap a consumer under a provider Component with nothing to paint; hold the instance as a field on the control that already exists and let sibling views `.get()` it.
99
99
 
100
- **Anti-pattern - subcomponent overuse.** The sections in `render()` above are freestanding FCs, not PascalCase methods. Subcomponents (`<this.Header />`) are extension points for subclasses. Test: **would a subclass reasonably replace or wrap this renderer?** For ordinary scopes no - a freestanding FC calling `ReviewStep.get()` is clearer. See [expressive-mvc/component.md](../expressive-mvc/component.md).
100
+ **Anti-pattern - subcomponent overuse.** The sections in `render()` above are freestanding FCs, not PascalCase methods. Subcomponents (`<this.Header />`) are extension points for subclasses. Test: **would a subclass reasonably replace or wrap this renderer?** For ordinary scopes no - a freestanding FC calling `ReviewStep.get()` is clearer. See `expressive-mvc/component.md`.
101
101
 
102
102
  ## 4. Give repeated UI entries their own class
103
103
 
@@ -148,7 +148,7 @@ Selection flags, per-row status, row actions live on the member (`message.select
148
148
 
149
149
  A row earns a pool with any one of: mutable UI state (selection, expanded), async lifecycle (upload, watch, progress), actions (remove, retry). Demoting it to a plain DTO is not economy: status reads thru lookups, and a method call on a raw instance creates no subscription - progress rendered only thru `page.importFor(id)` never repaints. Tracked reads reach the member thru the pool or its own `render()`.
150
150
 
151
- A factory earns its line only when the seed must transform: fat payload folded to one field (`has((dto: MessageDto) => new Message({ info: dto, id: dto.id }))`), a rename, a colliding key dropped, multi-argument construction (`has((file: File) => new Attachment({ file }))`). Keep members small: promote a payload key to reactive field only when views render it or it changes independently; the rest stays whole as `info`. Normalize API `null` to `undefined` here so presence fields stay optional. See [expressive-mvc/field/has.md](../expressive-mvc/field/has.md) for pool surface, [patterns.md](patterns.md) for worked recipes.
151
+ A factory earns its line only when the seed must transform: fat payload folded to one field (`has((dto: MessageDto) => new Message({ info: dto, id: dto.id }))`), a rename, a colliding key dropped, multi-argument construction (`has((file: File) => new Attachment({ file }))`). Keep members small: promote a payload key to reactive field only when views render it or it changes independently; the rest stays whole as `info`. Normalize API `null` to `undefined` here so presence fields stay optional. See `expressive-mvc/field/has.md` for pool surface, [patterns.md](patterns.md) for worked recipes.
152
152
 
153
153
  Behavior parity does not exempt this step - parity constrains observable behavior, not code shape ("no redesigns" means UI and public contracts). Entry ownership is an invariant, not a style option.
154
154
 
@@ -237,9 +237,9 @@ Once ownership is settled:
237
237
  - `useEffect` setup/teardown -> `protected new()` returning cleanup; browser-only resources -> an effect declared in `new()`, which waits for commit.
238
238
  - Chains of `useEffect`s reacting to each other -> tracked reactions (`this.get($ => ...)`) registered in `new()`; updates batch, one re-run per flush however many trigger fields changed.
239
239
  - `useCallback` handlers -> auto-bound class methods - pass directly to timers and listeners: `setInterval(this.tick, 1000)`, not `() => this.tick()`.
240
- - `useRef` handles - unsubscribe functions, snapshots, timer ids -> unmanaged fields ([expressive-mvc/state/state.md](../expressive-mvc/state/state.md#unmanaged-instance-data)) - never reactive, never `#private`.
240
+ - `useRef` handles - unsubscribe functions, snapshots, timer ids -> unmanaged fields (`expressive-mvc/state/state.md#unmanaged-instance-data`) - never reactive, never `#private`.
241
241
  - Repeated `postMessage`-style calls over a typed union -> one signal helper (`signal('setLabel', { id })`). The union is the API - no per-message facade methods.
242
- - Inbound host snapshots -> `this.set(values)` - unknown keys are ignored, missing keys stay; no `apply()`/`pick` facade ([expressive-mvc/state/set.md](../expressive-mvc/state/set.md)).
242
+ - Inbound host snapshots -> `this.set(values)` - unknown keys are ignored, missing keys stay; no `apply()`/`pick` facade (`expressive-mvc/state/set.md`).
243
243
  - Route params -> props on the page owner. Working identity (session, selection) is a separate field a reaction soft-syncs - never the URL param itself. Fusing them shows as stale-prop workarounds: fresh ids threaded thru arguments to outrun the route, shadow fields remembering the last route. Router recipe in [patterns.md](patterns.md).
244
244
 
245
245
  ```tsx
@@ -435,7 +435,7 @@ const { is: review, confirmed } = ReviewStep.get(); // root object + sibling val
435
435
 
436
436
  ## 12. Widgets own their gates
437
437
 
438
- Default: a self-contained widget mounts unconditionally and gates itself - the parent writes `<UndoBar />`; the bar reads `Outbox.get()` and falls thru when `pendingSend` is unset ([expressive-mvc/style.md](../expressive-mvc/style.md) render fallthrough). A parent read existing only to gate belongs in the widget.
438
+ Default: a self-contained widget mounts unconditionally and gates itself - the parent writes `<UndoBar />`; the bar reads `Outbox.get()` and falls thru when `pendingSend` is unset (`expressive-mvc/style.md` render fallthrough). A parent read existing only to gate belongs in the widget.
439
439
 
440
440
  This is for a widget the parent has no reason to mention. A piece split out of a Component's own `render()` (step 13) is the other way round: the parent writes `cond && <Slot />` and the slot paints unconditionally, never opening with `if (!cond) return`.
441
441
 
@@ -534,7 +534,7 @@ Classify every finding by severity:
534
534
  - **Invariant** - fail unless a real constraint is documented.
535
535
  - **Default** - follow unless the alternative has clearer ownership or API value.
536
536
  - **Heuristic** - investigate, but never fail on the numerical signal alone; the finding must name a concrete cost.
537
- - **Style** - apply by default per [expressive-mvc/style.md](../expressive-mvc/style.md); report separately from architectural correctness.
537
+ - **Style** - apply by default per `expressive-mvc/style.md`; report separately from architectural correctness.
538
538
 
539
539
  The checklist:
540
540
 
@@ -564,6 +564,6 @@ The checklist:
564
564
 
565
565
  Auditing notes:
566
566
 
567
- - Compare ownership, dependency surfaces, and write behavior - never filenames, file counts, or similarity to a reference implementation. File size and consolidation follow [expressive-mvc/style.md](../expressive-mvc/style.md) layout unless the project overrides - style lane, scored separately.
567
+ - Compare ownership, dependency surfaces, and write behavior - never filenames, file counts, or similarity to a reference implementation. File size and consolidation follow `expressive-mvc/style.md` layout unless the project overrides - style lane, scored separately.
568
568
  - Report two verdicts - architectural conformance and style adherence - so a formatting miss cannot obscure correct structure, or vice versa.
569
569
  - Deliver the filled checklist with the change (PR description or ledger), not only a verdict.