Skip to content

Commit

Permalink
fix adding of revivers and initscripts, improve deps filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 11, 2024
1 parent d2072bf commit 3ab7cb5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions assets/js/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion src/Layout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/stipple/jsmethods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 3ab7cb5

Please sign in to comment.