Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Observables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ mutable struct Observable{T} <: AbstractObservable{T}

listeners::Vector{Pair{Int, Any}}
inputs::Vector{Any} # for map!ed Observables
ignore_equal_values::Bool
isinvalid::Union{Nothing, Function}
val::T

function Observable{T}(; ignore_equal_values::Bool=false) where {T}
return new{T}(Pair{Int, Any}[], [], ignore_equal_values)
return new{T}(Pair{Int, Any}[], [], ignore_equal_values ? isequal : nothing)
end
function Observable{T}(@nospecialize(val); ignore_equal_values::Bool=false) where {T}
return new{T}(Pair{Int, Any}[], [], ignore_equal_values, val)
return new{T}(Pair{Int, Any}[], [], ignore_equal_values ? isequal : nothing, val)
end
end

Expand Down Expand Up @@ -79,8 +79,8 @@ listeners(observable::Observable) = observable.listeners
Updates the value of an `Observable` to `val` and call its listeners.
"""
function Base.setindex!(@nospecialize(observable::Observable), @nospecialize(val))
if observable.ignore_equal_values
isequal(observable.val, val) && return
if !isnothing(observable.isinvalid)
observable.isinvalid(observable.val, val) && return
end
observable.val = val
return notify(observable)
Expand Down