Skip to content

Commit e100c0f

Browse files
add index by id
1 parent bb6b7a4 commit e100c0f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/app/dashapp.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ mutable struct DashApp
4040

4141
end
4242

43+
const VecChildTypes = Union{NTuple{N, DashBase.Component} where {N}, Vector{<:DashBase.Component}}
44+
function Base.getindex(app::Dash.DashApp, id::AbstractString)
45+
app.layout[id]
46+
end
47+
function Base.getindex(component::DashBase.Component, id::AbstractString)
48+
component.id == id && return component
49+
hasproperty(component, :children) || return nothing
50+
cc = component.children
51+
cc isa Union{VecChildTypes, DashBase.Component} ? cc[id] : nothing
52+
end
53+
function Base.getindex(children::VecChildTypes, id::AbstractString)
54+
for element in children
55+
element.id == id && return element
56+
el = element[id]
57+
el !== nothing && return el
58+
end
59+
end
60+
4361
#only name, index_string and layout are available to set
4462
function Base.setproperty!(app::DashApp, property::Symbol, value)
4563
property == :index_string && return set_index_string!(app, value)

0 commit comments

Comments
 (0)