Skip to content

Commit c021c17

Browse files
committed
in work
1 parent 30f22d0 commit c021c17

File tree

14 files changed

+88
-74
lines changed

14 files changed

+88
-74
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1313
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
1414
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1515
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
16+
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
1617
MD5 = "6ac74813-4b46-53a4-afec-0b5dc9d7885c"
1718
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1819
PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
@@ -33,8 +34,8 @@ JSON = "0.21"
3334
JSON2 = "0.3"
3435
MD5 = "0.2"
3536
PlotlyBase = "0.8.5, 0.8.6"
36-
julia = "1.3"
3737
YAML = "0.4.7"
38+
julia = "1.3"
3839

3940
[extras]
4041
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/Dash.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Dash
22
using DashBase
3-
import HTTP, JSON2, CodecZlib, MD5
3+
import HTTP, JSON2, JSON3, CodecZlib, MD5
44
using Sockets
55
using Pkg.Artifacts
66
const ROOT_PATH = realpath(joinpath(@__DIR__, ".."))
@@ -107,6 +107,7 @@ function __init__()
107107
end
108108

109109

110-
110+
JSON3.StructTypes.StructType(::Type{DashBase.Component}) = JSON3.StructTypes.Struct()
111+
JSON3.StructTypes.excludes(::Type{DashBase.Component}) = (:name, :available_props, :wildcard_regex)
111112

112113
end # module

src/app/supporttypes.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ struct Wildcard
22
type ::Symbol
33
end
44

5-
JSON2.write(io::IO, wild::Wildcard; kwargs...) = Base.write(io, "[\"", wild.type, "\"]")
5+
JSON3.StructTypes.StructType(::Type{Wildcard}) = JSON3.RawType()
6+
7+
JSON3.rawbytes(wild::Wildcard) = string("[\"", wild.type, "\"]")
68

79
const MATCH = Wildcard(:MATCH)
810
const ALL = Wildcard(:ALL)
@@ -30,6 +32,8 @@ const Input = Dependency{TraitInput}
3032
const State = Dependency{TraitState}
3133
const Output = Dependency{TraitOutput}
3234

