diff --git a/assets/js/watchers.js b/assets/js/watchers.js index 2a467f1b..4cd55efb 100644 --- a/assets/js/watchers.js +++ b/assets/js/watchers.js @@ -81,8 +81,9 @@ const reviveMixin = { const eventMixin = { methods: { - handle_event: function (event_data, event_handler) { + handle_event: function (event_data, event_handler, mode) { console.debug('event: ' + JSON.stringify(event_data) + ":" + event_handler) + if (mode=='addclient') { event_data._addclient = true} Genie.WebChannels.sendMessageTo(window.CHANNEL, 'events', { 'event': { 'name': event_handler, diff --git a/src/Elements.jl b/src/Elements.jl index e4c9a7c7..31440780 100644 --- a/src/Elements.jl +++ b/src/Elements.jl @@ -359,6 +359,7 @@ Sometimes preprocessing of the events is necessary, e.g. to add or skip informat ``` """ macro on(arg, expr, preprocess = nothing) + preprocess isa QuoteNode && preprocess == :(:addclient) && (preprocess = "event._addclient = true") kw = Symbol("v-on:", arg isa String ? arg : arg isa QuoteNode ? arg.value : arg.head == :vect ? join(lstrip.(string.(arg.args), ':'), '.') : throw("Value '$arg' for `arg` not supported. `arg` should be of type Symbol, String, or Vector{Union{String, Symbol}}")) @@ -370,7 +371,7 @@ macro on(arg, expr, preprocess = nothing) :(replace("""function(event) { const preprocess = (event) => { """ * replace($preprocess, '"' => "\\\"") * """; return event } handle_event(preprocess(event), '$($(esc(expr)))') - }'""", '\n' => ';')) + }""", '\n' => ';')) end else esc_expr(expr) diff --git a/src/Stipple.jl b/src/Stipple.jl index 7c8b5e2b..7057e0b9 100644 --- a/src/Stipple.jl +++ b/src/Stipple.jl @@ -525,6 +525,13 @@ function init(::Type{M}; # form handler parameter & call event notifier handler = Symbol(get(event, "name", nothing)) event_info = get(event, "event", nothing) + + # add client id if requested + if event_info isa Dict && get(event_info, "_addclient", false) + client = transport == Genie.WebChannels ? Genie.WebChannels.id(Genie.Requests.wsclient()) : Genie.Requests.wtclient() + push!(event_info, "_client" => client) + end + isempty(methods(notify, (M, Val{handler}))) || notify(model, Val(handler)) isempty(methods(notify, (M, Val{handler}, Any))) || notify(model, Val(handler), event_info) LAST_ACTIVITY[Symbol(channel)] = now()