Created
May 4, 2017 19:20
-
-
Save b0urb4k1/9175f54f7f72f1964ba60a64e0a51328 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
#r "./packages/FSharp.Control.Reactive/lib/net45/FSharp.Control.Reactive.dll" | |
#r "./packages/System.Reactive.Interfaces/lib/net45/System.Reactive.Interfaces.dll" | |
#r "./packages/System.Reactive.Linq/lib/net45/System.Reactive.Linq.dll" | |
#r "./packages/System.Reactive.Core/lib/net45/System.Reactive.Core.dll" | |
open System | |
open System.Windows.Forms | |
open System.Drawing | |
open FSharp.Control.Reactive | |
type Action = | |
| Increment | |
| Decrement | |
Application.EnableVisualStyles () | |
Application.SetCompatibleTextRenderingDefault false | |
let form = new Form(Width= 400, Height = 300, Visible = true, Text = "Hello World") | |
form.TopMost <- true | |
let panel = new FlowLayoutPanel() | |
panel.Dock <- DockStyle.Fill | |
panel.WrapContents <- false | |
let incBtn = new Button() | |
let decBtn = new Button() | |
let label = new Label() | |
incBtn.Text <- "+" | |
decBtn.Text <- "-" | |
incBtn.AutoSize <- true | |
decBtn.AutoSize <- true | |
panel.Controls.Add(incBtn) | |
panel.Controls.Add(label) | |
panel.Controls.Add(decBtn) | |
let model = 0 | |
let view model = | |
label.Text <- 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) | |
incBtn.Click | |
let decrement = | |
Control.Observable.map | |
(fun _ -> Decrement) | |
decBtn.Click | |
let timer = | |
System.Reactive.Linq.Observable.Interval | |
(System.TimeSpan.FromSeconds (1.0)) | |
let random = | |
Control.Observable.map | |
(fun c -> Increment) | |
timer | |
// let actions = Control.Observable.merge increment decrement | |
let actions = Control.Observable.merge increment random | |
let stateObservable = Control.Observable.scan update model actions | |
Control.Observable.subscribe view stateObservable | |
form.Controls.Add(panel) | |
// form.FormBorderStyle <- FormBorderStyle.SizableToolWindow; | |
form.Resize.Add (fun x -> form.Width <- 400) | |
form.ControlBox <- false | |
form.Text <- "" | |
Application.Run (form) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment