Skip to content

Commit

Permalink
Merge branch 'master' into sd/fix-custom-obsfuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Nov 6, 2023
2 parents 8874ece + f01cc59 commit 77b79a5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ function clear(@nospecialize(obs::Observable))
end

"""
onany(f, args...)
onany(f, args...; weak::Bool = false, priority::Int = 0, update::Bool = false)
Calls `f` on updates to any observable refs in `args`.
`args` may contain any number of `Observable` objects.
Expand All @@ -462,7 +462,7 @@ All other objects in `args` are passed as-is.
See also: [`on`](@ref).
"""
function onany(f, args...; weak::Bool = false, priority::Int=0)
function onany(f, args...; weak::Bool = false, priority::Int = 0, update::Bool = false)
callback = OnAny(f, args)
obsfuncs = ObserverFunction[]
for observable in args
Expand All @@ -471,6 +471,7 @@ function onany(f, args...; weak::Bool = false, priority::Int=0)
push!(obsfuncs, obsfunc)
end
end
update && callback(nothing)
return obsfuncs
end

Expand Down Expand Up @@ -510,13 +511,13 @@ Observable{Number}(1.7320508075688772)
can handle any number type for which `sqrt` is defined.
"""
@inline function Base.map!(@nospecialize(f), result::AbstractObservable, os...; update::Bool=true, weak::Bool=true)
@inline function Base.map!(@nospecialize(f), result::AbstractObservable, os...; update::Bool=true, priority::Int = 0)
# note: the @inline prevents de-specialization due to the splatting
callback = MapCallback(f, result, os)
obsfuncs = ObserverFunction[]
for o in os
if o isa AbstractObservable
obsfunc = on(callback, o)
obsfunc = on(callback, o, priority = priority)
push!(obsfuncs, obsfunc)
end
end
Expand Down Expand Up @@ -560,10 +561,10 @@ julia> map(length, obs)
Observable(3)
```
"""
@inline function Base.map(f::F, arg1::AbstractObservable, args...; ignore_equal_values=false) where F
@inline function Base.map(f::F, arg1::AbstractObservable, args...; ignore_equal_values::Bool=false, priority::Int = 0) where F
# note: the @inline prevents de-specialization due to the splatting
obs = Observable(f(arg1[], map(to_value, args)...); ignore_equal_values=ignore_equal_values)
map!(f, obs, arg1, args...; update=false)
map!(f, obs, arg1, args...; update=false, priority = priority)
return obs
end

Expand Down

0 comments on commit 77b79a5

Please sign in to comment.