Primitives / foldkit-primitives/interaction

BundleBehavior

namespace · packages/primitives/src/interaction/bundle-behavior.ts:17

export * as BundleBehavior from './bundle-behavior.js'

The mixin half of a Bundle: a Behavior whose slots are wired to the Bundle's Messages through its Declared placement.

The Bundle owns the Model, its Message union and the transition; a parent declares and places it (Bundle.declare(...).at(...)); this Behavior writes the element's attributes from the placed slice and mounts the Bundle's events, wrapping each Message with the placement's wrapper into the parent's universe. A Behavior still owns no state, and a Message still has one update: this is a bridge, not a second runtime.

attributes receives send, the same wrap, for a handler it writes itself (h.OnClick(send(Message.Activated({ id })))). events receives the Bundle's own Mount (a Mount.defineStream), and the helper supplies the mapping, so a caller never repeats Mount.mapMessage(events, wrapper.make).

Members

BundleBehavior.BundleBehavior

const · packages/primitives/src/interaction/bundle-behavior.ts:105

const BundleBehavior = { fromBundle }

BundleBehavior.BundleBehaviorSpec

type · packages/primitives/src/interaction/bundle-behavior.ts:55

type BundleBehaviorSpec<
  D extends Declared<any, any>,
  Input,
  ParentMessage,
> = Readonly<Record<string, BundleSlotOptions<D, Input, ParentMessage>>>

BundleBehavior.BundleMessageOf

type · packages/primitives/src/interaction/bundle-behavior.ts:38

type BundleMessageOf<D extends Declared<any, any>> = Bundle.BundleParts<
  BundleOf<D>
>['Message']

The Bundle's Message, which send wraps for the parent.

BundleBehavior.BundleModelOf

type · packages/primitives/src/interaction/bundle-behavior.ts:35

type BundleModelOf<D extends Declared<any, any>> = Bundle.BundleParts<
  BundleOf<D>
>['Model']

The Bundle's Model, which the parent's Input must hold at declared.field.

BundleBehavior.BundleSlotOptions

interface · packages/primitives/src/interaction/bundle-behavior.ts:42

interface BundleSlotOptions<
  D extends Declared<any, any>,
  Input,
  ParentMessage,
> {
  readonly requires?: SlotRequirements
  readonly attributes?: (context: {
    readonly input: Input
    readonly h: HtmlBuilder<ParentMessage>
    readonly item?: SlotItem
    readonly send: (message: BundleMessageOf<D>) => ParentMessage
  }) => SlotAttributes<ParentMessage>
  readonly events?: MountAction<BundleMessageOf<D>, any>
}

BundleBehavior.fromBundle

function · packages/primitives/src/interaction/bundle-behavior.ts:66

function fromBundle<D extends Declared<any, any>>(
  declared: D,
): <Slots>(
  slots: Slots,
) => <
  Input extends { readonly [K in D['field']]: BundleModelOf<D> },
  ParentMessage,
>(
  spec: BundleBehaviorSpec<D, Input, ParentMessage>,
  options?: { readonly name?: string },
) => NamedBehavior<Slots, Input, ParentMessage>

fromBundle(declared)(slots)<Input, ParentMessage>(spec) — a Behavior over declared, with every events mount and every send mapped through the placement's wrapper. Input must hold the Bundle's Model at the declared field, so attributes read the placed slice; the parent's Message includes the declared wrapper cases, so nothing can be sent outside it.