Genie Discord forum

Author Avatarmi-ti
12/30/2023, 8:56:43 PM

Hi friends here, the more I use genie, the more I love it!!! Now I put many of my code into web. Thank you! Genie guys. And since I have many small tools in genie, I would like to ask if there any easy way to put them all together into a toolkit?

let me make it more clear, I build many apps for myself's usage, and they are smililar in the code structure, but have different reactive variable and output page, for example: this is app1

# app1
@app begin
    @in xxx = 1
    @in yyy = 2
    @out result = 0
    @onchange xxx,yyy begin
        result = xxx + yyy
    end
end
@page("/app1_page", "app1.html")

and this is app2

# app2
@in V = Int64[]
@out result = Int64[]
@onchange V begin
    result = V.^2
end

@page("/app2_page", "app2.html")

what I want to do is to merge them together, I can do it by just pool all code into one file, such as app.jl, it works but it is messy, so I try to split the code into different files and include them in when needed, so when I visit "localhost/app1", it will go to app1, and load app1's reactive variable and html file, below is want I try, but it does not work:

app1.jl:

    @in xxx = 1
    @in yyy = 2
    @out result = 0
    @onchange xxx,yyy begin
        result = xxx + yyy
    end

toolkit.jl:

global appList = ["app1","app2"]
global current_app = "app1"
@app begin
    include("$(current_app).jl") 
end

for app in appList
    route("/$(app)") do
        global currentapp = app
        Genie.Renderer.redirect("/$(app)_page", 302)
    end
    @page("/$(app)_page", "$(app).html" )
end

any suggetion on this? Thank you very much !!!!

Author Avatarbienpierre
1/2/2024, 7:14:29 PM

Hello, in Multiple app modules paragraph : https://learn.genieframework.com/docs/guides/adding-reactive-pages it is divided with module and sub-module, perhaps it will help you. regards

Author Avatarmi-ti
1/2/2024, 10:27:34 PM

Thanks @bienpierre so much!!! it helps a lots.

Author Avatarhhaensel
1/3/2024, 1:08:23 AM

You can also create named apps in a single module:

@app App1 begin
    @in xxx = 1
    @in yyy = 2
    @out result = 0
    @onchange xxx,yyy begin
        result = xxx + yyy
    end
end

@app App1 begin
    @in V = Int64[]
    @out result = Int64[]
    @onchange V begin
        result = V.^2
    end
end

@page("/app1_page", "app1.html", model = App1)
@page("/app2_page", "app2.html", model = App2)
Author Avatarhhaensel
1/3/2024, 1:11:28 AM

Or you can merge such apps into one:

@app MyGeneralApp begin
    @mixin App1
    @mixin App2
end

Currently, only the fields are merged, but the handlers are not! There is a PR in place that would even allow to merge the mixins: https://github.com/GenieFramework/Stipple.jl/pull/245

@mixins [App1, App2]
Author Avatarhhaensel
1/3/2024, 1:13:35 AM

But that's work in progress. In the long run the handlers should be merged automatically.

Author Avatarhhaensel
1/3/2024, 1:35:28 AM

@essenciary shall we allow alternative keyword app instead of model?

Author Avataressenciary
1/3/2024, 9:58:26 AM

won't that be confusing given that we also have @app?

Author Avatarhhaensel
1/3/2024, 10:40:56 AM

It would read

@page("/app1_page", "app1.html", app = App1)
@page("/app2_page", "app2.html", app = App2)
Author Avatarhhaensel
1/3/2024, 10:43:22 AM

That looks quite natural as @app creates an App, which then can be passed by kw

Author Avataressenciary
1/5/2024, 1:23:58 PM

@hhaensel In general I don't like having multiple names for one thing... it complicates user understanding, it complicates dev understanding, it adds code and makes code slower

Author Avataressenciary
1/5/2024, 1:24:24 PM

I've seen the code for this in your branch - quite a few more computations for no gain really

Author Avataressenciary
1/5/2024, 1:26:49 PM

in principle I'm ok with replacing all references to the idea of model with that of app - but adding a chunk of code just to support a different keyword doesn't justify the cons IMO

Author Avataressenciary
1/5/2024, 1:28:30 PM

it's a matter of principle: 5 years of this and the code becomes a slow codebase of redundant options

Author Avatarhhaensel
1/5/2024, 1:30:28 PM

Let's discuss the wording model vs. app in a call. My idea would be, app is the type, model is the instance

Author Avataressenciary
1/5/2024, 1:31:13 PM

ok - let's discuss in detail (my current thinking is that with the new API the model has disappeared... the user only sees @app)

Author Avatarhhaensel
1/5/2024, 1:35:21 PM

I still don't like the invisible model type too much. My personal favourite would be to have named models as the basis and, if really needed, grab the model from a Dict{Module, ReactiveModel}

Author Avatarhhaensel
1/5/2024, 1:35:40 PM

But that's also something g for a call

Author Avataressenciary
1/5/2024, 1:36:31 PM

ok - yes, we should discuss a cleanup - we can probably remove a lot of legacy code and some layers

Author Avataressenciary
1/5/2024, 1:36:43 PM

my main concern is the lack of scope in @app blocks