Skip to main content
On this pageFunctions

Mount

Functions

define

functionsource

defineStream

functionsource

Types

LayeredMountDefinition

typesource
/** 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>

MountAction

typesource
/**
 * 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
}>

MountDefinition

typesource
/**
 * 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>

RequirementsOf

typesource
/** 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

Interfaces

Handler

interfacesource
/** 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
  }>
}

LayeredMountDefinitionNoArgs

interfacesource
/** 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>
}

LayeredMountDefinitionWithArgs

interfacesource
/** 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>
}

LayeredStreamMountDefinitionNoArgs

interfacesource
/** 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>
}

LayeredStreamMountDefinitionWithArgs

interfacesource
/** 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>
}

MountDefinitionNoArgs

interfacesource
/** A Mount definition for a Mount with no declared args. Call as `Definition()` to produce a MountAction. */
interface MountDefinitionNoArgs {
  [MountDefinitionTypeId]: typeof MountDefinitionTypeId
  name: Name
}

MountDefinitionWithArgs

interfacesource
/** A Mount definition for a Mount with declared args. Call as `Definition(args)` to produce a MountAction. */
interface MountDefinitionWithArgs {
  [MountDefinitionTypeId]: typeof MountDefinitionTypeId
  name: Name
}

ToEffectLayer

interfacesource
/**
 * 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

ToStreamLayer

interfacesource
/**
 * 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

Constants

MountDefinitionTypeId

constsource
/** Type-level brand for MountDefinition values. */
const MountDefinitionTypeId: unique symbol

MountRegistrationTypeId

constsource
/**
 * Property key carrying a layered Mount's registration identity through Block
 * composition.
 */
const MountRegistrationTypeId: unique symbol

ViewState

constsource
/**
 * 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"]>

liveViewStateChanges

constsource
/**
 * 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>

mapMessage

constsource
/**
 * 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>