garados007/component/1.0.0

Component

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

Update Handlers

(cmsg -> comp -> Triple comp (Cmd cmsg) (List cevent))
-> (cevent -> model -> ( model, Cmd msg ))
-> (model -> comp)
-> (comp -> model -> model)
-> (cmsg -> msg)
-> cmsg
-> model
-> ( model, 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 -> ...
        ...
(cmsg -> comp -> Triple comp (Cmd cmsg) (List cevent))
-> (cevent -> model -> Triple model (Cmd msg) (List event))
-> (model -> comp)
-> (comp -> model -> model)
-> (cmsg -> msg)
-> cmsg
-> model
-> Triple model (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 -> ...
        ...