Skip to content

Commit 1f9117b

Browse files
authored
Merge pull request #150 from plotly/dev
Release 1.1.1
2 parents 3fc358a + af22273 commit 1f9117b

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Dash"
22
uuid = "1b08a953-4be3-4667-9a23-3db579824955"
33
authors = ["Chris Parmer <[email protected]>", "Alexandr Romanenko <[email protected]>"]
4-
version = "1.1.0"
4+
version = "1.1.1"
55

66
[deps]
77
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/handler/make_handler.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function start_reload_poll(state::HandlerState)
1414
for pkg in values(state.registry.components)
1515
push!(folders, pkg.path)
1616
end
17-
state.reload.task = @async poll_folders(folders; interval = get_devsetting(state.app, :hot_reload_watch_interval)) do file, ts, deleted
17+
initial_watched = init_watched(folders)
18+
state.reload.task = @async poll_folders(folders, initial_watched; interval = get_devsetting(state.app, :hot_reload_watch_interval)) do file, ts, deleted
1819
state.reload.hard = true
1920
state.reload.hash = generate_hash()
2021
assets_path = get_assets_path(state.app)

src/handler/state.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ struct ChangedAsset
33
modified ::Int
44
is_css ::Bool
55
end
6+
JSON3.StructTypes.StructType(::Type{ChangedAsset}) = JSON3.StructTypes.Struct()
7+
68
mutable struct StateReload
79
hash::Union{String, Nothing}
810
hard::Bool

src/utils/poll.jl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function poll_until_changed(files::Set{String}; interval = 1.)
1212
active = true
1313
while active
1414
for w in watched
15-
if !isfile(w.filename)
15+
if !isfile(w.filename)
1616
active = false
1717
break;
1818
end
@@ -25,17 +25,32 @@ function poll_until_changed(files::Set{String}; interval = 1.)
2525
end
2626
end
2727

28-
function poll_folders(on_change, folders; interval = 1.)
28+
function init_watched(folders)
2929
watched = Dict{String, Float64}()
30+
for folder in folders
31+
!isdir(folder) && continue
32+
for (base, _, files) in walkdir(folder)
33+
for f in files
34+
path = joinpath(base, f)
35+
new_time = mtime(path)
36+
watched[path] = new_time
37+
end
38+
end
39+
end
40+
return watched
41+
end
42+
43+
function poll_folders(on_change, folders, initial_watched; interval = 1.)
44+
watched = initial_watched
3045
while true
3146
walked = Set{String}()
3247
for folder in folders
3348
!isdir(folder) && continue
3449
for (base, _, files) in walkdir(folder)
3550
for f in files
36-
path = joinpath(base, f)
51+
path = joinpath(base, f)
3752
new_time = mtime(path)
38-
if new_time > get(watched, path, -1.)
53+
if new_time > get(watched, path, -1.)
3954
on_change(path, new_time, false)
4055
end
4156
watched[path] = new_time

test/config_functional.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ end
7272
app = dash()
7373
@test app.config.routes_pathname_prefix == "/"
7474
@test app.config.requests_pathname_prefix == "/test-app/"
75+
delete!(ENV, "DASH_APP_NAME")
7576

7677
end
7778

test/reload_hash.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Test
2+
using Dash
3+
using Dash: HandlerState, main_registry, start_reload_poll, enable_dev_tools!
4+
import HTTP
5+
import JSON3
6+
@testset "reload state" begin
7+
rm("assets/test2.png", force = true)
8+
app = dash()
9+
enable_dev_tools!(app, dev_tools_hot_reload_watch_interval = 1.)
10+
app.layout = html_div()
11+
state = HandlerState(app, main_registry())
12+
start_reload_poll(state)
13+
initial_hash = state.reload.hash
14+
sleep(1)
15+
@test length(state.reload.changed_assets) == 0
16+
write("assets/test2.png", "")
17+
sleep(2)
18+
@test state.reload.hash != initial_hash
19+
@test length(state.reload.changed_assets) == 1
20+
@test length(state.reload.changed_assets) == 1
21+
@test state.reload.changed_assets[1].url == "/assets/test2.png"
22+
rm("assets/test2.png", force = true)
23+
24+
end
25+
@testset "reload handler" begin
26+
rm("assets/test2.css", force = true)
27+
app = dash()
28+
enable_dev_tools!(app, dev_tools_hot_reload = true, dev_tools_hot_reload_watch_interval = 1.)
29+
app.layout = html_div()
30+
handler = make_handler(app)
31+
write("assets/test2.css", "")
32+
sleep(2)
33+
response = HTTP.handle(handler, HTTP.Request("GET", "/_reload-hash"))
34+
data = JSON3.read(response.body)
35+
@test length(data.files) == 1
36+
@test data.files[1].url == "/assets/test2.css"
37+
@test data.files[1].is_css == true
38+
rm("assets/test2.css", force = true)
39+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ include("misc.jl")
1111
include("callbacks.jl")
1212
include("components_utils.jl")
1313
include("table_format.jl")
14+
include("reload_hash.jl")
1415
#include("dev.jl")

0 commit comments

Comments
 (0)