Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "program"

Index

Program

Program

Program

Program<Init, State, Action, View>: { init: (init: Init) => readonly [State, undefined | Cmd<Action, string>]; subscriptions?: undefined | ((state: State) => Sub<Action> | undefined); update: (action: Action, state: State) => readonly [State, undefined | Cmd<Action, string>]; view: (props: { dispatch: Dispatch<Action>; state: State }) => View }

A program represents the root of an application.

Type parameters

  • Init

  • State

  • Action

  • View

Type declaration

  • Readonly init: (init: Init) => readonly [State, undefined | Cmd<Action, string>]
      • (init: Init): readonly [State, undefined | Cmd<Action, string>]
      • Parameters

        • init: Init

        Returns readonly [State, undefined | Cmd<Action, string>]

  • Optional Readonly subscriptions?: undefined | ((state: State) => Sub<Action> | undefined)
  • Readonly update: (action: Action, state: State) => readonly [State, undefined | Cmd<Action, string>]
      • (action: Action, state: State): readonly [State, undefined | Cmd<Action, string>]
      • Parameters

        • action: Action
        • state: State

        Returns readonly [State, undefined | Cmd<Action, string>]

  • Readonly view: (props: { dispatch: Dispatch<Action>; state: State }) => View
      • (props: { dispatch: Dispatch<Action>; state: State }): View
      • Parameters

        • props: { dispatch: Dispatch<Action>; state: State }
          • Readonly dispatch: Dispatch<Action>
          • Readonly state: State

        Returns View

run

  • run<Init, State, Action, View>(program: Program<Init, State, Action, View>, init: Init, render: (view: View) => void, effectManagers?: ReadonlyArray<EffectManager<string, unknown, unknown>>): () => void
  • This is the runtime that provides the main loop to run a Program. Given a Program and an array of EffectManagers it will start the program and progress the state each time the program calls update(). You can use the returned function to terminate the program.

    Type parameters

    • Init

      This is the type of the initial value passed to the program's init function.

    • State

    • Action

    • View

    Parameters

    • program: Program<Init, State, Action, View>

      This is the program to run.

    • init: Init
    • render: (view: View) => void
        • (view: View): void
        • Parameters

          • view: View

          Returns void

    • Default value effectManagers: ReadonlyArray<EffectManager<string, unknown, unknown>> = []

    Returns () => void

      • (): void
      • Returns void

Generated using TypeDoc