Here's an example from elm-style-animation, looking at animating a list of
something like cards.
type alias Model =
{ cards : List Card }
type alias Card =
{ content : String
, imageSrc : Msg
, likes : Int
, style : Animation.State
}
... basic update. Doesn't look too bad.
Animate time ->
let
updateCard card =
{ card | style = Animation.update time card.style }
in
( { model
| cards =
List.map updateCard model.cards
}
, Cmd.none
)
... update with Animation.Messenger, which returns (Animation.State, Cmd
Msg)
Animate time ->
let
updateCard card (updatedCards,cmd) =
let
(newStyle, newCmd) = Animation.Messenger.update time
card.style
newCard = { card | style = newStyle }
in
( updatedCards ++ [ newCard ]
, Cmd.batch [ newCmd, cmd ]
)
(updatedCards, cmds) =
List.foldl
updateCard
([], Cmd.none)
model.cards
in
( { model | cards = updatedCards }
, cmds
)
The `Animate` msg can get pretty hairy when you have a bunch of different
animations to keep track of.
On Friday, March 3, 2017 at 8:46:36 AM UTC-5, Richard Feldman wrote:
>
> Can we express these in terms of examples of real-world code that is
> currently painful? That's really the key here. :)
>
> On Fri, Mar 3, 2017, 4:18 AM 'Rupert Smith' via Elm Discuss <
> [email protected] <javascript:>> wrote:
>
>> Another one I have run into, is when selecting just one field from a
>> record, there is no syntax to further pattern match on it. Again, abusing
>> the 'as' syntax in a quite different way to how it is currently used,
>> something along these lines:
>>
>> func { field } =
>> let
>> SomeConstructor arg = field
>> in
>> arg
>>
>> Could be shortened to:
>>
>> func { field as SomeConstructor arg } = arg
>>
>> Sorry, that wasn't an update but it relates to record syntax.
>>
>> --
>> 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/oWfARte8DJU/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.