-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@app is scope leaky #223
Comments
If I'm right, this is due to historic devolopment of the ReactiveTools API. Having said all this, constructions like the one above @app begin
DATA = sort!(DataFrame(rand(10, 2), ["x1", "x2"]))
@out df = DATA
<...>
end are currently not handled correctly. There are two ways to achieve that sort of behaviour:
route("/") do
model = @init
DATA = sort!(DataFrame(rand(10, 2), ["x1", "x2"]))
model.df[!] = DATA # The `[!]` is only needed if you have a handler attached to `df`, otherwise `model.df` is sufficient
page(model, ui) |> html
@onchange isready notify(df) # to transfer the updated value of the model to the front-end after the setup
end
@app begin
@out df = DataFrame()
<...>
@onchange isready begin
DATA = sort!(DataFrame(rand(10, 2), ["x1", "x2"]))
df = DATA # here it is ok to trigger a handler, because everything is already setup, so no `[!]` is necessary
end
end |
We can at least use references to already declared variables with a little trick. |
When we have something like this:
df
is scoped inside the ReactiveModel and is not accessible at module scopeDATA
leaks into the module scope -- which is surprising and not good for performanceI hoped it would be straightforward and wrapped the
@app
macro output into alet ... 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 thelet
block:Well, other things needing patching before getting to this point so it looks like scoping is a bit messy.
The text was updated successfully, but these errors were encountered: