ggpeti / return-optics / Return.Optics

Return.Optics is a utility library extending Return with Monocle making a clean, concise API for doing Elm component updates in the context of other updates.

The signatures abbreviations

Optics

modell : Monocle.Lens.Lens (Return x model) model

Lens to the model, the first element of the Return tuple.

msgl : Monocle.Lens.Lens (Return msg x) (Platform.Cmd.Cmd msg)

Lens to the msg, the second element of the Return tuple.

Utilities

refractl : Monocle.Lens.Lens pmod cmod -> (cmsg -> pmsg) -> (cmod -> Return cmsg cmod) -> Return pmsg pmod -> Return pmsg pmod

Refract in a component's update via a Lens and a way to merge the message back along a parent return in the update function.

Return.singleton model
    |> case msg of
        ...

        MyComponentMsg msg ->
            refractl Model.myComponent MyComponentMsg <|
                MyComponent.update msg

refracto : Monocle.Optional.Optional pmod cmod -> (cmsg -> pmsg) -> (cmod -> Return cmsg cmod) -> Return pmsg pmod -> Return pmsg pmod

Refract in a component's update via an Optional and a way to merge the message back along a parent return in the update function. If the getter returns Nothing then the Return will not be modified.

Return.singleton model
    |> case msg of
        ...

        MyComponentMsg msg ->
            refracto Model.myComponent MyComponentMsg <|
                MyComponent.update msg