Route element hooks by ID and support field selectors
This commit is contained in:
+25
-2
@@ -262,8 +262,10 @@ Import from `/react` for React only, or the re-export in `/react-flow`.
|
||||
- `useCanvas(selector, isEqual?)` observes the one immutable project Root. Default
|
||||
equality is `Object.is`; choose an appropriate comparator for allocated results.
|
||||
Snapshots are cached per selection and unchanged selections do not notify React.
|
||||
- `useElement(idOrTarget)` returns `present`, `absent`, `unloaded`, or `stale`.
|
||||
A Target includes incarnation; a restored element does not silently retarget it.
|
||||
- `useElement(idOrTarget, selector?, isEqual?)` returns `present`, `absent`,
|
||||
`unloaded`, or `stale`, or the supplied selector result. A Target includes
|
||||
incarnation; a restored element does not silently retarget it. Custom selectors
|
||||
use `Object.is` by default; provide a comparator for allocated field groups.
|
||||
- `useActions(target)` exposes stable `rename`, `setData`, `resize`, `remove`, and
|
||||
`moveTo` facades over normal editor commands. Optional command settings retain
|
||||
label/grouping/history semantics. Call actions from events, not during render.
|
||||
@@ -500,3 +502,24 @@ streaming SHA implementation. Main-thread fallback stays chunked/cooperative.
|
||||
Native read/hash errors remain visible; they do not silently select another path.
|
||||
Worker termination still owns cancellation. The full source check remains before
|
||||
imported elements are published; no journal revisions or integrity gates are skipped.
|
||||
|
||||
|
||||
Element hooks share one upstream editor listener per engine while subscribed.
|
||||
An ID→bucket Map and listener Sets route explicit changes to their targets;
|
||||
runtime-only cuts do no element lookup work. Document replacements check active
|
||||
IDs, and loading coverage changes recheck missing lookups. Reads still consult the
|
||||
current engine, including while unsubscribed. Buckets retain lookup values, not
|
||||
per-element Root snapshots; the last listener releases its bucket and the final
|
||||
bucket releases the upstream listener. No document, history or durable state is
|
||||
copied into the bindings. Arbitrary `useCanvas` selectors remain Root observers.
|
||||
|
||||
```tsx
|
||||
const title = useElement(target, view =>
|
||||
view.status === 'present' && typeof view.element.data.title === 'string'
|
||||
? view.element.data.title : ''
|
||||
);
|
||||
```
|
||||
|
||||
A change to another field on this target evaluates the title selector but does
|
||||
not rerender its consumer. Unrelated target edits skip the selector entirely.
|
||||
This is ID routing and value selection, not a static field dependency index.
|
||||
|
||||
Reference in New Issue
Block a user