-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.fs
49 lines (40 loc) · 1.38 KB
/
Client.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
namespace WebSharperPassStateToClient
open WebSharper
open WebSharper.JavaScript
open WebSharper.UI
open WebSharper.UI.Client
open WebSharper.UI.Html
module ClientCode =
[<JavaScriptExport>]
type [<AbstractClass>] A() =
abstract member Doc: Map<string, A> -> Doc
[<JavaScriptExport>]
type [<AbstractClass>] B() =
inherit A()
[<JavaScriptExport>]
type C() =
inherit B()
override __.Doc map =
div [] [
hr [] []
div [] [h1 [] [text "C"]]
div [attr.``class`` "jumbotron"] [ map |> map.["D"].Doc ]
]
[<JavaScriptExport>]
type D() =
inherit A()
override __.Doc _ =
span [attr.``class`` "alert alart-info"] [ text "D" ]
[<JavaScript>]
module Client =
let _map : Var<Map<string, ClientCode.A>> = Var.Create <| Map.empty
let initializeMapping() =
// Here I am hard-coding the mappings of the concrete instances of `ClientCode.A`, entirely in the compiled javascript
// I need to be able to do this mapping from the server-side.
Map.empty
|> Map.add "C" (upcast ClientCode.C() : ClientCode.A)
|> Map.add "D" (upcast ClientCode.D() : ClientCode.A)
|> _map.Set
let getDoc (docName : string) =
_map.View.Map(fun m -> m.[docName].Doc(m))
|> Doc.EmbedView