Skip to content

Commit c259287

Browse files
Fix error thrown when updating Observable listeners
Non-MWE: - In IJulia, with PlotlyJS, an observer on a plot event (e.g. "hover", "click", etc) gave the following error when updating/being run: ```julia KERNEL EXCEPTION MethodError: objects of type Pair{Int64, Any} are not callable Stacktrace: [1] #invokelatest#2 @ ./essentials.jl:729 [inlined] [2] invokelatest @ ./essentials.jl:726 [inlined] [3] set_nosync(ob::Observable{Dict{Any, Any}}, val::Dict{String, Any}) @ WebIO ~/.julia/dev/WebIO/src/scope.jl:355 [4] dispatch(ctx::Scope, key::String, data::Dict{String, Any}) @ WebIO ~/.julia/dev/WebIO/src/scope.jl:368 [5] dispatch_command(conn::WebIO.IJuliaConnection, data::Dict{String, Any}) @ WebIO ~/.julia/dev/WebIO/src/messaging.jl:104 [6] dispatch(conn::WebIO.IJuliaConnection, data::Dict{String, Any}) @ WebIO ~/.julia/dev/WebIO/src/messaging.jl:81 [7] (::WebIO.var"#97#98"{WebIO.IJuliaConnection})(msg::IJulia.Msg) @ WebIO ~/.julia/dev/WebIO/src/providers/ijulia.jl:21 [8] comm_msg(sock::ZMQ.Socket, msg::IJulia.Msg) @ IJulia.CommManager ~/.julia/packages/IJulia/AQu2H/src/comm_manager.jl:134 [9] #invokelatest#2 @ ./essentials.jl:729 [inlined] [10] invokelatest @ ./essentials.jl:726 [inlined] [11] eventloop(socket::ZMQ.Socket) @ IJulia ~/.julia/packages/IJulia/AQu2H/src/eventloop.jl:8 [12] (::IJulia.var"#15#18")() @ IJulia ./task.jl:484 ``` I narrowed the problem down to an incorrect assumption about what is returned from `Observables.listeners`. The previous expectation was an array of functions, the reality is a `Vector{Pair,Function}`.
1 parent a34c405 commit c259287

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ AssetRegistry = "0.1.0"
2424
FunctionalCollections = "0.5.0"
2525
JSExpr = "0.5"
2626
JSON = "0.18, 0.19, 0.20, 0.21"
27-
Observables = "0.3, 0.4, 0.5"
27+
Observables = "0.4, 0.5"
2828
Requires = "0.4.4, 0.5, 1.0.0"
2929
WebSockets = "1.5.0"
3030
Widgets = "0.6.2"

src/scope.jl

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,31 +332,21 @@ struct SyncCallback
332332
end
333333

334334
(s::SyncCallback)(xs...) = s.f(xs...)
335+
335336
"""
336337
Set observable without synchronizing with the counterpart on the browser.
337338
338339
This is mostly used to update observables in response to updates sent from th
339340
browser (so that we aren't sending the same update *back* to the browser).
340341
"""
341-
function set_nosync end
342-
343-
if isdefined(Observables, :setexcludinghandlers)
344-
# Observables <=0.3
345-
function set_nosync(ob, val)
346-
Observables.setexcludinghandlers(ob, val, x -> !(x isa SyncCallback))
347-
return
348-
end
349-
else
350-
# Observables >=0.4
351-
function set_nosync(ob, val)
352-
Observables.setexcludinghandlers!(ob, val)
353-
for f in listeners(ob)
354-
if !(f isa SyncCallback)
355-
Base.invokelatest(f, val)
356-
end
342+
function set_nosync(ob, val)
343+
Observables.setexcludinghandlers!(ob, val)
344+
for (_, f) in listeners(ob)
345+
if !(f isa SyncCallback)
346+
Base.invokelatest(f, val)
357347
end
358-
return
359348
end
349+
return
360350
end
361351

362352
const lifecycle_commands = ["scope_created"]

0 commit comments

Comments
 (0)