Skip to content

Instantly share code, notes, and snippets.

@voronoipotato
Created January 4, 2018 19:05
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 voronoipotato/20cc6210c4608c1f4162270d4dba8964 to your computer and use it in GitHub Desktop.
Save voronoipotato/20cc6210c4608c1f4162270d4dba8964 to your computer and use it in GitHub Desktop.
#r "WindowsBase"
#r "PresentationCore"
#r "PresentationFramework"
open System.Windows
open System.Windows.Controls
type Action =
| Increment
| Decrement
let incButton = Button(Content="+")
let decButton = Button(Content="-")
let label = Label(Content="Hello")
let model = 0
let view model =
label.Content <- sprintf "%d" model
let update (model : int32) (action : Action) =
match action with
| Increment -> model + 1
| Decrement -> model - 1
let increment = Control.Observable.map (fun _ -> Increment) incButton.Click
let decrement = Control.Observable.map (fun _ -> Decrement) decButton.Click
let actions = Control.Observable.merge increment decrement
let stateObservable = Control.Observable.scan update model actions
Control.Observable.subscribe view stateObservable
let layout = StackPanel()
layout.Children.Add label
layout.Children.Add incButton
layout.Children.Add decButton
let window =
Window(
Content = layout,
Visibility = Visibility.Visible)
let app = Application(MainWindow = window)
app.Run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment