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

Using Observables inside Oxygen.jl app and/or HypertextLiteral.jl #107

Open
Dale-Black opened this issue Apr 29, 2023 · 1 comment
Open

Comments

@Dale-Black
Copy link

I created a super simple app with Oxygen that has various routes. In this, I created an HTML page using HypertextLiteral.jl (HTL) and a counter using HTL and the <script> tag inside the @htl macro.

I now want to recreate this simple functionality using Observables.jl (and maybe WebIO or whatever) inside this Oxygen app. Is there a simple way to go about this? Here is the app.jl file and if someone could direct me on how to make a route like /counter but using Observables, that would be a helpful starting place!

using Oxygen
using HTTP
using HypertextLiteral

@get "/greet" function (req::HTTP.Request)
    return "hello world!"
end

@get "/multiply/{a}/{b}" function (req, a::Float64, b::Float64)
    return a * b
end

@get "/getdata" function ()
    return Dict("message" => "hello2!")
end

@get "/htl" function ()
    string(@htl """
        <h1>Hello test</h1>
        <p>This is a simple frontend using HypertextLiteral.jl.</p>
    """)
end

@get "/counter" function ()
    string(@htl """
        <h1>Counter</h1>
        <button onclick="incrementCounter()">Increment</button>
        <p>Counter: <span id="counter">0</span></p>
        <script>
            let counter = 0;
            function incrementCounter() {
                counter += 1;
                document.getElementById("counter").innerText = counter;
            }
        </script>
    """)
end

serve()
@Dale-Black
Copy link
Author

Also, HypertextLiteral.jl doesn't work with Observables as far as I know. But if it were possible to do something like

@get "/obs/counter" function ()
    counter = Observable(0)
    return string(@htl """
        <label>$(counter)</label>
        <button onclick=$(counter += 1)>Click me</button>
    """)
end

This would be incredible!

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

No branches or pull requests

1 participant