Surface / foldkit-surface/writes

Writes

namespace · packages/surface/src/writes.ts:297

const Writes = { of }

Its type

interface Writes<Root, Message, Tag extends string> {
  readonly rootView: <Model, ViewMessage, Params>(
    surface: Surface<Root, Model, ViewMessage, Params>,
    params: Params,
    render: Renderer<Model, ViewMessage>,
  ) => ReturnType<typeof Surface.rootView<Root, Model, ViewMessage, Params>>
  readonly declared: (message: Message) => Option.Option<DependencyTree>
  readonly track: <
    Return extends {
      readonly model: Root
    },
  >(
    update: (model: Root, message: Message) => Return,
  ) => (model: Root, message: Message) => Return
  readonly install: () => () => void
  readonly epochFor: (reads: DependencyTree) => (root: Root) => number
  readonly regions: () => ReadonlyArray<RegionFacts<Tag>>
}

The writes of an application's Messages, as Writes.of makes them from a Machine.

In the guides

Members

Writes.of

function · packages/surface/src/writes.ts:115

of<
  Root,
  F extends Schema.Struct.Fields,
  Cases extends Record<string, Schema.Struct.Fields>,
  Transitions extends Readonly<Record<string, unknown>>,
>(
  app: AppScope<Root, F, Cases>,
  machine: Machine<Root, Transitions> & OnlyMessages<Cases, Transitions>,
  options?: WritesOptions,
): Writes<
  Root,
  Schema.Schema.Type<MessageUnion<Cases>>,
  keyof Transitions & string
>

The writes of an application's Messages, from a metakit Machine over its Model whose transitions are named by Message tags. Make each view with its rootView, and wrap update with its track.

Example

ts
const writes = Writes.of(App, Machine.make({ state: Model, transitions: { Renamed, Counted } }))
const header = writes.rootView(Header, undefined, drawHeader)
const update = writes.track(appUpdate)