Skip to content

Commit

Permalink
#240 - Standardize naming of client-server bridge functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jooseppi12 authored and Jand42 committed Oct 4, 2022
1 parent b52acee commit 702f3bd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WebSharper.UI.CSharp/HTML.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Html =
let textView v = Client.Doc.TextView v

/// Insert a client-side Doc.
let client q = Doc.ClientSideLinq q
let client q = WebSharper.UI.ClientServer.clientLinq q

/// Concatenate Docs.
[<JavaScript; Inline>]
Expand Down
2 changes: 2 additions & 0 deletions WebSharper.UI.Routing.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ open WebSharper.UI.Server
open WebSharper.UI.Routing
open Actions


module Site =
open WebSharper.UI.Html
open type WebSharper.UI.ClientServer
open WebSharper.Web

let page (content: seq<INode>) =
Expand Down
17 changes: 17 additions & 0 deletions WebSharper.UI/Doc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,20 @@ type Doc with
static member Verbatim t = ConcreteDoc(VerbatimDoc t) :> Doc

static member OfINode n = ConcreteDoc(INodeDoc n) :> Doc

[<AbstractClass; Sealed>]
type ClientServer =

static member client ([<ReflectedDefinition; JavaScript>] expr: Expr<#IControlBody>) =
Doc.ClientSideImpl expr

static member hydrate ([<ReflectedDefinition(true); JavaScript>] expr: Expr<Doc>) =
match expr with
| Patterns.WithValue(doc, _, docExpr) ->
ConcreteDoc(INodeDoc (new InlineControlWithPlaceHolder (Expr.Cast<Doc> docExpr, doc :?> Doc))) :> Doc
| _ ->
// value missing, nothing to render on server
Doc.ClientSideImpl expr

static member clientLinq (expr: System.Linq.Expressions.Expression<System.Func<IControlBody>>) =
ConcreteDoc(INodeDoc (new Web.CSharpInlineControl(expr))) :> Doc
11 changes: 11 additions & 0 deletions WebSharper.UI/Doc.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ type Doc =
static member internal ClientSideImpl : Expr<#IControlBody> -> Doc

/// Client-side control.
[<Obsolete "Use ClientServer.client instead (or open the type WebSharper.UI.ClientServer) without <@ ... @>.">]
static member ClientSide : [<ReflectedDefinition; JavaScript>] expr: Expr<#IControlBody> -> Doc

/// Client-side control.
[<Obsolete "Use ClientServer.clientLinq instead (or open the type WebSharper.UI.ClientServer).">]
static member ClientSideLinq : System.Linq.Expressions.Expression<System.Func<IControlBody>> -> Doc

/// Client-side control with a server-side placeholder.
[<Obsolete "Use ClientServer.hydrate instead (or open the type WebSharper.UI.ClientServer) without <@ ... @>.">]
static member Hydrate : [<ReflectedDefinition(true); JavaScript>] expr: Expr<Doc> -> Doc

/// Verbatim HTML.
Expand Down Expand Up @@ -599,3 +602,11 @@ type DynDoc =
type ConcreteDoc =
inherit Doc
new : DynDoc -> ConcreteDoc

type [<AbstractClass; Sealed>] ClientServer =

static member client : [<ReflectedDefinition; JavaScript>] expr: Expr<#IControlBody> -> Doc

static member hydrate : [<ReflectedDefinition(true); JavaScript>] expr: Expr<Doc> -> Doc

static member clientLinq : System.Linq.Expressions.Expression<System.Func<IControlBody>> -> Doc
2 changes: 1 addition & 1 deletion WebSharper.UI/HTML.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module Html =

/// Insert a client-side Doc.
[<JavaScript; Inline>]
[<System.Obsolete "This is an alias of Doc.ClientSide. Use Doc.ClientSide directly for auto-quotation support.">]
[<System.Obsolete "This is an alias of ClientServer.client. Use ClientServer.client instead (or open the type WebSharper.UI.ClientServer) without <@ ... @>.">]
let client ([<ReflectedDefinition; JavaScript>] q) = Doc.ClientSide %q

module Elt =
Expand Down

0 comments on commit 702f3bd

Please sign in to comment.