Skip to content
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

Support multi-model pages #299

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Support multi-model pages #299

wants to merge 13 commits into from

Conversation

hhaensel
Copy link
Member

@hhaensel hhaensel commented Nov 11, 2024

This PR fixes at least part of what was requested in #171.
It goes together with a respective PR in Genie.

We now support multiple models on a single page, even models of the same type.
Each model has its own websocket connection, with its own keepalive timer and ws_disonnected field.
The reconnection loop issue has also been fixed.

MWE:

using Stipple, Stipple.ReactiveTools
using StippleUI

@app MyApp1 begin
    @in i = 0
    
    @onchange i begin
        @notify("i has changed $i")
    end
end handlers1

@app MyApp2 begin
    @in j = 0

    @onchange j begin
        @notify("j has changed $j")
    end
end handlers2

@app MyApp3 begin
    @in k = 0

    @onchange k begin
        @notify("k has changed $k")
    end
end handlers3

ui(field = :i) = () -> row(card([
    cardsection(h6("Websocket disconnected"), @if(:ws_disconnected))
    cardsection(numberfield(String(field), field))
    cardsection(textfield("$field text", field))
]))

route("/") do
    global model1 = init(MyApp1, channel = Stipple.channelfactory()) |> handlers1
    global model2 = init(MyApp2, channel = Stipple.channelfactory()) |> handlers2
    global model3 = init(MyApp3, channel = Stipple.channelfactory()) |> handlers3
    page([model1, model2, model3], [ui(:i), ui(:j), ui(:k)], pagetemplate = (x...) -> row([x...]), "v-cloak") |> html
end

route("/multi") do
    global models = [init(MyApp1, channel = Stipple.channelfactory()) |> handlers1 for _ in 1:5]    
    page(models, fill(ui(), length(models)), pagetemplate = (x...) -> row([x...]), "v-cloak") |> html
end

up(open_browser = true)
image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant