-
Notifications
You must be signed in to change notification settings - Fork 2
Using JSServe.jsrender #3
Description
Awesome package :) Looking forward to see it being used & registered.
One thing that should be changed though is this:
landing2 = App() do session::Session
CssMakieLayout.CurrentSession = session
...
endThis is pretty hacky, since Session isn't something that's easily globally shared.
Also, it's somewhat unnecessary for any user to set it, if you properly overload JSServe.jsrender(s::Session, my_object).
I haven't looked into this in detail, but I'd propose something like this:
All the functions like zstack should define a small custom struct, like this:
struct ZStack
items::Vector{Any}
attributes::Dict{Symbol, Any}
end
# properly add attributes like: activeidx::Observable=nothing class="", anim=[:default], style="", md=false
zstack(items...; kw...) = ZStack(Any[items...], Dict{Symbol, Any}(kw))
function JSServe.jsrender(session::Session, zstack::ZStack)
.....
# add on(activeidx) event
onjs(session, activeidx, js"""function on_update(new_value) {
const activefig_stack = $(item_div)
for(i = 1; i <= $(height); ++i) {
const element = activefig_stack.querySelector(":nth-child(" + i +")")
element.classList.remove("CssMakieLayout_active");
if(i == new_value) {
element.classList.add("CssMakieLayout_active");
}
}
}
""")
end
return item_div
endAnything else will be pretty hacky, but this should pretty nicely integrate with JSServe, so one can return any CssMakieLayout struct in an App.
Also, I'd put formatstyle into a css file and insert it in all jsrender calls as an asset: DOM.div(Asset("path/to/formatstyle.css")).
JSServe will make sure, that it will get included only one time, so don't worry about putting it in every jsrender.