Documentation navigation

Published API · 0.1.0-rc.1

foldkit · submodel

Published foldkit API declarations for submodel.

./submodel

@wsagency/wseffect-foldkit · MIT · source · MIT license · WS-AGENCY-NOTICE · THIRD-PARTY-NOTICES

This entry point is published in @wsagency/wseffect-foldkit@0.1.0-rc.1. Import it from the package subpath shown below; the signatures and documentation are read from the installed package declarations.

import * as Wseffect from '@wsagency/wseffect-foldkit/submodel'

Exported declarations

Config

export type SubmodelConfig<View extends AnySubmodelView, ParentMessage> = Readonly<{
    slotId: string;
    model: ViewModelOf<View>;
    view: View;
    toParentMessage: (message: ViewMessageOf<View>) => ParentMessage;
}> & ([ViewInputsOf<View>] extends [void] ? Readonly<{
    viewInputs?: never;
}> : Readonly<{
    viewInputs: ViewInputsOf<View>;
}>);

defineView

Defines the view function of a Submodel, a child component embedded via `h.submodel`. The runtime supplies the view's `h` builder, typed by the Submodel's own Message. It is the only builder whose handlers route through this Submodel's boundary, so a Message from another Message universe is a type error at the handler call site. A helper this view delegates to takes `h` as an ordinary parameter; markup owned by an ancestor arrives pre-built through a `viewInputs` slot callback, which the runtime executes in the ancestor's boundary. Use this ONLY for views that will be embedded via `h.submodel`. Plain view functions (page-level render functions, helper render functions that compose Html, etc.) don't need to be defined this way. Write them as ordinary `(model, h) => Html` functions. Explicit type arguments are required because the Model and ViewInputs parameters cannot drive inference on their own. `Message` defaults to `never` so that omitting them fails loudly. Nothing in the parameter list can infer it, so without the default it would widen to `unknown` and the builder would accept any Message at all, which is exactly the confusion this type is meant to prevent.

defineView: <Model, Message = never, ViewInputs = void>(fn: [ViewInputs] extends [void] ? (model: Model, h: HtmlBuilder<Message>) => VNode | null : (model: Model, viewInputs: ViewInputs, h: HtmlBuilder<Message>) => VNode | null) => SubmodelView<Model, Message, ViewInputs>

Reflect

Data-first / data-last signature for a `reflect*` setter built with `Function.dual`. A `reflect*` helper conforms a Submodel to a value that originated outside it (a URL, a server push, restored storage, a sibling field), without emitting an OutMessage. It is the inbound complement to OutMessage's outbound direction: the world is the source of truth, so the Submodel mirrors it silently and never announces the change back. Being dual, it reads two ways. Data-first sets the field and returns the model; data-last returns `(model) => model`, which slots point-free into a `modifyFields` callback: ```ts // data-first const next = Slider.reflectRange(model.priceSlider, rangeFromUrl) // data-last, point-free in modifyFields modifyFields(model, { priceSlider: Slider.reflectRange(rangeFromUrl) }) ```

export type Reflect<Model, Value> = {
    (model: Model, value: Value): Model;
    (value: Value): (model: Model) => Model;
};

Reflect2

export type Reflect2<Model, A, B> = {
    (model: Model, a: A, b: B): Model;
    (a: A, b: B): (model: Model) => Model;
};

View

export type SubmodelView<Model, Message, ViewInputs = void> = ([
    ViewInputs
] extends [void] ? (model: Model, h: HtmlBuilder<Message>) => VNode | null : (model: Model, viewInputs: ViewInputs, h: HtmlBuilder<Message>) => VNode | null) & {
    readonly [SUBMODEL_MESSAGE_BRAND]: Message;
};