Skip to content

Instantly share code, notes, and snippets.

@mdgriffith
Last active February 22, 2017 21:58
Show Gist options
  • Save mdgriffith/4977ea6f717a990300e42ce112299173 to your computer and use it in GitHub Desktop.
Save mdgriffith/4977ea6f717a990300e42ce112299173 to your computer and use it in GitHub Desktop.
-- Create a helper function that organizes your animations
-- You might consider listing the literal animations here.
-- Meaning embed "Animation.interrupt..." instead of referring it to the value closeMenuStyle.
-- This is probably the only place those animation definitions are going to live and
-- it's nice to have one place to go to understand whats going on.
runAnimation menu model =
case menu of
UserMenu Open ->
{ model
| navbarUserToggleStyle = closeToggleStyle model.navbarUserToggleStyle
, navbarUserMenuStyle = closeMenuStyle model.navbarUserMenuStyle
}
UserMenu Close ->
{ model
| navbarUserToggleStyle = openToggleStyle model.navbarUserToggleStyle
, navbarUserMenuStyle = openMenuStyle model.navbarUserMenuStyle
}
AddMenu Open ->
{ model
| navbarAddToggleStyle = openToggleStyle model.navbarAddToggleStyle
, navbarAddMenuStyle = openMenuStyle model.navbarAddMenuStyle
}
AddMenu Close ->
{ model
| navbarAddToggleStyle = closeToggleStyle model.navbarAddToggleStyle
, navbarAddMenuStyle = closeMenuStyle model.navbarAddMenuStyle
}
-- A convenience function that we'll use in a moment
noCmd : Model -> (Model, Cmd Msg)
noCmd model = model ! []
-- The revised Update funciton
ToggleNavbarDropdown menu ->
let
maybeNewMenu =
if model.openNavbarDropdownMenu == menu then
Nothing
else
menu
in
case maybeNewMenu of
Just NavbarAddMenu ->
model
|> runAnimation UserMenu Open
|> runAnimation AddMenu Closed
|> noCmd
Just NavbarUserMenu ->
model
|> runAnimation UserMenu Open
|> runAnimation AddMenu Closed
|> noCmd
Nothing ->
model
|> runAnimation UserMenu Closed
|> runAnimation AddMenu Closed
|> noCmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment