-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathstate.jl
More file actions
68 lines (58 loc) · 2.25 KB
/
state.jl
File metadata and controls
68 lines (58 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
struct ChangedAsset
url ::String
modified ::Int
is_css ::Bool
end
JSON3.StructTypes.StructType(::Type{ChangedAsset}) = JSON3.StructTypes.Struct()
mutable struct StateReload
hash::Union{String, Nothing}
hard::Bool
changed_assets::Vector{ChangedAsset}
task ::Union{Nothing, Task}
StateReload(hash) = new(hash, false, ChangedAsset[], nothing)
end
mutable struct StateCache
resources::ApplicationResources
index_string ::String
dependencies_json ::String
need_recache ::Bool
StateCache(app, registry) = new(_cache_tuple(app, registry)..., false)
end
abstract type BackgroundCallBackManager end
mutable struct DiskcacheManager <: BackgroundCallBackManager
end
_dep_clientside_func(func::ClientsideFunction) = func
_dep_clientside_func(func) = nothing
function _dependencies_json(app::DashApp)
result = map(values(app.callbacks)) do callback
(
inputs = dependency_tuple.(callback.dependencies.input),
state = dependency_tuple.(callback.dependencies.state),
output = output_string(callback.dependencies),
clientside_function = _dep_clientside_func(callback.func),
prevent_initial_call = callback.prevent_initial_call,
long = callback.long !== false && (interval = callback.long[:interval],)
)
end
return JSON3.write(result)
end
function _cache_tuple(app::DashApp, registry::ResourcesRegistry)
app_resources = ApplicationResources(app, registry)
index_string::String = index_page(app, app_resources)
dependencies_json = _dependencies_json(app)
return (app_resources, index_string, dependencies_json)
end
struct HandlerState
app::DashApp
registry::ResourcesRegistry
cache::StateCache
reload::StateReload
HandlerState(app, registry = main_registry()) = new(app, registry, StateCache(app, registry), make_reload_state(app))
end
make_reload_state(app::DashApp) = get_devsetting(app, :hot_reload) ? StateReload(generate_hash()) : StateReload(nothing)
get_cache(state::HandlerState) = state.cache
function rebuild_cache!(state::HandlerState)
cache = get_cache(state)
(cache.resources, cache.index_string, cache.dependencies_json) = _cache_tuple(state.app, state.registry)
cache.need_recache = false
end