Created
February 1, 2018 15:03
-
-
Save voronoipotato/8017774b468adc91bad1a086de0f53e0 to your computer and use it in GitHub Desktop.
This file contains 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
#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