Created
July 16, 2016 18:18
-
-
Save coreyhaines/e168c5db64ccf8f8340ee5bdc72f1421 to your computer and use it in GitHub Desktop.
Some elm cleanup
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
updateItemBasedOnEditItemState : EditItemType -> Item -> Item | |
updateItemBasedOnEditItemState editItemType item = | |
let | |
stopEditing : { item | typeData : ItemTypeData } -> (Maybe.Maybe newEditState -> ItemTypeData) -> { item | typeData : ItemTypeData } | |
stopEditing item itemTypeDataWithoutEditState = | |
{ item | typeData = itemTypeDataWithoutEditState Nothing } | |
updateEditingState : { item | typeData : ItemTypeData } -> (Maybe.Maybe newEditState -> ItemTypeData) -> newEditState -> { item | typeData : ItemTypeData } | |
updateEditingState item itemTypeDataWithoutEditState editItem = | |
{ item | typeData = itemTypeDataWithoutEditState (Just editItem) } | |
stopEditing2 : Item -> Item -> Item | |
stopEditing2 item newItem = | |
case newItem.typeData of | |
Text itemTypeDataItem _ -> | |
stopEditing item (Text itemTypeDataItem) | |
Link itemTypeDataItem _ -> | |
stopEditing item (Link itemTypeDataItem) | |
Quote itemTypeDataItem _ -> | |
stopEditing item (Quote itemTypeDataItem) | |
updateEditingState2 : Item -> EditItemType -> Item | |
updateEditingState2 item editItemType = | |
case ( editItemType, item.typeData ) of | |
( EditText editItem, Text itemTypeDataItem _ ) -> | |
updateEditingState item (Text itemTypeDataItem) editItem | |
( EditLink editItem, Link itemTypeDataItem _ ) -> | |
updateEditingState item (Link itemTypeDataItem) editItem | |
( EditQuote editItem, Quote itemTypeDataItem _ ) -> | |
updateEditingState item (Quote itemTypeDataItem) editItem | |
_ -> | |
item | |
handleEditingStateChange editItem = | |
case editItem.editState of | |
EditItem.Cancelled -> | |
stopEditing2 item item | |
EditItem.Successful newItem -> | |
stopEditing2 item newItem | |
EditItem.Editing -> | |
updateEditingState2 item editItemType | |
EditItem.Submitting -> | |
updateEditingState2 item editItemType | |
in | |
case (editItemType) of | |
EditText editItem -> | |
handleEditingStateChange editItem | |
EditLink editItem -> | |
handleEditingStateChange editItem | |
EditQuote editItem -> | |
handleEditingStateChange editItem |
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
updateItemBasedOnEditItemState : EditItemType -> Item -> Item | |
updateItemBasedOnEditItemState editItemType item = | |
case ( editItemType, item.typeData ) of | |
( EditText editItem, Text textItem _ ) -> | |
case editItem.editState of | |
EditItem.Cancelled -> | |
{ item | typeData = Text textItem Nothing } | |
EditItem.Successful newItem -> | |
case newItem.typeData of | |
Text newTextItem _ -> | |
{ item | typeData = Text { textItem | text = newTextItem.text } Nothing } | |
_ -> | |
item | |
EditItem.Editing -> | |
{ item | typeData = Text textItem (Just editItem) } | |
EditItem.Submitting -> | |
{ item | typeData = Text textItem (Just editItem) } | |
( EditLink editItem, Link linkItem _ ) -> | |
case editItem.editState of | |
EditItem.Cancelled -> | |
{ item | typeData = Link linkItem Nothing } | |
EditItem.Successful newItem -> | |
case newItem.typeData of | |
Link newLinkItem _ -> | |
{ item | typeData = Link { linkItem | title = newLinkItem.title, url = newLinkItem.url, description = newLinkItem.description } Nothing } | |
_ -> | |
item | |
EditItem.Editing -> | |
{ item | typeData = Link linkItem (Just editItem) } | |
EditItem.Submitting -> | |
{ item | typeData = Link linkItem (Just editItem) } | |
( EditQuote editItem, Quote quoteItem _ ) -> | |
case editItem.editState of | |
EditItem.Cancelled -> | |
{ item | typeData = Quote quoteItem Nothing } | |
EditItem.Successful newItem -> | |
case newItem.typeData of | |
Quote newQuoteItem _ -> | |
{ item | typeData = Quote { quoteItem | attribution = newQuoteItem.attribution, text = newQuoteItem.text } Nothing } | |
_ -> | |
item | |
EditItem.Editing -> | |
{ item | typeData = Quote quoteItem (Just editItem) } | |
EditItem.Submitting -> | |
{ item | typeData = Quote quoteItem (Just editItem) } | |
_ -> | |
item | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still finishing up cleanup on the function names exactly, but these are placeholders while getting them extracted.