Skip to content

Commit 291f81c

Browse files
remove type piracy
1 parent 13bb206 commit 291f81c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/app/dashapp.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ function Base.getindex(component::DashBase.Component, id::AbstractString)
4848
component.id == id && return component
4949
hasproperty(component, :children) || return nothing
5050
cc = component.children
51-
cc isa Union{VecChildTypes, DashBase.Component, Vector{Any}} ? cc[id] : nothing
51+
return if cc isa Union{VecChildTypes, DashBase.Component}
52+
cc[id]
53+
elseif cc isa AbstractVector
54+
identity.(filter(x->hasproperty(x, :id), cc))[id]
55+
else
56+
nothing
57+
end
5258
end
5359
function Base.getindex(children::VecChildTypes, id::AbstractString)
5460
for element in children
@@ -57,14 +63,6 @@ function Base.getindex(children::VecChildTypes, id::AbstractString)
5763
el !== nothing && return el
5864
end
5965
end
60-
function Base.getindex(children::AbstractVector, id::AbstractString)
61-
for element in children
62-
hasproperty(element, :id) || continue
63-
element.id == id && return element
64-
el = element[id]
65-
el !== nothing && return el
66-
end
67-
end
6866

6967
#only name, index_string and layout are available to set
7068
function Base.setproperty!(app::DashApp, property::Symbol, value)

test/core.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,5 @@ end
213213
html_div(id = "my-div2")
214214
end
215215
@test app["target"].id == "target"
216+
@test app["ups"] === nothing
216217
end

0 commit comments

Comments
 (0)