35+
JSON3.StructTypes.StructType(::Type{<:Dependency}) = JSON3.StructTypes.Struct()
36+
3337
"""
3438
Base.==(a::Dependency, b::Dependency)
3539
@@ -97,6 +101,9 @@ struct ClientsideFunction
97101
namespace ::String
98102
function_name ::String
99103
end
104+
105+
JSON3.StructTypes.StructType(::Type{ClientsideFunction}) = JSON3.StructTypes.Struct()
106+
100107
struct Callback
101108
func ::Union{Function, ClientsideFunction}
102109
dependencies ::CallbackDeps

src/handler/callback_context.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ end
1919

2020
const _callback_context_storage = TaskContextStorage()
2121

22-
function with_callback_context(f, context::CallbackContext)
22+
function with_callback_context(f, context::CallbackContext)
2323
return with_context(f, _callback_context_storage, context)
24-
end
24+
end
2525

2626
"""
2727
callback_context()::CallbackContext
2828
2929
Get context of current callback, available only inside callback processing function
3030
"""
31-
function callback_context()
31+
function callback_context()
3232
!has_context(_callback_context_storage) && error("callback_context() is only available from a callback processing function")
3333
return get_context(_callback_context_storage)
3434
end
3535

36-
function inputs_list_to_dict(list::Vector{Any})
36+
function inputs_list_to_dict(list::AbstractVector)
3737
result = Dict{String, Any}()
3838
_item_to_dict!.(Ref(result), list)
3939
return result
4040
end
4141

42-
dep_id_string(id::NamedTuple) = sorted_json(id)
42+
dep_id_string(id::AbstractDict) = sorted_json(id)
4343
dep_id_string(id::AbstractString) = String(id)
4444
function _item_to_dict!(target::Dict{String, Any}, item)
4545
target["$(dep_id_string(item.id)).$(item.property)"] = get(item, :value, nothing)
4646
end
4747

48-
_item_to_dict!(target::Dict{String, Any}, item::Vector) = _item_to_dict!.(Ref(target), item)
48+
_item_to_dict!(target::Dict{String, Any}, item::AbstractVector) = _item_to_dict!.(Ref(target), item)

src/handler/index_page.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function resource_url(app::DashApp, resource::AppRelativeResource)
1+
function resource_url(app::DashApp, resource::AppRelativeResource)
22
prefix = get_setting(app, :requests_pathname_prefix)
33
return string(prefix,
44
"_dash-component-suites/",
55
resource.namespace,
66
"/",
7-
build_fingerprint(resource.relative_path, resource.version, resource.ts)
7+
build_fingerprint(resource.relative_path, resource.version, resource.ts)
88
)
99
end
1010

@@ -19,7 +19,7 @@ function asset_path(app::DashApp, path::AbstractString)
1919
end
2020

2121
resource_url(app::DashApp, resource::AppExternalResource) = resource.url
22-
function resource_url(app::DashApp, resource::AppAssetResource)
22+
function resource_url(app::DashApp, resource::AppAssetResource)
2323
return string(
2424
asset_path(app, resource.path),
2525
"?m=", resource.ts
@@ -42,7 +42,7 @@ function metas_html(app::DashApp)
4242
get(tag, "http-equiv", "") == "X-UA-Compatible"
4343
end
4444
has_charset = any(tag -> haskey(tag, "charset"), meta_tags)
45-
45+
4646
result = String[]
4747
!has_ie_compat && push!(result, "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">")
4848
!has_charset && push!(result, "<meta charset=\"UTF-8\">")
@@ -52,7 +52,7 @@ function metas_html(app::DashApp)
5252

5353
end
5454

55-
function css_html(app::DashApp, resources::ApplicationResources)
55+
function css_html(app::DashApp, resources::ApplicationResources)
5656
join(
5757
make_css_tag.(Ref(app), resources.css), "\n "
5858
)
@@ -77,7 +77,7 @@ app_entry_html() = """
7777
</div>
7878
"""
7979

80-
function config_html(app::DashApp)
80+
function config_html(app::DashApp)
8181
config = Dict{Symbol, Any}(
8282
:url_base_pathname => get_setting(app, :url_base_pathname),
8383
:requests_pathname_prefix => get_setting(app, :requests_pathname_prefix),
@@ -93,17 +93,17 @@ function config_html(app::DashApp)
9393
max_retry = get_devsetting(app, :hot_reload_max_retry)
9494
)
9595
end
96-
return """<script id="_dash-config" type="application/json">$(JSON2.write(config))</script>"""
97-
end
96+
return """<script id="_dash-config" type="application/json">$(JSON3.write(config))</script>"""
97+
end
9898

9999

100100
renderer_html() = """<script id="_dash-renderer" type="application/javascript">var renderer = new DashRenderer();</script>"""
101101

102-
favicon_html(app::DashApp) = ""
102+
favicon_html(app::DashApp) = ""
103+
103104

105+
function index_page(app::DashApp, resources::ApplicationResources)
104106

105-
function index_page(app::DashApp, resources::ApplicationResources)
106-
107107
result = interpolate_string(app.index_string,
108108
metas = metas_html(app),
109109
title = app.title,
@@ -121,7 +121,7 @@ function index_page(app::DashApp, resources::ApplicationResources)
121121
"#_dash_config" => r"id=\"_dash-config\"",
122122
"dash-renderer" => r"src=\"[^\"]*dash[-_]renderer[^\"]*\"",
123123
"new DashRenderer" => r"id=\"_dash-renderer",
124-
]
124+
]
125125
)
126126
return result
127127
end

src/handler/processors/callback.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ function split_callback_id(callback_id::AbstractString)
99
end
1010

1111
input_to_arg(input) = get(input, :value, nothing)
12-
input_to_arg(input::Vector) = input_to_arg.(input)
12+
input_to_arg(input::AbstractVector) = input_to_arg.(input)
1313

1414
make_args(inputs, state) = vcat(input_to_arg(inputs), input_to_arg(state))
1515

1616
res_to_vector(res) = res
1717
res_to_vector(res::Vector) = res
1818

19-
function _push_to_res!(res, value, out::Vector)
19+
function _push_to_res!(res, value, out::AbstractVector)
2020
_push_to_res!.(Ref(res), value, out)
2121
end
2222
function _push_to_res!(res, value, out)
@@ -44,20 +44,21 @@ function process_callback_call(app, callback_id, outputs, inputs, state)
4444

4545
_push_to_res!(response, res_vector, outputs)
4646

47+
4748
if length(response) == 0
4849
throw(PreventUpdate())
4950
end
5051
return Dict(:response=>response, :multi=>true)
5152
end
5253

53-
outputs_to_vector(out::Vector) = out
54+
outputs_to_vector(out::AbstractVector) = out
5455
outputs_to_vector(out) = [out]
5556

5657
function process_callback(request::HTTP.Request, state::HandlerState)
5758
app = state.app
5859
response = HTTP.Response(200, ["Content-Type" => "application/json"])
5960

60-
params = JSON2.read(String(request.body))
61+
params = JSON3.read(String(request.body))
6162
inputs = get(params, :inputs, [])
6263
state = get(params, :state, [])
6364
output = Symbol(params[:output])
@@ -69,7 +70,7 @@ function process_callback(request::HTTP.Request, state::HandlerState)
6970
cb_result = with_callback_context(context) do
7071
process_callback_call(app, output, outputs_list, inputs, state)
7172
end
72-
response.body = Vector{UInt8}(JSON2.write(cb_result))
73+
response.body = Vector{UInt8}(JSON3.write(cb_result))
7374
catch e
7475
if isa(e,PreventUpdate)
7576
return HTTP.Response(204)

src/handler/processors/layout.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ function process_layout(request::HTTP.Request, state::HandlerState)
44
return HTTP.Response(
55
200,
66
["Content-Type" => "application/json"],
7-
body = JSON2.write(layout_data(state.app.layout))
7+
body = JSON3.write(layout_data(state.app.layout))
88
)
99
end

src/handler/processors/reload_hash.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ function process_reload_hash(request::HTTP.Request, state::HandlerState)
44
hard = state.reload.hard,
55
packages = keys(state.cache.resources.files),
66
files = state.reload.changed_assets
7-
)
7+
)
88
state.reload.hard = false
99
state.reload.changed_assets = []
10-
return HTTP.Response(200, ["Content-Type" => "application/json"], body = JSON2.write(reload_tuple))
10+
return HTTP.Response(200, ["Content-Type" => "application/json"], body = JSON3.write(reload_tuple))
1111

1212
end

src/handler/state.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function _dependencies_json(app::DashApp)
3131
prevent_initial_call = callback.prevent_initial_call
3232
)
3333
end
34-
return JSON2.write(result)
34+
return JSON3.write(result)
3535
end
3636

3737
function _cache_tuple(app::DashApp, registry::ResourcesRegistry)

src/utils/misc.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function format_tag(name ::String, attributes::Dict{String, String}, inner::Stri
1010
tag *= "/>"
1111
elseif opened
1212
tag *= ">"
13-
else
13+
else
1414
tag *= ">$inner</$name>"
1515
end
1616
end
@@ -32,7 +32,7 @@ function validate_index(name::AbstractString, index::AbstractString, checks::Vec
3232
string(
3333
"Missing item", (length(missings)>1 ? "s" : ""), " ",
3434
join(getindex.(missings, 1), ", "),
35-
" in ", name
35+
" in ", name
3636
)
3737
)
3838
end
@@ -43,26 +43,26 @@ macro var_str(s)
4343
end
4444

4545
function parse_props(s)
46-
function make_prop(part)
46+
function make_prop(part)
4747
m = match(r"^(?<id>[A-Za-z]+[\w\-\:\.]*)\.(?<prop>[A-Za-z]+[\w\-\:\.]*)$", strip(part))
4848
if isnothing(m)
4949
error("expected <id>.<property>[,<id>.<property>...] in $(part)")
5050
end
51-
51+
5252
return (Symbol(m[:id]), Symbol(m[:prop]))
53-
end
53+
end
5454

5555
props_parts = split(s, ",", keepempty = false)
56-
56+
5757
return map(props_parts) do part
5858
return make_prop(part)
59-
end
59+
end
6060
end
6161

6262
function generate_hash()
63-
return strip(string(UUIDs.uuid4()), '-')
63+
return strip(string(UUIDs.uuid4()), '-')
6464
end
6565

66-
sort_by_keys(data::NamedTuple) = (;sort!(collect(pairs(data)), by = (x)->x[1])...,)
66+
sort_by_keys(data) = (;sort!(collect(pairs(data)), by = (x)->x[1])...,)
6767

68-
sorted_json(data::NamedTuple) = JSON2.write(sort_by_keys(data))
68+
sorted_json(data) = JSON3.write(sort_by_keys(data))

0 commit comments

Comments
 (0)