garados007 / component / Component

This library contains some function that make the update and event process with components easier.

Update Handlers

update : (cmsg -> comp -> Triple comp (Platform.Cmd.Cmd cmsg) (List cevent)) -> (cevent -> model -> ( model, Platform.Cmd.Cmd msg )) -> (model -> comp) -> (comp -> model -> model) -> (cmsg -> msg) -> cmsg -> model -> ( model, Platform.Cmd.Cmd msg )

Performs the update and handling the events of a component. In the handling of the events no new events are generated.

import MyComponent -- the client component
import Component -- this library

update : Msg -> Host -> (Host, Cmd Msg)
update msg host =
    case msg of
        ...
        -- call the update manager
        WrapMyComponent compMsg ->
            Component.update
                MyComponent.update
                handleMyCompEvents
                .component
                (\c h -> { h | component = c })
                WrapMyComponent
                compMsg
                host
        ...

-- handle all possible events
handleMyCompEvents : Component.Event -> Host -> (Host, Cmd Msg)
handleMyCompEvents event host =
    case event of
        ...
        MyComponent.Event1 -> ...
        ...

updateEvents : (cmsg -> comp -> Triple comp (Platform.Cmd.Cmd cmsg) (List cevent)) -> (cevent -> model -> Triple model (Platform.Cmd.Cmd msg) (List event)) -> (model -> comp) -> (comp -> model -> model) -> (cmsg -> msg) -> cmsg -> model -> Triple model (Platform.Cmd.Cmd msg) (List event)

Performs the update and handling the events of a component. The event handler can generate new events which can propagated to the host of the host.

import MyComponent -- the client component
import Component -- this library

update : Msg -> Host -> (Host, Cmd Msg, List Event)
update msg host =
    case msg of
        ...
        -- call the update manager
        WrapMyComponent compMsg ->
            Component.updateEvents
                MyComponent.update
                handleMyCompEvents
                .component
                (\c h -> { h | component = c })
                WrapMyComponent
                compMsg
                host
        ...

-- handle all possible events. New events can be generated here.
handleMyCompEvents : Component.Event -> Host -> (Host, Cmd Msg, List Event)
handleMyCompEvents event host =
    case event of
        ...
        MyComponent.Event1 -> ...
        ...