Documentation navigation

Published API · 0.1.0-rc.1

foldkit · message

Published foldkit API declarations for message.

./message

@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/message'

Exported declarations

defineMessageUnion

Declares every Message variant in one object. Each key is a tag, and its value lists that Message's fields. The result is both a Schema and a namespace. Construct a Message with a variant such as `Message.ClickedReset()`, and handle every variant with `Message.match`. Each constructor is also a Schema, so it can appear in a `Command.define` `messages` list. Message unions intentionally expose only constructors and exhaustive `match`. Use Effect `Match` when only some tags need handling or several tags share one handler. Declare a Submodel's OutMessages in their own `defineMessageUnion`. Messages are facts the Submodel handles; OutMessages are facts it reports to its parent. Keep the two unions separate even when two variants carry the same fields. A tag cannot use a name already owned by the union, such as `make`, `match`, `matchOrElse`, `cases`, `ast`, `members`, or `subset`. TypeScript rejects these names, and untyped calls throw an error.

export declare function defineMessageUnion<const CasesByTag extends Record<string, Schema.Struct.Fields>>(casesByTag: CasesByTag & ValidateVariantNames<CasesByTag>): MessageUnion<CasesByTag>;

MessageUnion

The Schema returned by `defineMessageUnion`. Each variant is a callable property on the union, and `match` handles the union exhaustively. With no output type argument, `match` returns the union of the handler results. Pass an output type argument when every handler must return that type. Pass a structurally refined union as `match`'s optional second type argument to preserve narrower payload fields in each handler.

export type MessageUnion<CasesByTag extends Record<string, Schema.Struct.Fields>> = UnionSchema<CasesByTag> & {
    readonly [Tag in keyof CasesByTag & string]: CallableTaggedStruct<Tag, CasesByTag[Tag]>;
};