Skip to content

Instantly share code, notes, and snippets.

@qwe2
Created February 9, 2015 13:54
Show Gist options
  • Save qwe2/1306fdadd7df2593b89b to your computer and use it in GitHub Desktop.
Save qwe2/1306fdadd7df2593b89b to your computer and use it in GitHub Desktop.
RPC Test
namespace RPCTest
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.JavaScript
open IntelliFactory.WebSharper.Html.Client
[<JavaScript>]
type RpcResult<'T> =
| Success of 'T
| Error of string
module Server =
let rand = System.Random()
[<Rpc>]
let GetResult () =
if rand.Next 5 > 0 then Success [ 1; 2; 3 ]
else Error "Error."
|> async.Return
[<JavaScript>]
module Client =
let Main () =
let div = Div []
async {
let! res = Server.GetResult ()
match res with
| Success nums ->
nums
|> List.map (fun n -> Div [ Text <| string n ])
|> Div
| Error err ->
Div [ Text err ]
|> (fun el -> div.Append el.Dom)
}
|> Async.Start
div
type ClientControl() =
inherit Web.Control()
[<JavaScript>]
override this.Body = Client.Main () :> _
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment