Created
February 9, 2015 13:54
-
-
Save qwe2/1306fdadd7df2593b89b to your computer and use it in GitHub Desktop.
RPC Test
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
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