Created
November 17, 2016 19:21
-
-
Save mrmurphy/202e2ff5e24457c23dc05b61b0cab1ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Model.Lenses exposing (..) | |
-- other imports omitted | |
import Monocle.Optional as MO | |
import RemoteData | |
entryInList : String -> MO.Optional (List Entry) Entry | |
entryInList id = | |
{ getOption = List.Extra.find (\entry -> entry.id == id) | |
, set = | |
(\newEntry entries -> | |
List.map | |
(\entry -> | |
if entry.id == id then | |
newEntry | |
else | |
entry | |
) | |
entries | |
) | |
} | |
entriesInModel : MO.Optional Model (List Entry) | |
entriesInModel = | |
{ getOption = .entries >> RemoteData.toMaybe | |
, set = | |
(\newEntries model -> | |
{ model | entries = RemoteData.Success newEntries } | |
) | |
} | |
entryInModel : String -> MO.Optional Model Entry | |
entryInModel id = | |
MO.compose entriesInModel (entryInList id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Stuff up here | |
type alias Model = | |
{ route : Router.Route | |
, showSidebar : Bool | |
, journals : WebData (List Journal) | |
, entries : WebData (List Entry) | |
, editor : Savable String | |
, notification : Notification.Model | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment