Skip to content

Instantly share code, notes, and snippets.

@john-kelly
Last active March 8, 2017 03:46
Show Gist options
  • Save john-kelly/56797a8b26775cfc3cb48198ee273b1f to your computer and use it in GitHub Desktop.
Save john-kelly/56797a8b26775cfc3cb48198ee273b1f to your computer and use it in GitHub Desktop.
ExperimentElmRecordUpdate.elm
[{name="john", age=100}, {name="jessta", age=100}, {name="mixed", age=100}]
|> List.map (\u -> {u | name = toUpper u.name})
[{name="john", age=100}, {name="jessta", age=100}, {name="mixed", age=100}]
|> List.map {u | name = toUpper u.name}
[{name="john", age=100}, {name="jessta", age=100}, {name="mixed", age=100}]
|> List.map (\u -> !name (toUpper u.name) u)
[{name="john", age=100}, {name="jessta", age=100}, {name="mixed", age=100}]
|> List.map (!name toUpper)
type alias Model =
{ user : User
, posts : Posts
}
type alias User =
{ userName : String
, userId : Int
, email : String
, displayName : String
, newName : String
, showNewNameModal : Bool
, following : List Int
}
type alias Posts =
{
, elements: List Post
, postsPerPage : Int
, blocked : List Int
, showNewPostModal : Bool
, newPost : String
}
update : Msg -> Model -> Model
update msg model =
case msg of
ShowNewPostModal ->
model
|> !posts (!showNewPostModal True model.posts)
UpdateNewPostData data ->
model
|> !posts (!newPost data model.posts)
SubmitNewPost newPost ->
model
|> !posts (!elements ((Post newPost) :: model.posts.elements) model.posts)
|> !posts (!showNewPostModal False model.posts)
ShowNewNameModal ->
model
|> !user (!showNewNameModal True model.user)
UpdateNewNameData data ->
model
|> !user (!userName data model.user)
SubmitNameChange newName ->
model
|> !user (!displayName newName model.user)
|> !user (!showNewNameModal False model.user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment