Skip to content

Commit

Permalink
Merge pull request #497 from halleysfifthinc/fix-scope-observable-lis…
Browse files Browse the repository at this point in the history
…teners

Update use of Observables listeners to current interface
  • Loading branch information
pfitzseb authored Nov 9, 2022
2 parents 2614f4d + 066744d commit 341022b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WebIO"
uuid = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
license = "MIT"
version = "0.8.18"
version = "0.8.19"

[deps]
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
Expand All @@ -24,7 +24,7 @@ AssetRegistry = "0.1.0"
FunctionalCollections = "0.5.0"
JSExpr = "0.5"
JSON = "0.18, 0.19, 0.20, 0.21"
Observables = "0.3, 0.4, 0.5"
Observables = "0.5"
Requires = "0.4.4, 0.5, 1.0.0"
WebSockets = "1.5.0"
Widgets = "0.6.2"
Expand Down
28 changes: 9 additions & 19 deletions src/scope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function JSON.lower(scope::Scope)
if sync === nothing
# by default, we sync if there are any listeners
# other than the JS back edge
sync = any(f-> !isa(f, SyncCallback), listeners(ob))
sync = any(((_, f),) -> !isa(f, SyncCallback), listeners(ob))
end
obs_dict[k] = Dict(
"sync" => sync,
Expand Down Expand Up @@ -332,31 +332,21 @@ struct SyncCallback
end

(s::SyncCallback)(xs...) = s.f(xs...)

"""
Set observable without synchronizing with the counterpart on the browser.
This is mostly used to update observables in response to updates sent from th
browser (so that we aren't sending the same update *back* to the browser).
"""
function set_nosync end

if isdefined(Observables, :setexcludinghandlers)
# Observables <=0.3
function set_nosync(ob, val)
Observables.setexcludinghandlers(ob, val, x -> !(x isa SyncCallback))
return
end
else
# Observables >=0.4
function set_nosync(ob, val)
Observables.setexcludinghandlers!(ob, val)
for f in listeners(ob)
if !(f isa SyncCallback)
Base.invokelatest(f, val)
end
function set_nosync(ob, val)
Observables.setexcludinghandlers!(ob, val)
for (_, f) in listeners(ob)
if !(f isa SyncCallback)
Base.invokelatest(f, val)
end
return
end
return
end

const lifecycle_commands = ["scope_created"]
Expand Down Expand Up @@ -388,7 +378,7 @@ end
function ensure_sync(ctx, key)
ob = ctx.observs[key][1]
# have at most one synchronizing handler per observable
if !any(x->isa(x, SyncCallback) && x.ctx==ctx, listeners(ob))
if !any(((_, x),) ->isa(x, SyncCallback) && x.ctx==ctx, listeners(ob))
f = SyncCallback(ctx, (msg) -> send_update_observable(ctx, key, msg))
on(SyncCallback(ctx, f), ob)
end
Expand Down

2 comments on commit 341022b

@MasonProtter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Register Failed
@MasonProtter, it looks like you are not a publicly listed member/owner in the parent organization (JuliaGizmos).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

Please sign in to comment.