Skip to content

Commit

Permalink
Fix #198: ensure Elt.OnAfterRender() depends on OnAfterRenderControl
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Oct 24, 2018
1 parent aca6ff3 commit 09661a4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
14 changes: 13 additions & 1 deletion WebSharper.UI.Templating.ServerSide.Tests/Main.fs
Expand Up @@ -94,10 +94,22 @@ let Main = Application.SinglePage(fun ctx ->
let s = "[OK] Inserted using .OnAfterRender()"
el.TextContent <- s
)
:> _
:> Doc
div [attr.id "oar-main"] []
MainTemplate.Main.OAR()
.Elt()
.OnAfterRender(fun el ->
let s = "[OK] Inserted using .OnAfterRender() on template"
el.TextContent <- s
)
:> Doc
])
.AfterRender(fun () -> Client.OnStartup())
.TBody([MainTemplate.Main.Row().Doc(); MainTemplate.Main.Row().Doc()])
.Elt(keepUnfilled = true)
.OnAfterRender(fun (_: JavaScript.Dom.Element) ->
let s = "[OK] Inserted using .OnAfterRender() on main template"
JavaScript.JS.Document.GetElementById("oar-main").TextContent <- s
)
)
)
1 change: 1 addition & 0 deletions WebSharper.UI.Templating.ServerSide.Tests/Main.html
Expand Up @@ -36,6 +36,7 @@
$!{Input}
</div>
</div>
<div ws-template="OAR"></div>
<div ws-hole="ClientSide"></div>
<script ws-replace="scripts"></script>
</body>
Expand Down
11 changes: 7 additions & 4 deletions WebSharper.UI/Attr.fs
Expand Up @@ -101,9 +101,11 @@ module private Internal =
doCall s, reqs :> seq<_>
)

type private OnAfterRenderControl() =
type private OnAfterRenderControl private () =
inherit Web.Control()

static member val Instance = new OnAfterRenderControl(ID = "ws.ui.oar") :> IRequiresResources

[<JavaScript>]
override this.Body =
let l = JS.Document.QuerySelectorAll("[ws-runafterrender]")
Expand Down Expand Up @@ -184,16 +186,17 @@ type Attr =
let init meta =
if Option.isNone !value then
value :=
let oarReqs = OnAfterRenderControl.Instance.Requires meta
match Internal.compile meta json q id with
| Some _ as v -> v
| Some (v, m) -> Some (v, Seq.append oarReqs m)
| _ ->
let m =
match q with
| Lambda (x1, Call(None, m, [Var x2])) when x1 = x2 -> m
| _ -> failwithf "Invalid handler function: %A" q
let loc = WebSharper.Web.ClientSideInternals.getLocation' q
let func, reqs = Attr.HandlerFallback(m, loc, id)
Some (func meta, reqs)
Some (func meta, Seq.append oarReqs reqs)
let getValue (meta: M.Info) =
init meta
fst (Option.get !value)
Expand All @@ -202,7 +205,7 @@ type Attr =
snd (Option.get !value)
let enc (meta: M.Info) (json: J.Provider) =
init meta
(new OnAfterRenderControl() :> IRequiresResources).Encode(meta, json)
OnAfterRenderControl.Instance.Encode(meta, json)
DepAttr("ws-runafterrender", getValue, getReqs, enc)

static member HandlerImpl(event: string, q: Expr<Dom.Element -> #Dom.Event -> unit>) =
Expand Down
30 changes: 15 additions & 15 deletions paket.lock
Expand Up @@ -493,18 +493,18 @@ NUGET
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
System.Security.Cryptography.OpenSsl (4.3) - restriction: || (&& (== net461) (< net40) (>= netstandard2.0)) (&& (== net461) (>= netstandard1.6) (>= uap10.0)) (&& (== net471) (< net40)) (&& (== net471) (>= uap10.0)) (== netstandard2.0)
runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - restriction: || (&& (== net461) (>= monoandroid)) (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Collections (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Collections (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.IO (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Runtime.Extensions (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Runtime.Handles (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.InteropServices (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Numerics (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Handles (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.InteropServices (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Numerics (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Security.Cryptography.Algorithms (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Security.Cryptography.Encoding (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Security.Cryptography.Primitives (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Security.Cryptography.Primitives (4.3)
System.Diagnostics.Debug (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
System.Globalization (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
Expand Down Expand Up @@ -661,17 +661,17 @@ NUGET
System.Xml.XmlDocument (>= 4.3)
System.Xml.XPath (>= 4.3)
remote: https://daily.websharper.com/nuget
WebSharper (4.5.4.312)
WebSharper.CSharp (4.5.4.312)
WebSharper (4.5.4.312)
WebSharper.FSharp (4.5.4.312)
WebSharper (4.5.4.312)
WebSharper.Testing (4.5.4.312)
WebSharper (4.5.4.312)
WebSharper (4.5.4.314)
WebSharper.CSharp (4.5.4.314)
WebSharper (4.5.4.314)
WebSharper.FSharp (4.5.4.314)
WebSharper (4.5.4.314)
WebSharper.Testing (4.5.4.314)
WebSharper (4.5.4.314)
GITHUB
remote: fsprojects/FSharp.TypeProviders.SDK
src/ProvidedTypes.fs (45cae888d8cf104b6e02b93cd4ed4546e6762fed)
src/ProvidedTypes.fsi (45cae888d8cf104b6e02b93cd4ed4546e6762fed)
src/ProvidedTypes.fs (7d57cd409d7299592822713195924e42b2b7acde)
src/ProvidedTypes.fsi (7d57cd409d7299592822713195924e42b2b7acde)
GROUP build
RESTRICTION: == net45
NUGET
Expand Down

0 comments on commit 09661a4

Please sign in to comment.