Genie Discord forum

Is there a way to Observable.connect!
a variable from an @app
body to an Observable
?
Something like this:
using Observables, MyModule
@app begin
@in variable = 0
end
connect!(MyModule.some_observable, variable)

This is interesting, have you tried doing this inside a handler? Something like
@onchange isready begin connect!(observable, variable) end

Just to give some insight, we use Observable's on
to attach callbacks to a variable. The @app macro generates a handlers
function that attaches the callbacks.
julia> @macroexpand @app Model begin @out i = 10; @onchange i begin; print(i); end end
quote
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:585 =#
begin
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:659 =#
Stipple.ReactiveTools.delete_events(Model)
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:661 =#
function handlers(__model__)
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:661 =#
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:662 =#
#= REPL[57]:1 =#
begin
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:842 =#
on(__model__.i) do i
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:843 =#
#= REPL[57]:1 =#
print(i)
end
end
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:664 =#
__model__
end
#= /Users/pere/.julia/packages/Stipple/a9IBQ/src/ReactiveTools.jl:666 =#
(Model, handlers)
end
end
This handlers
function is called at a later stage when the page's model is instantiated

but would isready
be updated only once? Because the connect!
ion needs to happen only once..

yes, isready comes by default and changes to true when the page is finished loading. It'll be updated on page reload only

ok!!! awesome. trying it

nah, the observable variable
is stripped off inside the scope of @onchange
. So in my case it's no longer Observable{Bool}
it's just Bool
(e.g. false
). Then the connect!
fails because it connects two observables.

I see, that is right. I guess then we'd have to add the connect! call to the list of functions ( like on
) executed when instantiating the model with handlers
...I don't know how to do that yet, but I'm currently studying the Stipple source so I might be able to help soon

If this is something you need, please open an issue on the Stipple.jl repo with a MWE and we'll look into it