Last active
October 6, 2016 22:16
-
-
Save Tarmil/bda2cc9e63fa184dd48a to your computer and use it in GitHub Desktop.
Revisions
-
Tarmil revised this gist
Mar 13, 2016 . 3 changed files with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ module Counter = Attr.Style "text-align" "center" ] let Render (send: Action -> unit) (model: View<Model>) : Doc = div [ buttonAttr [on.click (fun _ _ -> send Decrement)] [text "-"] divAttr [countStyle] [textView (model.Map string)] 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 charactersOriginal file line number Diff line number Diff line change @@ -13,5 +13,5 @@ module Main = StartApp.Start { Model = 0 Update = Counter.Update Render = Counter.Render } 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ // Straightforward equivalent of Elm's StartApp.Simple // using `Action -> unit` to model Elm's `Signal.Address Action` // and renaming `view` to `Render` to avoid ambiguity with UI.Next's View<'T> module StartApp open WebSharper @@ -11,12 +12,12 @@ type App<'Model, 'Action> = { Model : 'Model Update : 'Action -> 'Model -> 'Model Render : ('Action -> unit) -> View<'Model> -> Doc } [<JavaScript>] let Start (app: App<'Model, 'Action>) : unit = let model = Var.Create app.Model let send = app.Update >> Var.Update model app.Render send model.View |> Doc.RunAppend JS.Document?body -
Tarmil revised this gist
Mar 11, 2016 . 2 changed files with 4 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,10 +26,10 @@ module Counter = Attr.Style "text-align" "center" ] let View (send: Action -> unit) (model: View<Model>) : Doc = div [ buttonAttr [on.click (fun _ _ -> send Decrement)] [text "-"] divAttr [countStyle] [textView (model.Map string)] buttonAttr [on.click (fun _ _ -> send Increment)] [text "+"] ] :> Doc 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 charactersOriginal file line number Diff line number Diff line change @@ -11,13 +11,12 @@ type App<'Model, 'Action> = { Model : 'Model Update : 'Action -> 'Model -> 'Model View : ('Action -> unit) -> View<'Model> -> Doc } [<JavaScript>] let Start (app: App<'Model, 'Action>) : unit = let model = Var.Create app.Model let send = app.Update >> Var.Update model app.View send model.View |> Doc.RunAppend JS.Document?body -
Tarmil created this gist
Mar 11, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ namespace Example1 open WebSharper open WebSharper.UI.Next open WebSharper.UI.Next.Html open WebSharper.UI.Next.Client [<JavaScript>] module Counter = type Model = int type Action = Increment | Decrement let Update (action: Action) (model: Model) : Model = match action with | Increment -> model + 1 | Decrement -> model - 1 let private countStyle = Attr.Concat [ Attr.Style "font-size" "20px" Attr.Style "font-family" "monospace" Attr.Style "display" "inline-block" Attr.Style "width" "50px" Attr.Style "text-align" "center" ] let View (send: Action -> unit) (model: Model) : Doc = div [ buttonAttr [on.click (fun _ _ -> send Decrement)] [text "-"] divAttr [countStyle] [text (string model)] buttonAttr [on.click (fun _ _ -> send Increment)] [text "+"] ] :> Doc 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ namespace Example1 open WebSharper open WebSharper.JavaScript open WebSharper.JQuery open WebSharper.UI.Next open WebSharper.UI.Next.Client [<JavaScript>] module Main = let Main = StartApp.Start { Model = 0 Update = Counter.Update View = Counter.View } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ // Straightforward equivalent of Elm's StartApp.Simple // using `Action -> unit` to model Elm's `Signal.Address Action` module StartApp open WebSharper open WebSharper.JavaScript open WebSharper.UI.Next open WebSharper.UI.Next.Client type App<'Model, 'Action> = { Model : 'Model Update : 'Action -> 'Model -> 'Model View : ('Action -> unit) -> 'Model -> Doc } [<JavaScript>] let Start (app: App<'Model, 'Action>) : unit = let model = Var.Create app.Model let send = app.Update >> Var.Update model model.View |> Doc.BindView (app.View send) |> Doc.RunAppend JS.Document?body