Created
July 5, 2018 14:24
-
-
Save ScottHutchinson/ab3a737a21910ff766cee23693791826 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
/// The update function knows how to update the model given a message. | |
let update msg model = | |
match model, msg with | |
| { ValidationError = None; Postcode = postcode }, GetReport -> | |
{ model with ServerState = Loading }, Cmd.ofPromise getResponse postcode GotReport ErrorMsg | |
| _, GetReport -> model, Cmd.none | |
| _, GotReport response -> | |
{ model with | |
ValidationError = None | |
Report = Some response | |
ServerState = Idle }, Cmd.none | |
| _, PostcodeChanged p -> | |
let p = p.ToUpper() | |
let validationError p = | |
match Validation.validatePostcode p with | |
| true -> None | |
| _ -> Some "INvalid Postal Code" | |
{ model with | |
Postcode = p | |
(* Task 2.2 Validation. Use the Validation.validatePostcode function to implement client-side form validation. | |
Note that the validation is the same shared code that runs on the server! *) | |
ValidationError = validationError(p) }, Cmd.none | |
| _, ErrorMsg e -> { model with ServerState = ServerError e.Message }, Cmd.none | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment