Created
March 6, 2018 04:39
-
-
Save ericgj/5416b456b7c78fed31483fa3806d4b35 to your computer and use it in GitHub Desktop.
session example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Page | |
= Search Page.Search.Model | |
type alias Model = | |
{ page : Page | |
, session : Session | |
} | |
type Msg | |
= UpdatePage PageMsg | |
type PageMsg | |
= UpdateSearch Page.Search.Msg | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
UpdatePage pagemsg -> | |
updatePage pagemsg model | |
updatePage : PageMsg -> Model -> ( Model, Cmd Msg ) | |
updatePage msg model = | |
case ( msg, model.page ) of | |
( UpdateSearch pagemsg, Search pagemodel ) -> | |
let | |
( newSearch, cmd, sessionMsgs ) = | |
Page.Search.update pagemsg pagemodel | |
newPage = | |
Search newSearch | |
( newSession, sessionCmd ) = | |
Session.updateBatch sessionMsgs model.session | |
in | |
( { model | page = newPage, session = newSession } | |
, Cmd.batch | |
[ Cmd.map (UpdatePage << UpdateSearch) cmd | |
, sessionCmd | |
] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Session exposing (Msg(..)) | |
type Msg | |
= UpdateFilter Filter.Msg | |
| SetTableState Table.State | |
update : Msg -> Model -> ( Model, Cmd Msg, List Session.Msg ) | |
update msg model = | |
case msg of | |
NoOp -> | |
( model, Cmd.none, [] ) | |
UpdateFilter filtermsg -> | |
let | |
newFilter = | |
Filter.update filtermsg model.filter | |
newModel = | |
{ model | filter = newFilter } | |
in | |
( newModel | |
, Cmd.none | |
, [ SetSearchFilter newFilter ] | |
) | |
SetTableState newTable -> | |
( { model | table = newTable } | |
, Cmd.none | |
, [ SetSearchTable newTable ] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Msg | |
= SetSearchFilter Filter | |
| SetSearchFrom Date | |
| SetSearchTable Table.State | |
update : Msg -> Session -> ( Session, Cmd msg ) | |
update msg session = | |
updateSimple msg session |> andStore | |
updateBatch : List Msg -> Session -> ( Session, Cmd msg ) | |
updateBatch msgs session = | |
case msgs of | |
[] -> | |
( session, Cmd.none ) | |
_ -> | |
List.foldl updateSimple session msgs |> andStore | |
updateSimple : Msg -> Session -> Session | |
updateSimple msg session = | |
case msg of | |
SetSearchFilter filter -> | |
setSearchFilter filter session | |
SetSearchFrom date -> | |
setSearchFrom date session | |
SetSearchTable table -> | |
setSearchTable table session | |
andStore : Session -> ( Session, Cmd msg ) | |
andStore session = | |
( session, Ports.storeSession <| encode session ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment