Header menu logo Mibo

Cmd Module

Functions for creating and composing Elmish commands.

Commands encapsulate side effects and allow message dispatch back to the update loop. Use commands for async operations, timer callbacks, or any impure work.

Functions and values

Function or value Description

batch cmds

Full Usage: batch cmds

Parameters:
    cmds : Cmd<'Msg> seq

Returns: Cmd<'Msg>

Combines multiple commands into a single command.

Commands are merged efficiently, preserving the distinction between immediate and deferred effects. Use this when returning multiple commands from a single update branch.

cmds : Cmd<'Msg> seq
Returns: Cmd<'Msg>

batch2 (a, b)

Full Usage: batch2 (a, b)

Parameters:
Returns: Cmd<'Msg>

Combines exactly 2 commands with minimal allocation overhead.

a : Cmd<'Msg>
b : Cmd<'Msg>
Returns: Cmd<'Msg>

batch3 (a, b, c)

Full Usage: batch3 (a, b, c)

Parameters:
Returns: Cmd<'Msg>

Combines exactly 3 commands with minimal allocation overhead.

a : Cmd<'Msg>
b : Cmd<'Msg>
c : Cmd<'Msg>
Returns: Cmd<'Msg>

batch4 (a, b, c, d)

Full Usage: batch4 (a, b, c, d)

Parameters:
Returns: Cmd<'Msg>

Combines exactly 4 commands with minimal allocation overhead.

a : Cmd<'Msg>
b : Cmd<'Msg>
c : Cmd<'Msg>
d : Cmd<'Msg>
Returns: Cmd<'Msg>

deferNextFrame cmd

Full Usage: deferNextFrame cmd

Parameters:
    cmd : Cmd<'Msg>

Returns: Cmd<'Msg>
Modifiers: inline
Type parameters: 'Msg

Defer command execution until the next frame.

In the runtime, deferred commands are executed at the start of the next frame, before Tick is enqueued. This is useful for avoiding infinite update loops or for scheduling work that should happen after the current frame completes.

cmd : Cmd<'Msg>
Returns: Cmd<'Msg>

map f cmd

Full Usage: map f cmd

Parameters:
    f : 'A -> 'Msg
    cmd : Cmd<'A>

Returns: Cmd<'Msg>

Map a command producing messages of type 'A into a command producing messages of type 'Msg.

This is the command equivalent of Sub.map and is required for parent-child composition in nested Elmish architectures where child modules have their own message types.

f : 'A -> 'Msg
cmd : Cmd<'A>
Returns: Cmd<'Msg>

none

Full Usage: none

Returns: Cmd<'Msg>

An empty command that does nothing. Use when no side effects are needed.

Returns: Cmd<'Msg>

ofAsync task ofSuccess ofError

Full Usage: ofAsync task ofSuccess ofError

Parameters:
    task : Async<'T>
    ofSuccess : 'T -> 'Msg
    ofError : exn -> 'Msg

Returns: Cmd<'Msg>

Creates a command from an F# async workflow. The async is started immediately and the result is mapped to a message. If the async throws, the error handler is invoked instead. ## Example ```fsharp Cmd.ofAsync (loadDataAsync url) DataLoaded LoadError ```

task : Async<'T>
ofSuccess : 'T -> 'Msg
ofError : exn -> 'Msg
Returns: Cmd<'Msg>

ofEffect eff

Full Usage: ofEffect eff

Parameters:
Returns: Cmd<'Msg>
Modifiers: inline
Type parameters: 'Msg

Wraps a raw effect delegate into a command.

eff : Effect<'Msg>
Returns: Cmd<'Msg>

ofMsg msg

Full Usage: ofMsg msg

Parameters:
    msg : 'Msg

Returns: Cmd<'Msg>
Modifiers: inline
Type parameters: 'Msg

Creates a command that immediately dispatches the given message.

Useful for triggering follow-up messages from within the update cycle.

msg : 'Msg
Returns: Cmd<'Msg>

ofTask task ofSuccess ofError

Full Usage: ofTask task ofSuccess ofError

Parameters:
    task : Task<'T>
    ofSuccess : 'T -> 'Msg
    ofError : exn -> 'Msg

Returns: Cmd<'Msg>

Creates a command from a .NET Task.

The task result is awaited and mapped to a message. If the task throws, the error handler is invoked instead.

task : Task<'T>
ofSuccess : 'T -> 'Msg
ofError : exn -> 'Msg
Returns: Cmd<'Msg>
Example

 Cmd.ofTask (httpClient.GetAsync url) ResponseReceived RequestFailed

Type something to start searching.