Skip to content

Commit 341022b

Browse files
authored
Merge pull request #497 from halleysfifthinc/fix-scope-observable-listeners
Update use of Observables listeners to current interface
2 parents 2614f4d + 066744d commit 341022b

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "WebIO"
22
uuid = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
33
license = "MIT"
4-
version = "0.8.18"
4+
version = "0.8.19"
55

66
[deps]
77
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
@@ -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.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: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ function JSON.lower(scope::Scope)
242242
if sync === nothing
243243
# by default, we sync if there are any listeners
244244
# other than the JS back edge
245-
sync = any(f-> !isa(f, SyncCallback), listeners(ob))
245+
sync = any(((_, f),) -> !isa(f, SyncCallback), listeners(ob))
246246
end
247247
obs_dict[k] = Dict(
248248
"sync" => sync,
@@ -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"]
@@ -388,7 +378,7 @@ end
388378
function ensure_sync(ctx, key)
389379
ob = ctx.observs[key][1]
390380
# have at most one synchronizing handler per observable
391-
if !any(x->isa(x, SyncCallback) && x.ctx==ctx, listeners(ob))
381+
if !any(((_, x),) ->isa(x, SyncCallback) && x.ctx==ctx, listeners(ob))
392382
f = SyncCallback(ctx, (msg) -> send_update_observable(ctx, key, msg))
393383
on(SyncCallback(ctx, f), ob)
394384
end

0 commit comments

Comments
 (0)