The profile widget contains one slider and several date-time pickers
wrapped in a WaypointConf component.
For Profile.update, I start by updating the internal model with the exposed
model (possibly creating a fresh internal model if the selected route has
changed):
internalUpdate : Msg -> Internal -> Internal
internalUpdate msg model =
case msg of
SliderMsg (Slider.ChangeValue newSpeed) ->
{ model | average_speed = newSpeed }
WaypointConfMsg idx msg' ->
let
newOp : Maybe (WaypointConf.Model {})
newOp =
Maybe.map (WaypointConf.update msg') (Array.get idx model.way
pointsConfs)
in
case newOp of
Nothing ->
model
Just op ->
{ model | operating_points = Array.Extra.update idx (\_ -> op)
model.waypointsConfs }
update : Msg -> Model a -> Model a
update msg model =
let
newInternal : Internal
newInternal =
internalUpdate msg <| toInternal model
in
case msg of
SliderMsg (Slider.ChangeValue newSpeed) ->
{ model | profile = newInternal, shared = Trip.setAverageSpeed model
.shared newSpeed }
WaypointConfMsg idx msg' ->
case msg' of
WaypointConf.ChangeDateOrTime _ ->
{ model | profile = newInternal, shared = Trip.changeOpDate
model.shared idx <| getDate idx model newInternal }
WaypointConf.SameDateAndTime _ ->
{ model | profile = newInternal }
The Msg is a union type which contains one tag for the slider & one for the
WaypointConf which contains the message itself and the index of the
waypoint it applies to. It looks like this:
type Msg =
WaypointConfMsg Int WaypointConf.Msg
| SliderMsg Slider.Msg
The profile is updated either when the selected route changes, or when the
waypoints are moved on the map widget or when the dates are changed in the
profile widget or when the slider is moved on the profile widget.
On Thursday, August 25, 2016 at 8:28:24 AM UTC+2, Richard Feldman wrote:
>
> Follow up questions: What do Profile.update and Profile.Msg look like?
> Also, what kinds of different places do different profiles get updated?
>
> On Wed, Aug 24, 2016, 11:11 PM Charles-Edouard Cady <
> [email protected] <javascript:>> wrote:
>
>> I have just one more tiny question: if the Profile module only has a view
>> function, how do you handle Profile.Internal's update? More specifically,
>> in the profile widget, each waypoint (there can be any number of them per
>> route) has its own date picker which has an internal state (opened/closed,
>> hovered/unhovered, etc.) and matching internal actions. Currently,
>> Profile.update handles it which means the nitty-gritty of each component's
>> update doesn't bubble up to the main app: how would you handle that if you
>> only have a view function?
>>
>>
>> On Thursday, August 25, 2016 at 12:20:59 AM UTC+2, Richard Feldman wrote:
>>
>>> Awesome! Best of luck with it! <3
>>>
>>> On Wed, Aug 24, 2016 at 1:43 PM Charles-Edouard Cady <
>>> [email protected]> wrote:
>>>
>> Thanks a lot, Richard, it makes much more sense now!
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "Elm Discuss" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/elm-discuss/NPOcF4Dle2w/unsubscribe.
>>>>
>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>
>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Elm Discuss" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/elm-discuss/NPOcF4Dle2w/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.