diff --git a/assets/js/watchers.js b/assets/js/watchers.js index a9b6214..9f973cc 100644 --- a/assets/js/watchers.js +++ b/assets/js/watchers.js @@ -67,7 +67,7 @@ const watcherMixin = { }, push: function (field) { - Genie.WebChannels.sendMessageTo(this.channel_, 'watchers', {'payload': { + this.WebChannel.sendMessageTo(this.channel_, 'watchers', {'payload': { 'field': field, 'newval': this[field], 'oldval': null, @@ -110,7 +110,7 @@ const eventMixin = { if (event_data === undefined) { event_data = {} } console.debug('event: ' + JSON.stringify(event_data) + ":" + event_handler) if (mode=='addclient') { event_data._addclient = true} - Genie.WebChannels.sendMessageTo(this.channel_, 'events', { + this.WebChannel.sendMessageTo(this.channel_, 'events', { 'event': { 'name': event_handler, 'event': event_data diff --git a/src/Elements.jl b/src/Elements.jl index 200ffee..9c478aa 100644 --- a/src/Elements.jl +++ b/src/Elements.jl @@ -177,7 +177,7 @@ function vue_integration(::Type{M}; }); $app = window.GENIEMODEL = app.mount(rootSelector); window.channelIndex = window.channelIndex || 0; - $app.WebChannel = Genie.AllWebChannels[channelIndex]; + $app.WebChannel = Genie.WebChannels; $app.WebChannel.parent = $app; $app.channel_ = $app.WebChannel.channel; diff --git a/src/Layout.jl b/src/Layout.jl index 03ac188..4f02fc7 100644 --- a/src/Layout.jl +++ b/src/Layout.jl @@ -16,6 +16,25 @@ const THEMES = Ref(Function[]) const FLEXGRID_KWARGS = [:col, :xs, :sm, :md, :lg, :xl, :gutter, :xgutter, :ygutter] +""" + make_unique!(src::Vector, condition::Union{Nothing, Function} = nothing) + +Utility function for removing duplicates from a vector that fulfill a given condition. +""" +function make_unique!(src::Vector, condition::Union{Nothing, Function} = nothing) + seen = Int[] + dups = Int[] + for (i, name) in enumerate(src) + if name ∈ view(src, seen) && (condition === nothing || condition(name)) + push!(dups, i) + else + push!(seen, i) + end + end + + deleteat!(src, dups) +end + """ function layout(output::Union{String,Vector}; partial::Bool = false, title::String = "", class::String = "", style::String = "", head_content::String = "", channel::String = Genie.config.webchannels_default_route) :: String @@ -53,7 +72,9 @@ function layout(output::Union{S,Vector}, m::Union{M, Vector{M}}; output theme(; core_theme) Stipple.deps.(m)... - ] |> union + ] + + make_unique!(content, contains(r"src=|href="i)) partial && return content diff --git a/src/Stipple.jl b/src/Stipple.jl index e56815c..2f22cab 100644 --- a/src/Stipple.jl +++ b/src/Stipple.jl @@ -854,7 +854,6 @@ end function initscript(vue_app_name) :: String Genie.Renderer.Html.script([""" - // script id: $(randstring(64)) document.addEventListener("DOMContentLoaded", () => window.create$vue_app_name() ); """]) end diff --git a/src/stipple/jsmethods.jl b/src/stipple/jsmethods.jl index fb4017f..7d6bc24 100644 --- a/src/stipple/jsmethods.jl +++ b/src/stipple/jsmethods.jl @@ -204,9 +204,9 @@ myreviver: function(key, value) { return (key.endsWith('_onebased') ? value - 1 """ function js_add_reviver(revivername::String) """ - Genie.WebChannels.subscriptionHandlers.push(function(event) { + document.addEventListener("DOMContentLoaded", () => Genie.WebChannels.subscriptionHandlers.push(function(event) { Genie.Revivers.addReviver($revivername); - }); + })); """ end @@ -222,9 +222,9 @@ It needs to be added to the dependencies of an app in order to be executed, e.g. """ function js_initscript(initscript::String) """ - Genie.WebChannels.subscriptionHandlers.push(function(event) { + document.addEventListener("DOMContentLoaded", () => Genie.WebChannels.subscriptionHandlers.push(function(event) { $(initscript) - }); + })); """ end