Skip to content

Commit

Permalink
Allow interactively revising both update and view as we play
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxWilson committed Mar 4, 2024
1 parent 6f68631 commit 8fe17d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions scratch/GuessNumber.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ let update msg model =
{ model with guesses = model.guesses @ [feedback] }
let view model =
$"You've won {model.wins} times. What you know about this next number: {model.guesses}"
let send = connect init update view
let send, state = connect init update view

send 10
send 5
send 3
send 4
send 4

let view2 model =
let fullGuesses = model.guesses |> List.map (sprintf "%A") |> String.concat ", "
$"Score: {model.wins}. Hints: {fullGuesses}"
let send, state = reconnect state update view2
send 5
15 changes: 11 additions & 4 deletions scratch/SketchUI.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
#endif

let connect init update view =
let mutable current = init()
let state = ref (init())
let dispatch msg =
current <- update msg current
printfn "\n%s" (view current)
dispatch
state.Value <- update msg state.Value
printfn "\n%s" (view state.Value)
dispatch, state

let reconnect (state: _ ref) update view =
printfn "\n[Reconnecting...]\n%s" (view state.Value)
let dispatch msg =
state.Value <- update msg state.Value
printfn "\n%s" (view state.Value)
dispatch, state

0 comments on commit 8fe17d6

Please sign in to comment.