sub() And unsub()
Use sub() outside React to load TeamPlay object-tree signals from the server.
It supports document signals, collection queries, and aggregations.
In React components, use useSub(), useAsyncSub(), or useBatchSub() instead.
Syntax
Parameters
$doc: A public document signal, for example$.users[userId].$collection: A public collection signal, for example$.users.$aggregation: An aggregation input or transformed aggregation header.queryParams: Mongo-style query parameters for collection queries.params: Aggregation parameters.options.mode: Optional transport mode:'auto','fetch', or'subscribe'.
mode: 'auto' is the default. It uses live subscription intent unless the root
context is configured as fetch-only.
Documents
Use fetch-only transport when you need a one-time load instead of a live subscription:
Queries
Fetch-only query:
Parallel Subscriptions
Use Promise.all() for independent subscriptions:
Cleanup can be parallel too:
Cleanup
Call unsub($signal) for signals returned by sub().
unsub() remembers whether the signal was loaded with fetch or subscribe mode
and releases it with the matching transport. This matters for mixed flows such
as a fetch-only load followed by a live subscription on the same signal.
If subscription GC delay is enabled, cleanup may finish after the delay unless a quick re-subscribe cancels it.