mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-03 17:31:58 +03:00
Init local model with load from global model.
This commit is contained in:
parent
6bebe4f32c
commit
dc9e34207a
@ -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 )
|
||||
|
@ -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 )
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user