mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-07 06:53:46 +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
|
| Increment
|
||||||
|
|
||||||
|
|
||||||
init : a -> Model
|
init : a -> ( Model, Cmd Msg )
|
||||||
init maybePagePath =
|
init maybePagePath =
|
||||||
{ showMobileMenu = False
|
( { showMobileMenu = False
|
||||||
, counter = 0
|
, counter = 0
|
||||||
}
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
@ -54,7 +54,7 @@ load globalModel model =
|
|||||||
|
|
||||||
save : Model -> Global.Model -> Global.Model
|
save : Model -> Global.Model -> Global.Model
|
||||||
save model globalModel =
|
save model globalModel =
|
||||||
globalModel
|
{ globalModel | counter = model.counter }
|
||||||
|
|
||||||
|
|
||||||
init : Documentation -> ( Model, Cmd Msg )
|
init : Documentation -> ( Model, Cmd Msg )
|
||||||
|
@ -114,8 +114,11 @@ init :
|
|||||||
}
|
}
|
||||||
-> ( Model, Cmd Msg )
|
-> ( Model, Cmd Msg )
|
||||||
init currentGlobalModel maybePagePath =
|
init currentGlobalModel maybePagePath =
|
||||||
( { global = currentGlobalModel |> Maybe.withDefault (Global.init maybePagePath)
|
let
|
||||||
, page =
|
( globalModel, globalCmd ) =
|
||||||
|
currentGlobalModel |> Maybe.map (\\m -> ( m, Cmd.none )) |> Maybe.withDefault (Global.init maybePagePath)
|
||||||
|
|
||||||
|
page =
|
||||||
case maybePagePath |> Maybe.map .metadata of
|
case maybePagePath |> Maybe.map .metadata of
|
||||||
Nothing ->
|
Nothing ->
|
||||||
NotFound
|
NotFound
|
||||||
@ -128,12 +131,22 @@ init currentGlobalModel maybePagePath =
|
|||||||
|> Model${name}
|
|> Model${name}
|
||||||
|
|
||||||
`).join("\n ")}
|
`).join("\n ")}
|
||||||
|
|
||||||
|
( templateModel, templateCmd ) =
|
||||||
|
load globalModel page
|
||||||
|
in
|
||||||
|
( { global = globalModel
|
||||||
|
, page = templateModel
|
||||||
, current = maybePagePath
|
, current = maybePagePath
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.batch
|
||||||
|
[ templateCmd
|
||||||
|
, globalCmd |> Cmd.map MsgGlobal
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
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 : TemplateModel -> Global.Model -> Global.Model
|
||||||
save model globalModel=
|
save model globalModel=
|
||||||
case model of
|
case model of
|
||||||
|
Loading…
Reference in New Issue
Block a user