Last active
August 25, 2022 05:11
-
-
Save coreyhaines/cf40b7dca8916b77878c97fdb5c8184e to your computer and use it in GitHub Desktop.
Revisions
-
coreyhaines revised this gist
Jul 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,7 @@ startEditing editable = NotEditing { value } -> newEditing value Editing _ -> editable -
coreyhaines revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -50,7 +50,7 @@ startEditing : Editable ofType -> Editable ofType startEditing editable = case editable of NotEditing { value } -> newEditing value _ -> editable -
coreyhaines revised this gist
Jan 16, 2017 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -41,6 +41,11 @@ newEditing value = Editing { originalValue = value, buffer = value } newNotEditing : ofType -> Editable ofType newNotEditing value = NotEditing { value = value } startEditing : Editable ofType -> Editable ofType startEditing editable = case editable of -
coreyhaines revised this gist
Dec 31, 2016 . 1 changed file with 16 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ module Editable exposing (..) type Editable ofType @@ -16,6 +16,16 @@ value editable = originalValue bufferValue : Editable ofType -> ofType bufferValue editable = case editable of NotEditing { value } -> value Editing { buffer } -> buffer setBuffer : Editable ofType -> ofType -> Editable ofType setBuffer editable newBuffer = case editable of @@ -26,6 +36,11 @@ setBuffer editable newBuffer = Editing { values | buffer = newBuffer } newEditing : ofType -> Editable ofType newEditing value = Editing { originalValue = value, buffer = value } startEditing : Editable ofType -> Editable ofType startEditing editable = case editable of @@ -56,16 +71,6 @@ cancelEditing editable = NotEditing { value = originalValue } isEditing : Editable ofType -> Bool isEditing editable = case editable of -
coreyhaines revised this gist
Dec 29, 2016 . 2 changed files with 38 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,13 @@ module Shared.Editable exposing (..) type Editable ofType = NotEditing { value : ofType } | Editing { originalValue : ofType, buffer : ofType } value : Editable ofType -> ofType value editable = case editable of NotEditing { value } -> value @@ -13,8 +16,8 @@ editableValue editable = originalValue setBuffer : Editable ofType -> ofType -> Editable ofType setBuffer editable newBuffer = case editable of NotEditing _ -> editable @@ -23,18 +26,38 @@ editableSetBuffer editable newBuffer = Editing { values | buffer = newBuffer } startEditing : Editable ofType -> Editable ofType startEditing editable = case editable of NotEditing { value } -> setBuffer editable value _ -> editable finishEditing : Editable ofType -> Editable ofType finishEditing editable = case editable of NotEditing _ -> editable Editing { buffer } -> NotEditing { value = buffer } cancelEditing : Editable ofType -> Editable ofType cancelEditing editable = case editable of NotEditing _ -> editable Editing { originalValue } -> NotEditing { value = originalValue } bufferValue : Editable ofType -> ofType bufferValue editable = case editable of NotEditing { value } -> value @@ -43,8 +66,8 @@ editableBufferValue editable = buffer isEditing : Editable ofType -> Bool isEditing editable = case editable of NotEditing _ -> False @@ -53,12 +76,11 @@ editableIsEditing editable = True hasChanged : Editable comparable -> Bool hasChanged editable = case editable of NotEditing _ -> False Editing { originalValue, buffer } -> originalValue /= buffer This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,13 @@ StartEditingNotebookTitle -> ( { model | notebookTitle = Editable.startEditing model.notebookTitle } , Dom.focus "notebook-title-editor" |> Task.attempt (always NoOp) ) CancelEditingNotebookTitle -> ( { model | notebookTitle = Editable.cancelEditing model.notebookTitle } , Cmd.none ) -
coreyhaines revised this gist
Dec 22, 2016 . 1 changed file with 55 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ StartEditingNotebookTitle -> let notebookTitle = Types.editableValue model.notebookTitle in ( { model | notebookTitle = Editing { originalValue = notebookTitle, buffer = notebookTitle } } , Dom.focus "notebook-title-editor" |> Task.attempt (always NoOp) ) CancelEditingNotebookTitle -> let notebookTitle = Types.editableValue model.notebookTitle in ( { model | notebookTitle = NotEditing { value = notebookTitle } } , Cmd.none ) UpdateEditingNotebookTitle title -> ( { model | notebookTitle = Types.editableSetBuffer model.notebookTitle title } , Cmd.none ) SaveEditingNotebookTitle -> let cmd = saveNotebookTitleCmd model updatedValue = case model.notebookTitle of NotEditing { value } -> model.notebookTitle Editing { buffer } -> NotEditing { value = buffer } in ( { model | notebookTitle = updatedValue } , cmd ) SaveNotebookTitleFailure err -> ( model , Cmd.map IrnMsg <| Irn.showUserAlert "Error Updating Title" ) SaveNotebookTitleSuccess notebook -> ( { model | notebookTitle = NotEditing { value = notebook.title } } , Cmd.map IrnMsg <| Irn.showUserAlert "Notebook Title Updated" ) -
coreyhaines created this gist
Dec 22, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ type Editable ofType = NotEditing { value : ofType } | Editing { originalValue : ofType, buffer : ofType } editableValue : Editable ofType -> ofType editableValue editable = case editable of NotEditing { value } -> value Editing { originalValue } -> originalValue editableSetBuffer : Editable ofType -> ofType -> Editable ofType editableSetBuffer editable newBuffer = case editable of NotEditing _ -> editable Editing values -> Editing { values | buffer = newBuffer } editableStartEditing : Editable ofType -> Editable ofType editableStartEditing editable = case editable of NotEditing { value } -> editableSetBuffer editable value _ -> editable editableBufferValue : Editable ofType -> ofType editableBufferValue editable = case editable of NotEditing { value } -> value Editing { buffer } -> buffer editableIsEditing : Editable ofType -> Bool editableIsEditing editable = case editable of NotEditing _ -> False Editing _ -> True editableHasChanged : Editable comparable -> Bool editableHasChanged editable = case editable of NotEditing _ -> False Editing { originalValue, buffer } -> originalValue /= buffer