On this pageFunctions
Mount
/** A Layer-backed Mount Definition registered with an application. */
type LayeredMountDefinition = LayeredMountDefinitionNoArgs<Name, ResultMessage> | LayeredMountDefinitionWithArgs<Name, any, ResultMessage> | LayeredStreamMountDefinitionNoArgs<Name, ResultMessage> | LayeredStreamMountDefinitionWithArgs<Name, any, ResultMessage>/**
* A named, type-constrained per-element side effect, optionally carrying the
* args used to construct it. The runtime invokes `f` with the live `Element`
* and required view-state Stream when the element mounts. A Mount acquired by
* a live render keeps live dispatch, while one acquired by a historical
* render uses no-op dispatch. When resume reuses a replay-created element,
* the runtime releases its historical Mount before starting the live action.
* Otherwise the Stream's scope is tied to the element's lifetime: when the
* element unmounts, the runtime interrupts the fiber, which closes the
* Stream's scope and runs any registered `acquireRelease` finalizers.
*
* Authors don't construct this shape directly. `Mount.define` builds the
* one-shot case, while `Mount.defineStream` exposes the continuous-event
* shape.
*/
type MountAction = Readonly<{
[MountRegistrationTypeId]: MountRegistration
args: Record<string, unknown>
f: (element: Element, viewStateChanges: Stream.Stream<ViewState>) => Stream.Stream<Message, E, R>
name: string
}>/**
* A Mount definition created with `Mount.define` or `Mount.defineStream`.
* Union over the no-args and with-args shapes; consumers that only need
* name/identity can accept this.
*/
type MountDefinition = MountDefinitionNoArgs<Name, ResultMessage, R> | MountDefinitionWithArgs<Name, any, ResultMessage, R>/** The Layer service required by a Layer-backed Mount Definition or registry. */
type RequirementsOf = DefinitionOrDefinitions extends ReadonlyArray<infer Definition>
? RequirementsOf<Definition>
: DefinitionOrDefinitions extends (args: infer _Args) => infer Action
? Action extends MountAction<infer _Message, infer _Error, infer Requirements>
? Requirements
: never
: never/** The service required by a Mount whose implementation is supplied by a Layer. */
interface Handler {
[HandlerTypeId]: Readonly<{
input: (input: Input) => Input
name: Name
result: (result: ResultMessage) => ResultMessage
}>
}/** A one-shot Mount Definition whose implementation is supplied by a Layer. */
interface LayeredMountDefinitionNoArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
[MountRegistrationTypeId]: MountRegistration
name: Name
toLayer: ToEffectLayer<Name, Readonly<{
element: Element
viewStateChanges: Stream<"Live" | "Paused">
}>, ResultMessage>
}/** An argument-bearing one-shot Mount Definition whose implementation is supplied by a Layer. */
interface LayeredMountDefinitionWithArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
[MountRegistrationTypeId]: MountRegistration
name: Name
toLayer: ToEffectLayer<Name, Readonly<{
element: Element
viewStateChanges: Stream<"Live" | "Paused">
}> & View<Fields, "Type", TypeOptionalKeys<Fields>, TypeMutableKeys<Fields>>, ResultMessage>
}/** A streaming Mount Definition whose implementation is supplied by a Layer. */
interface LayeredStreamMountDefinitionNoArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
[MountRegistrationTypeId]: MountRegistration
name: Name
toLayer: ToStreamLayer<Name, Readonly<{
element: Element
viewStateChanges: Stream<"Live" | "Paused">
}>, ResultMessage>
}/** An argument-bearing streaming Mount Definition whose implementation is supplied by a Layer. */
interface LayeredStreamMountDefinitionWithArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
[MountRegistrationTypeId]: MountRegistration
name: Name
toLayer: ToStreamLayer<Name, Readonly<{
element: Element
viewStateChanges: Stream<"Live" | "Paused">
}> & View<Fields, "Type", TypeOptionalKeys<Fields>, TypeMutableKeys<Fields>>, ResultMessage>
}/** A Mount definition for a Mount with no declared args. Call as `Definition()` to produce a MountAction. */
interface MountDefinitionNoArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
name: Name
}/** A Mount definition for a Mount with declared args. Call as `Definition(args)` to produce a MountAction. */
interface MountDefinitionWithArgs {
[MountDefinitionTypeId]: typeof MountDefinitionTypeId
name: Name
}/**
* Creates a Layer recipe from an Effect that constructs a one-shot Mount handler.
* An Effect constructor runs once when the application Layer is built and may
* capture shared services. The returned handler receives the rendered element
* and executes in that element's scope. Perform DOM work inside the handler.
* Provide test services before building the same handler Layer.
* Captured services retain their identity; service lookups inside execution
* use the invocation context over the construction context.
*/
interface ToEffectLayer unknown/**
* Creates a Layer recipe from an Effect that constructs a streaming Mount handler.
* An Effect constructor runs once when the application Layer is built and may
* capture shared services. The returned handler receives the rendered element
* and produces a Stream whose resources follow that element's scope.
* Provide test services before building the same handler Layer.
* Captured services retain their identity; service lookups inside the Stream
* use the invocation context over the construction context.
*/
interface ToStreamLayer unknown/**
* Property key carrying a layered Mount's registration identity through Block
* composition.
*/
const MountRegistrationTypeId: unique symbol/**
* The state of the DOM currently owned by the Foldkit renderer. `Live` means
* it represents the current live Model. `Paused` means time travel has
* installed a historical view while the live application continues running.
*/
const ViewState: Literals<readonly ["Live", "Paused"]>/**
* A never-ending view-state Stream for renderers without time travel.
* It emits `Live` immediately and never completes. Custom renderers and
* low-level MountAction wrappers can pass it as the required second argument
* to `MountAction.f` when the rendered view is always live.
*/
const liveViewStateChanges: Stream.Stream<ViewState>/**
* Lifts a `MountAction` from one Message universe to another by mapping its
* dispatched Messages through a transform. Used by Block components to
* emit lifecycle action results into the parent's Message union via the
* consumer-supplied `toParentMessage` lift. Preserves `name` and `args`.
*/
const mapMessage: (f: (message: A) => B) => (action: MountAction<A, E, R>) => MountAction<B, E, R>