Init local model with load from global model.

This commit is contained in:
Dillon Kearns 2020-09-01 23:49:23 -07:00
parent 6bebe4f32c
commit dc9e34207a
3 changed files with 38 additions and 8 deletions

View File

@ -62,11 +62,13 @@ type Msg
| Increment
init : a -> Model
init : a -> ( Model, Cmd Msg )
init maybePagePath =
{ showMobileMenu = False
, counter = 0
}
( { showMobileMenu = False
, counter = 0
}
, Cmd.none
)
update : Msg -> Model -> ( Model, Cmd Msg )

View File

@ -54,7 +54,7 @@ load globalModel model =
save : Model -> Global.Model -> Global.Model
save model globalModel =
globalModel
{ globalModel | counter = model.counter }
init : Documentation -> ( Model, Cmd Msg )

View File

@ -114,8 +114,11 @@ init :
}
-> ( Model, Cmd Msg )
init currentGlobalModel maybePagePath =
( { global = currentGlobalModel |> Maybe.withDefault (Global.init maybePagePath)
, page =
let
( globalModel, globalCmd ) =
currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath)
page =
case maybePagePath |> Maybe.map .metadata of
Nothing ->
NotFound
@ -128,12 +131,22 @@ init currentGlobalModel maybePagePath =
|> Model${name}
`).join("\n ")}
( templateModel, templateCmd ) =
load globalModel page
in
( { global = globalModel
, page = templateModel
, current = maybePagePath
}
, Cmd.none
, Cmd.batch
[ templateCmd
, globalCmd |> Cmd.map MsgGlobal
]
)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
@ -176,6 +189,21 @@ update msg model =
load : Global.Model -> TemplateModel -> ( TemplateModel, Cmd Msg )
load globalModel model =
case model of
${templates.map(name => `Model${name} m ->
Template.${name}.template.load globalModel m
|> Tuple.mapFirst (Model${name})
|> Tuple.mapSecond (Cmd.map Msg${name})
`
).join("\n ")}
NotFound ->
( model, Cmd.none )
save : TemplateModel -> Global.Model -> Global.Model
save model globalModel=
case model of