Skip to main content
Foldkit
On this pageFunctions

Runtime

Functions

makeApplication

functionsource

Creates a Foldkit application with URL routing and returns a runtime that can be passed to run.

<Model, Message extends {
  _tag: string
}, StreamDepsMap extends Struct<Fields>, Flags, Resources = never, ManagedResourceServices = never>(config: ApplicationConfigWithFlags<Model, Message, StreamDepsMap, Flags, Resources, ManagedResourceServices>): MakeRuntimeReturn

<Model, Message extends {
  _tag: string
}, StreamDepsMap extends Struct<Fields>, Resources = never, ManagedResourceServices = never>(config: ApplicationConfigWithoutFlags<Model, Message, StreamDepsMap, Resources, ManagedResourceServices>): MakeRuntimeReturn

makeElement

functionsource

Creates a Foldkit element (no URL routing) and returns a runtime that can be passed to run.

<Model, Message extends {
  _tag: string
}, StreamDepsMap extends Struct<Fields>, Flags, Resources = never, ManagedResourceServices = never>(config: ElementConfigWithFlags<Model, Message, StreamDepsMap, Flags, Resources, ManagedResourceServices>): MakeRuntimeReturn

<Model, Message extends {
  _tag: string
}, StreamDepsMap extends Struct<Fields>, Resources = never, ManagedResourceServices = never>(config: ElementConfigWithoutFlags<Model, Message, StreamDepsMap, Resources, ManagedResourceServices>): MakeRuntimeReturn

run

functionsource

Starts a Foldkit runtime, with HMR support for development.

(foldkitRuntime: MakeRuntimeReturn): void

Types

ApplicationConfigWithFlags

typesource

Configuration for makeApplication when the application receives initial data via flags.

type ApplicationConfigWithFlags = BaseApplicationConfig<Model, Message, StreamDepsMap, Resources, ManagedResourceServices> & Readonly<{
  flags: Effect.Effect<Flags>
  Flags: Schema.Schema<Flags, any, never>
  init: (flags: Flags, url: Url) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
}>

ApplicationConfigWithoutFlags

typesource

Configuration for makeApplication without flags.

type ApplicationConfigWithoutFlags = BaseApplicationConfig<Model, Message, StreamDepsMap, Resources, ManagedResourceServices> & Readonly<{
  init: (url: Url) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
}>

ApplicationInit

typesource

The init function type for applications, receives the current URL and optional flags.

type ApplicationInit = Flags extends void
  ? (url: Url) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
  : (flags: Flags, url: Url) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]

BrowserConfig

typesource

Configuration for browser URL integration with handlers for URL requests and URL changes.

type BrowserConfig = Readonly<{
  onUrlChange: (url: Url) => Message
  onUrlRequest: (request: UrlRequest) => Message
}>

ElementConfigWithFlags

typesource

Configuration for makeElement when the element receives initial data via flags.

type ElementConfigWithFlags = BaseElementConfig<Model, Message, StreamDepsMap, Resources, ManagedResourceServices> & Readonly<{
  flags: Effect.Effect<Flags>
  Flags: Schema.Schema<Flags, any, never>
  init: (flags: Flags) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
}>

ElementConfigWithoutFlags

typesource

Configuration for makeElement without flags.

type ElementConfigWithoutFlags = BaseElementConfig<Model, Message, StreamDepsMap, Resources, ManagedResourceServices> & Readonly<{
  init: () => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
}>

ElementInit

typesource

The init function type for elements, with an optional flags parameter when Flags is not void.

type ElementInit = Flags extends void
  ? () => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]
  : (flags: Flags) => [Model, ReadonlyArray<Command<Message, never, Resources | ManagedResourceServices>>]

External

typesource

A URL request to an external page (different origin).

type External = CallableTaggedStruct<"External", {
  href: typeof String$
}>

Internal

typesource

A URL request to a page within the application (same origin).

type Internal = CallableTaggedStruct<"Internal", {
  url: Struct<{
    hash: OptionFromSelf<typeof String
gt;
host: typeof String$ pathname: typeof String$ port: OptionFromSelf<typeof String
gt;
protocol: typeof String$ search: OptionFromSelf<typeof String
gt;
}> }>

MakeRuntimeReturn

typesource

A configured Foldkit runtime returned by makeElement or makeApplication, passed to run to start the application.

type MakeRuntimeReturn = (hmrModel?: unknown) => Effect.Effect<void>

Constants

UrlRequest

constsource

Union of Internal and External URL request types.

const UrlRequest: Union<[
  CallableTaggedStruct<"Internal", {
    url: Struct<{
      hash: OptionFromSelf<typeof String
gt;
host: typeof String$ pathname: typeof String$ port: OptionFromSelf<typeof String
gt;
protocol: typeof String$ search: OptionFromSelf<typeof String
gt;
}> }>, CallableTaggedStruct<"External", { href: typeof String$ }> ]>