Last active
November 8, 2017 15:08
-
-
Save Chadtech/479b11bf01d077d28e1c828523cd5737 to your computer and use it in GitHub Desktop.
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 characters
| type Update | |
| = SmallUpdate | |
| | BigUpdate | |
| | EnormousUpdate | |
| validate : Appointment -> Appointment -> List Update | |
| validate originalModel newModel = | |
| [ differentCustomer | |
| , differentTime | |
| , newService | |
| ] | |
| |> check originalModel newModel | |
| type alias Validation = | |
| Appointment -> Appointment -> List Update | |
| check : Appointment -> Appointment -> List (List Validation) -> List Update | |
| check originalModel newModel validations = | |
| List.map (\v -> v originalModel newModel) validations | |
| |> List.concat | |
| differentCustomer : Validation | |
| differentCustomer originalModel newModel = | |
| if originalModel.customer == newModel.customer then | |
| [] | |
| else | |
| [ BigUpdate ] | |
| -- etc.. | |
| type alias Model = | |
| { --.. | |
| , updates : List Update | |
| } | |
| -- Called after every significant update | |
| checkForUpdates : Model -> Model | |
| checkForUpdates model = | |
| let | |
| updates = | |
| validate model.originalAppointment (toAppointment model) | |
| in | |
| if List.isEmpty updates then | |
| { model | |
| | updates = [] | |
| , updateButtonDisabled = True | |
| } | |
| else | |
| { model | |
| | updates = updates | |
| , updateButtonDisabled = False | |
| } | |
| update msg model = | |
| case msg of | |
| -- .. | |
| UpdateButtonClicked -> | |
| model => updatesToCmds model.updates | |
| updatesToCmds : List Update -> Cmd Msg | |
| updatesToCmds = | |
| List.map fromUpdate >> Cmd.batch | |
| fromUpdate : Update -> Cmd Msg | |
| fromUpdate update = | |
| case update of | |
| BigUpdate -> | |
| Ports.send OneKindOfApiCall | |
| SmallUpdate -> | |
| Ports.send AnotherKindOfApiCall | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment