Skip to content
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 .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- run:
name: 🔎 Unit tests
command: |
julia -e 'using Pkg; Pkg.update(); Pkg.add(PackageSpec(url="https://github.com/plotly/Dash.jl.git", rev=ENV["CIRCLE_BRANCH"])); Pkg.add(PackageSpec(url="https://github.com/waralex/dash-html-components.git", rev="jl_generator_test")); Pkg.add(PackageSpec(url="https://github.com/waralex/dash-core-components.git", rev="jl_generator_test")); Pkg.build("Dash"); Pkg.build("DashHtmlComponents"); Pkg.build("DashCoreComponents"); Pkg.test("Dash", coverage=true); function precompile_pkgs(); for pkg in collect(keys(Pkg.installed())); if !isdefined(Symbol(pkg), :Symbol) && pkg != "Compat.jl"; @info("Importing $(pkg)..."); try (@eval import $(Symbol(pkg))) catch end; end; end; end; precompile_pkgs()'
julia -e 'using Pkg; Pkg.update(); Pkg.add(PackageSpec(url="https://github.com/waralex/DashBase.jl.git")); Pkg.add(PackageSpec(url="https://github.com/waralex/dash-html-components.git", rev="jl_reverse_test")); Pkg.add(PackageSpec(url="https://github.com/waralex/dash-core-components.git", rev="jl_reverse_test"));Pkg.add(PackageSpec(url="https://github.com/waralex/dash-table.git", rev="jl_reverse_test")); Pkg.add(PackageSpec(url="https://github.com/plotly/Dash.jl.git", rev=ENV["CIRCLE_BRANCH"])); Pkg.build("Dash");Pkg.test("Dash", coverage=true); function precompile_pkgs(); for pkg in collect(keys(Pkg.installed())); if !isdefined(Symbol(pkg), :Symbol) && pkg != "Compat.jl"; @info("Importing $(pkg)..."); try (@eval import $(Symbol(pkg))) catch end; end; end; end; precompile_pkgs()'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awfully hard to tell what's changing here - perhaps we can move this to a separate .jl file? To make clear that it's meant only for CI we can put it in the .circleci folder - similar to what we do with the plotly.js test script.


- run:
name: ⚙️ Integration tests
Expand Down
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ version = "0.1.0"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
DashBase = "03207cf0-e2b3-4b91-9ca8-690cf0fb507e"
DashCoreComponents = "1b08a953-4be3-4667-9a23-03c9473d1193"
DashHtmlComponents = "1b08a953-4be3-4667-9a23-341813c6f7a5"
DashTable = "1b08a953-4be3-4667-9a23-d3c7dd0aada8"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
45 changes: 3 additions & 42 deletions src/Components.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
module Components
import JSON2
export Component, <|, hasproperty, is_prop_available, validate

abstract type AbstractComponent end


struct Component <: AbstractComponent
type ::String
namespace ::String
props ::Dict{Symbol, Any}
available_props ::Set{Symbol}
wildcard_props ::Set{Symbol}
end

JSON2.@format Component begin
available_props => (exclude = true,)
wildcard_props => (exclude = true,)
end

function <|(comp::Component, value::Any)
comp.props["children"] = value
return comp
end

hasproperty(c::Component, prop::Symbol) = haskey(c.props, prop)
function is_prop_available(c::Component, prop::Symbol)
if length(c.wildcard_props) > 0
wild_regs = Regex("^(?<prop>$(join(c.wildcard_props, "|")))")
if !isnothing(match(wild_regs, string(prop)))
return true
end
end

return prop in c.available_props
end


function _validate_children(children::Union{Vector, Tuple}, ids::Set{Symbol})
for child in children
Expand All @@ -48,17 +11,15 @@ function _validate_children(children, ids::Set{Symbol}) end


function _validate(comp::Component, ids::Set{Symbol})
if haskey(comp.props, :id)
id = Symbol(comp.props[:id])
if hasproperty(comp, :id) && !isnothing(comp.id)
id = Symbol(comp.id)
id in ids && error("Duplicate component id found in the initial layout: $(id)")
push!(ids, id)
end
_validate_children(get(comp.props, :children, nothing), ids)
hasproperty(comp, :children) && _validate_children(comp.children, ids)
end
function _validate(non_comp, ids::Set{Symbol}) end

function validate(comp::Component)
_validate(comp, Set{Symbol}())
end

end
79 changes: 74 additions & 5 deletions src/Dash.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module Dash
import HTTP, JSON2, CodecZlib, MD5
using Sockets
using MacroTools
using DashBase
const ROOT_PATH = realpath(joinpath(@__DIR__, ".."))
const RESOURCE_PATH = realpath(joinpath(ROOT_PATH, "resources"))

include("Components.jl")
include("Front.jl")
import .Front
using .Components

export dash, Component, Front, callback!,
enable_dev_tools!, ClientsideFunction,
run_server, PreventUpdate, no_update, @var_str,
Input, Output, State, make_handler
Input, Output, State, make_handler,
DashBase



#ComponentPackages.@reg_components()
include("env.jl")
include("utils.jl")
include("app.jl")
include("resources/registry.jl")
include("resources/application.jl")
include("handlers.jl")

Expand Down Expand Up @@ -163,4 +163,73 @@ end
get_inetaddr(host::String, port::Integer) = Sockets.InetAddr(parse(IPAddr, host), port)
get_inetaddr(host::IPAddr, port::Integer) = Sockets.InetAddr(host, port)


function __init__()
DashBase.main_registry().dash_dependency = (
dev = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.2.2",
[
Resource(
relative_package_path = "react@16.8.6/umd/react.production.min.js",
external_url = "https://unpkg.com/react@16.8.6/umd/react.production.min.js",
),
Resource(
relative_package_path = "react-dom@16.8.6/dist/react-dom.production.min.js",
external_url = "https://unpkg.com/browse/react-dom@16.8.6/umd/react-dom.production.min.js"
),
Resource(
relative_package_path = "polyfill@7.7.0/dist/polyfill.min.js",
external_url = "https://unpkg.com/@babel/polyfill@7.7.0/dist/polyfill.min.js"
),
Resource(
relative_package_path = "prop-types@15.7.2/prop-types/prop-types.js",
external_url = "https://unpkg.com/prop-types@15.7.2/prop-types.js",
),
]
),
prod = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.2.2",
[
Resource(
relative_package_path = "react@16.8.6/umd/react.production.min.js",
external_url = "https://unpkg.com/react@16.8.6/umd/react.production.min.js",
),
Resource(
relative_package_path = "react-dom@16.8.6/dist/react-dom.production.min.js",
external_url = "https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"
),
Resource(
relative_package_path = "polyfill@7.7.0/dist/polyfill.min.js",
external_url = "https://unpkg.com/@babel/polyfill@7.7.0/dist/polyfill.min.js"
),
Resource(
relative_package_path = "prop-types@15.7.2/prop-types/prop-types.min.js",
external_url = "https://unpkg.com/prop-types@15.7.2/prop-types.min.js",
),
]
)
)

DashBase.main_registry().dash_renderer = ResourcePkg(
"dash_renderer",
RESOURCE_PATH, version = "1.2.2",
[
Resource(
relative_package_path = "dash-renderer@1.2.2/dash-renderer/dash_renderer.min.js",
dev_package_path = "dash-renderer@1.2.2/dash-renderer/dash_renderer.dev.js",
external_url = "https://unpkg.com/dash-renderer@1.2.2/dash_renderer/dash_renderer.min.js"
),
Resource(
relative_package_path = "dash-renderer@1.2.2/dash-renderer/dash_renderer.min.js.map",
dev_package_path = "dash-renderer@1.2.2/dash-renderer/dash_renderer.dev.js.map",
dynamic = true,
),
]
)


end

end # module
13 changes: 0 additions & 13 deletions src/Front.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
module Front
import JSON, JSON2, PlotlyBase


to_dash(t::Any) = t
from_dash(::Type{Any}, t::Any) = t


function from_dash(::Type{PlotlyBase.Plot}, t)
data = PlotlyBase.GenericTrace[PlotlyBase.GenericTrace(tr) for tr in t.data]
layout = PlotlyBase.Layout(t.layout)
PlotlyBase.Plot(data, layout)
end

#FIXME It's not elegant, but I didn't find elegant soluiton
JSON2.write(io::IO, p::PlotlyBase.Plot; kwargs...) = write(io, JSON.json(p))
end
4 changes: 2 additions & 2 deletions src/handler/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function _process_callback(app::DashApp, body::String)
return Dict(
:response => Dict(
:props => Dict(
Symbol(app.callbacks[output].dependencies.output[1].property) => Front.to_dash(res)
Symbol(app.callbacks[output].dependencies.output[1].property) => DashBase.to_dash(res)
)
)
)
Expand All @@ -72,7 +72,7 @@ function _process_callback(app::DashApp, body::String)
if !(res[ind] isa NoUpdate)
push!(response,
Symbol(out.id) => Dict(
Symbol(out.property) => Front.to_dash(res[ind])
Symbol(out.property) => DashBase.to_dash(res[ind])
)
)
end
Expand Down
134 changes: 0 additions & 134 deletions src/resources/registry.jl

This file was deleted.

13 changes: 0 additions & 13 deletions test/Project.toml

This file was deleted.

Loading