Define defaults for init in State.elm
Problem: When I'm working on a feature, I save my code, and elm-live reloads the browser. This is usually good, except that the application state is reinitialized, which usually means that the view changes. I defined two state configurations, and I expect to define more: - prod: The initial state for the application - userHome: The state I'd like to use when developing a feature for the UserHome page. Idea: For more ad-hoc configurations, I can store the application state in LocalStorage and restore it in between page refreshes.
This commit is contained in:
parent
ac9629cad0
commit
57b6472e2f
1 changed files with 39 additions and 3 deletions
|
@ -379,10 +379,10 @@ routeParser =
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
{-| The initial state for the application.
|
{-| Set init to `prod` when going live.
|
||||||
-}
|
-}
|
||||||
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
prod : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||||
init _ url key =
|
prod _ url key =
|
||||||
let
|
let
|
||||||
( startDatePicker, startDatePickerCmd ) =
|
( startDatePicker, startDatePickerCmd ) =
|
||||||
DatePicker.init
|
DatePicker.init
|
||||||
|
@ -421,6 +421,42 @@ init _ url key =
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
{-| When working on a feature for the UserHome, use this.
|
||||||
|
-}
|
||||||
|
userHome : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||||
|
userHome flags url key =
|
||||||
|
let
|
||||||
|
( model, cmd ) =
|
||||||
|
prod flags url key
|
||||||
|
in
|
||||||
|
( { model
|
||||||
|
| route = Just UserHome
|
||||||
|
, session = Just { username = "mimi", role = User }
|
||||||
|
, trips =
|
||||||
|
RemoteData.Success
|
||||||
|
[ { destination = "Barcelona"
|
||||||
|
, startDate = Date.fromCalendarDate 2020 Time.Sep 25
|
||||||
|
, endDate = Date.fromCalendarDate 2020 Time.Oct 5
|
||||||
|
, comment = "Blah"
|
||||||
|
}
|
||||||
|
, { destination = "Paris"
|
||||||
|
, startDate = Date.fromCalendarDate 2021 Time.Jan 1
|
||||||
|
, endDate = Date.fromCalendarDate 2021 Time.Feb 1
|
||||||
|
, comment = "Bon voyage!"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
, cmd
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
{-| The initial state for the application.
|
||||||
|
-}
|
||||||
|
init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||||
|
init flags url key =
|
||||||
|
prod flags url key
|
||||||
|
|
||||||
|
|
||||||
{-| Now that we have state, we need a function to change the state.
|
{-| Now that we have state, we need a function to change the state.
|
||||||
-}
|
-}
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
|
|
Loading…
Reference in a new issue