diff --git a/src/sitelets/WebSharper.Web/Control.fs b/src/sitelets/WebSharper.Web/Control.fs index 5e2e3c84..2fa04fbf 100644 --- a/src/sitelets/WebSharper.Web/Control.fs +++ b/src/sitelets/WebSharper.Web/Control.fs @@ -277,8 +277,9 @@ module ClientSideInternals = open ClientSideInternals -/// Implements a web control based on a quotation-wrapped top-level body. -/// Use the function ClientSide or ctx.ClientSide to create an InlineControl. +/// Embed the given client-side control body in a server-side control. +/// The client-side control body must be an implicit or explicit quotation expression. +/// It can capture local variables, of the same types which are serializable by WebSharper as RPC results. [] type InlineControl<'T when 'T :> IControlBody>(elt: Expr<'T>) = inherit Control() @@ -330,6 +331,11 @@ type InlineControl<'T when 'T :> IControlBody>(elt: Expr<'T>) = member this.Encode(meta, json) = [this.ID, json.GetEncoder(this.GetType()).Encode this] + /// Embed the given client-side control body in a server-side control. + /// The client-side control body must be an implicit or explicit quotation expression. + /// It can capture local variables, of the same types which are serializable by WebSharper as RPC results. + static member Create<'T when 'T :> IControlBody> ([] e: Expr<'T>) = + new InlineControl<'T>(e) open System open System.Reflection @@ -435,8 +441,6 @@ module WebExtensions = open Microsoft.FSharp.Quotations open WebSharper.Web - /// Embed the given client-side control body in a server-side control. - /// The client-side control body must be an implicit or explicit quotation expression. - /// It can capture local variables, of the same types which are serializable by WebSharper as RPC results. + [] let ClientSide ([] e: Expr<#IControlBody>) = new InlineControl<_>(e) diff --git a/tests/WebSharper.Sitelets.Tests/SampleSite.fs b/tests/WebSharper.Sitelets.Tests/SampleSite.fs index 5c8b9cfa..a53cba1f 100644 --- a/tests/WebSharper.Sitelets.Tests/SampleSite.fs +++ b/tests/WebSharper.Sitelets.Tests/SampleSite.fs @@ -195,7 +195,7 @@ module SampleSite = yield! t.Login yield! t.Menu yield! t.Body - yield ClientSide <@ Client.Widget () @> :> _ + yield Web.InlineControl.Create ( Client.Widget () ) :> _ ] ) } @@ -233,18 +233,18 @@ module SampleSite = [ Elt("h1", Text "Welcome to our site!") "Let us know how we can contact you" => ctx.Link Action.Contact - Elt("div", ClientSide <@ Client.Elt "b" [|Client.Text "It's working baby"|] @>) + Elt("div", Web.InlineControl.Create (Client.Elt "b" [|Client.Text "It's working baby"|] )) Elt("div", Text """This should say 'Checking "attribute" encoding':""", Elt("input", Attr("placeholder", """Checking "attribute" encoding""")) ) Elt("div", - ClientSide - <@ Client.Elt "i" [| + Web.InlineControl.Create + ( Client.Elt "i" [| Client.Text "On the " Client.Elt "b" [|Client.Text "client side"|] Client.Text " too!" - |] @>) + |] )) ] /// A page to collect contact information. diff --git a/tests/WebSharper.StaticHtml.Tests.NetStandard/Main.fs b/tests/WebSharper.StaticHtml.Tests.NetStandard/Main.fs index f7cdab11..9d274e03 100644 --- a/tests/WebSharper.StaticHtml.Tests.NetStandard/Main.fs +++ b/tests/WebSharper.StaticHtml.Tests.NetStandard/Main.fs @@ -57,18 +57,18 @@ module Site = Body = [ Elt("h1", Text "Welcome to our site!") "About us" => ctx.Link EndPoint.About - Elt("div", ClientSide <@ Client.Elt "b" [|Client.Text "It's working baby"|] @>) + Elt("div", Web.InlineControl.Create ( Client.Elt "b" [|Client.Text "It's working baby"|] )) Elt("div", Text """This should say 'Checking "attribute" encoding':""", Elt("input", Attr("placeholder", """Checking "attribute" encoding""")) ) Elt("div", - ClientSide - <@ Client.Elt "i" [| + Web.InlineControl.Create + ( Client.Elt "i" [| Client.Text "On the " Client.Elt "b" [|Client.Text "client side"|] Client.Text " too!" - |] @>) + |] )) Elt("div", ClientSide <@ Client.Main() @>) ] ) diff --git a/tests/Website/Content.fs b/tests/Website/Content.fs index 7d4b5f12..6db0a4ac 100644 --- a/tests/Website/Content.fs +++ b/tests/Website/Content.fs @@ -95,16 +95,16 @@ let TestsPage runServerTests autoStart (ctx: Context) = Title = "WebSharper client-side tests", Body = ( [ - yield ClientSide <@ WebSharper.Tests.Main.RunTests runServerTests autoStart @> :> Web.Control - yield ClientSide <@ WebSharper.Collections.Tests.Main.RunTests() @> :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Tests.Main.RunTests runServerTests autoStart ) :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Collections.Tests.Main.RunTests() ) :> Web.Control yield WebSharper.CSharp.Tests.InlineControlTest.RunTestsControl runServerTests - yield ClientSide <@ Client.ClientSideTupleTest t12 @> :> Web.Control - yield ClientSide <@ WebSharper.Html5.Tests.Main.RunTests true @> :> Web.Control - yield ClientSide <@ WebSharper.Sitelets.Tests.ClientServerTests.RunTests apiBaseUri corsBaseUri runServerTests @> :> Web.Control + yield Web.InlineControl.Create ( Client.ClientSideTupleTest t12 ) :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Html5.Tests.Main.RunTests true ) :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Sitelets.Tests.ClientServerTests.RunTests apiBaseUri corsBaseUri runServerTests ) :> Web.Control if runServerTests then - yield ClientSide <@ WebSharper.Sitelets.Tests.ApiTests.RunTests apiBaseUri @> :> Web.Control - yield ClientSide <@ WebSharper.Module.Tests.Main.RunTests() @> :> Web.Control - yield ClientSide <@ WebSharperWebTestsMain.RunTests jsonBaseUri runServerTests @> :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Sitelets.Tests.ApiTests.RunTests apiBaseUri ) :> Web.Control + yield Web.InlineControl.Create ( WebSharper.Module.Tests.Main.RunTests() ) :> Web.Control + yield Web.InlineControl.Create ( WebSharperWebTestsMain.RunTests jsonBaseUri runServerTests ) :> Web.Control ] : list ) )