moonbit-community/rabbita/cmd does not have a README file

    Hook

    type Hook[Arg] = (&Scheduler, Arg) -> Unit

    MessageSender

    type MessageSender = () -> Unit

    Scheduler

    pub(open) trait Scheduler {
    run_effect(Self, EffectKind, (&Scheduler) -> Unit) -> Unit
    queue_message(Self,
    Id
    , () -> Unit) -> Unit
    drain_message(Self) -> Unit
    add(Self, Cmd) -> Unit = _
    hooks(Self) -> Hooks
    }

    Cmd

    type Cmd

    A deferred command handled by the Rabbita runtime.

    Cmd models side effects in the update loop. Commands are returned from update or embedded in Html event handlers, and are executed later by the runtime.

    Dispatch

    pub(all) struct Dispatch[Msg]((Msg) -> Cmd)

    Dispatch::map

    fn[A, B] Dispatch::map(self : Dispatch[A], f : (B) -> A) -> Dispatch[B]

    EffectKind

    pub(all) enum EffectKind {
    Immediately
    AfterRender
    }

    Hooks

    pub(all) struct Hooks {
    url_request : (&Scheduler, String) -> Unit?
    url_changed : (&Scheduler, String) -> Unit?
    }

    after_render

    let after_render : EffectKind

    attempt

    fn[A, E : Error] attempt(msg : (Result[A, E]) -> Cmd, f : async () -> A raise E) -> Cmd

    Create a command that runs an async function and handles errors.

    Similar to perform, but captures errors and passes Result[A, E] to msg.

    batch

    fn batch(cmds : Array[Cmd]) -> Cmd

    Combine multiple commands into one command.

    custom_cmd

    #alias(raw_effect, deprecated="`raw_effect` is deprecated, use `custom_cmd` instead")
    fn custom_cmd(callback : (&Scheduler) -> Unit, kind? : EffectKind) -> Cmd

    Create a low-level effect command for runtime and FFI integration. Consider use higher-level helpers like perform, delay, @http.post(), and @dialog.show() in app code.

    This function allows you to write wrappers that encapsulate FFI in a command when the functionality is not provided by Rabbita yet.

    Parameters:

    • callback: receives the runtime Scheduler, so it can enqueue follow-up commands (for example, after an async callback).

    • kind: determines when the effect runs.
      • Immediately: run as soon as the runtime receives it.
      • AfterRender: run after DOM patching for the current flush completes.

    Example:

    extern "js" fn set_timeout(f : () -> Unit, ms : Int) = "(f,ms) => setTimeout(f, ms)"

    pub fn delay(cmd : Cmd, ms : Int) -> Cmd {
    raw_effect(scheduler => set_timeout(() => scheduler.add(cmd), ms))
    }

    delay

    fn delay(cmd : Cmd, ms : Int) -> Cmd

    Delay execution of a command by ms milliseconds.

    The delayed command is added back to the message queue after the timer fires.

    effect

    fn effect(f : async () -> Unit noraise) -> Cmd

    Create a command that runs an effectful async function

    immediately

    let immediately : EffectKind

    none

    let none : Cmd

    A command that does nothing.

    perform

    fn[A] perform(msg : (A) -> Cmd, f : async () -> A noraise) -> Cmd

    Create a command that runs an async function.

    The async function f is executed, then its result is converted into a new command by msg and scheduled back into the update loop.