Skip to content

Instantly share code, notes, and snippets.

@ScottHutchinson
Created July 5, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottHutchinson/ab3a737a21910ff766cee23693791826 to your computer and use it in GitHub Desktop.
Save ScottHutchinson/ab3a737a21910ff766cee23693791826 to your computer and use it in GitHub Desktop.
/// 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