When we have something like this:
@app begin
DATA = sort!(DataFrame(rand(10, 2), ["x1", "x2"]))
@out df = DATA
# more code here
df is scoped inside the ReactiveModel and is not accessible at module scope
- however,
DATA leaks into the module scope -- which is surprising and not good for performance
I hoped it would be straightforward and wrapped the @app macro output into a let ... end block but it turns out that handlers are in a different scope and stuff breaks as handlers can't access the vars in the scope introduced by the let block:
ERROR: UndefVarError: `DATA` not defined
Stacktrace:
[1] var"##Main_ReactiveModel!#292"()
@ Main ./util.jl:567
[2] #invokelatest#2
@ ./essentials.jl:819 [inlined]
[3] invokelatest
@ ./essentials.jl:816 [inlined]
[4] |>
@ ./operators.jl:907 [inlined]
[5] init(::Type{Main_ReactiveModel}; vue_app_name::String, endpoint::String, channel::Any, debounce::Int64, transport::Module, core_theme::Bool)
@ Stipple ~/.julia/dev/Stipple/src/Stipple.jl:430
[6] init
@ ~/.julia/dev/Stipple/src/Stipple.jl:419 [inlined]
[7] init_from_storage(::Type{Main_ReactiveModel}; channel::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Stipple.ModelStorage.Sessions ~/.julia/dev/Stipple/src/ModelStorage.jl:15
[8] init_from_storage(::Type{Main_ReactiveModel})
@ Stipple.ModelStorage.Sessions ~/.julia/dev/Stipple/src/ModelStorage.jl:11
[9] top-level scope
@ ~/.julia/dev/Stipple/src/ReactiveTools.jl:607
in expression starting at /Users/adrian/.julia/dev/StippleUI/demos/tables/app.jl:40
Well, other things needing patching before getting to this point so it looks like scoping is a bit messy.
When we have something like this:
dfis scoped inside the ReactiveModel and is not accessible at module scopeDATAleaks into the module scope -- which is surprising and not good for performanceI hoped it would be straightforward and wrapped the
@appmacro output into alet ... endblock but it turns out that handlers are in a different scope and stuff breaks as handlers can't access the vars in the scope introduced by theletblock:Well, other things needing patching before getting to this point so it looks like scoping is a bit messy.