Skip to content

handle empty children for index by id #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
[compat]
Aqua = "0.6"
CodecZlib = "0.6, 0.7"
DashBase = "0.2"
DashBase = "0.2.1"
DashCoreComponents = "2.0.0"
DashHtmlComponents = "2.0.0"
DashTable = "5.0.0"
Expand Down
21 changes: 0 additions & 21 deletions src/app/dashapp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,6 @@ mutable struct DashApp

end

const VecChildTypes = Union{NTuple{N, DashBase.Component} where {N}, Vector{<:DashBase.Component}}

function Base.getindex(component::DashBase.Component, id::AbstractString)
component.id == id && return component
hasproperty(component, :children) || return nothing
cc = component.children
return if cc isa Union{VecChildTypes, DashBase.Component}
cc[id]
elseif cc isa AbstractVector
identity.(filter(x->hasproperty(x, :id), cc))[id]
else
nothing
end
end
function Base.getindex(children::VecChildTypes, id::AbstractString)
for element in children
element.id == id && return element
el = element[id]
el !== nothing && return el
end
end

#only name, index_string and layout are available to set
function Base.setproperty!(app::DashApp, property::Symbol, value)
Expand Down
14 changes: 0 additions & 14 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,3 @@ end
@test_throws ErrorException make_handler(app)
end

@testset "Index by id" begin
app = dash()
app.layout = html_div() do
dcc_input(id = "my-id", value="initial value", type = "text"),
html_div(id = "my-div", children = [
html_div(),
"string",
html_div(id = "target")
]),
html_div(id = "my-div2")
end
@test app.layout["target"].id == "target"
@test app.layout["ups"] === nothing
end