GenieFramework / StippleUI.jl

StippleUI is a library of reactive UI elements for Stipple.jl.
MIT License
82 stars 15 forks source link

Example App Inverter crashes #132

Closed michaelfliegner closed 2 weeks ago

michaelfliegner commented 2 weeks ago

What is wrong here?

using Pkg
Pkg.add("Stipple")
Pkg.add("StippleUI")
using Stipple, StippleUI

@vars Inverter begin
  process = false
  input = ""
  output::String, READONLY
end

function handlers(model)
  on(model.input) do input
      model.output[] = input |> reverse
  end

  onbutton(model.process) do
      model.output[] = model.output[] |> reverse
  end

  model
end

function ui()
  row(cell(class = "st-module", [
    textfield(class = "q-my-md", "Input", :input, hint = "Please enter some words", @on("keyup.enter", "process = true"))

    btn(class = "q-my-md", "Action!", @click(:process), color = "primary")

    card(class = "q-my-md", [
      card_section(h2("Output"))
      card_section("Variant 1: {{ output }}")
      card_section(["Variant 2: ", span(class = "text-red", @text(:output))])
    ])
  ]))
end

route("/") do
  model = Inverter |> init |> handlers
  page(model, ui()) |> html
end

Genie.isrunning(:webserver) || up()

@michaelfliegner ➜ /workspaces/GenieBuiltLifeProto.jl (main) $ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.4 (2024-06-04)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> include("Sample.jl")
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.10/Project.toml`
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`
   Resolving package versions...
  No Changes to `~/.julia/environments/v1.10/Project.toml`
  No Changes to `~/.julia/environments/v1.10/Manifest.toml`
┌ Info: 
└ Web Server starting at http://127.0.0.1:8000 
[ Info: Listening on: 127.0.0.1:8000, thread id: 1
Genie.Server.ServersCollection(HTTP.Servers.Server{HTTP.Servers.Listener{Nothing, Sockets.TCPServer}}(HTTP.Servers.Listener{Nothing, Sockets.TCPServer}(Sockets.InetAddr{Sockets.IPv4}(ip"127.0.0.1", 8000), "127.0.0.1", "8000", nothing, Sockets.TCPServer(RawFD(24) active)), nothing, Set{HTTP.Connections.Connection}(), Task (runnable) @0x00007698e97047e0, ReentrantLock(nothing, 0x00000000, 0x00, Base.GenericCondition{Base.Threads.SpinLock}(Base.IntrusiveLinkedList{Task}(nothing, nothing), Base.Threads.SpinLock(0)), (130399572652448, 130399572652448, 130399572652448))), nothing)

julia> [ Info: GET / 200
[ Info: GET /stippleui.jl/v0.24.1/assets/css/quasar.prod.css 200
[ Info: GET /stipple.jl/v0.30.7/assets/css/stipplecore.css 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/underscore-min.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/vue_filters.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/watchers.js 200
[ Info: GET /genie.jl/v5.30.3/assets/js/channels.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/vue2compat.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/vue.global.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/stipplecore.js 200
[ Info: GET /stippleui.jl/v0.24.1/assets/js/quasar.umd.prod.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/keepalive.js 200
[ Info: GET /stipple.jl/v0.30.7/assets/js/inverter.js 200
┌ Error: 
│ Error attempting to invoke handler.
│ 
│   Handler:
│   # 1 method for anonymous function "#5":
│  [1] (::var"#5#7")(input)
│      @ /workspaces/GenieBuiltLifeProto.jl/Sample.jl:14
│   Core.CodeInfo[CodeInfo(
│ 1 ─ %1 = input |> Main.reverse
│ │   %2 = Core.getfield(#self#, :model)
│ │   %3 = Base.getproperty(%2, :output)
│ │        Base.setindex!(%3, %1)
│ └──      return %1
│ )]
│ 
│   Type of argument:
│   String
│ 
│   Value:
│   a
│ 
│   Exception:
│   ErrorException("type ##Inverter!#225 has no field output")
│ 
│   exception =
│    type ##Inverter!#225 has no field output
│    Stacktrace:
│      [1] getproperty
│        @ ./Base.jl:37 [inlined]
│      [2] (::var"#5#7"{var"##Inverter!#225"})(input::String)
│        @ Main /workspaces/GenieBuiltLifeProto.jl/Sample.jl:14
│      [3] #invokelatest#2
│        @ ./essentials.jl:892 [inlined]
│      [4] invokelatest
│        @ ./essentials.jl:889 [inlined]
│      [5] callwatchers(field::Reactive{String}, val::String, keys::Int64; notify::Stipple.var"#35#37")
│        @ Stipple ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:34
│      [6] callwatchers
│        @ ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:18 [inlined]
│      [7] #setindex_withoutwatchers!#34
│        @ ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:13 [inlined]
│      [8] setindex_withoutwatchers!(field::Reactive{String}, val::String, keys::Int64)
│        @ Stipple ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:10
│      [9] update!(model::var"##Inverter!#225", field::Symbol, newval::String, oldval::String)
│        @ Stipple ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:120
│     [10] (::Stipple.var"#54#57"{Module, String, var"##Inverter!#225", DataType})()
│        @ Stipple ~/.julia/packages/Stipple/gle3a/src/Stipple.jl:565
│     [11] match_channels(req::HTTP.Messages.Request, msg::String, ws_client::HTTP.WebSockets.WebSocket, params::Genie.Router.Params{Any})
│        @ Genie.Router ~/.julia/packages/Genie/uliWf/src/Router.jl:624
│     [12] route_ws_request(req::HTTP.Messages.Request, msg::String, ws_client::HTTP.WebSockets.WebSocket)
│        @ Genie.Router ~/.julia/packages/Genie/uliWf/src/Router.jl:225
│     [13] #handle_ws_request#31
│        @ ~/.julia/packages/Genie/uliWf/src/Server.jl:412 [inlined]
│     [14] (::Genie.Server.var"#29#30"{HTTP.WebSockets.WebSocket})()
│        @ Genie.Server ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/macros.jl:123
│     [15] #invokelatest#2
│        @ ./essentials.jl:892 [inlined]
│     [16] invokelatest
│        @ ./essentials.jl:889 [inlined]
│     [17] #153
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:425 [inlined]
│     [18] run_work_thunk(thunk::Distributed.var"#153#154"{Genie.Server.var"#29#30"{HTTP.WebSockets.WebSocket}, Tuple{}, @Kwargs{}}, print_error::Bool)
│        @ Distributed ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/process_messages.jl:70
│     [19] #remotecall_fetch#158
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:450 [inlined]
│     [20] remotecall_fetch
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:449 [inlined]
│     [21] remotecall_fetch
│        @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/Distributed/src/remotecall.jl:492 [inlined]
│     [22] setup_ws_handler(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}, ws_client::HTTP.WebSockets.WebSocket)
│        @ Genie.Server ~/.julia/packages/Genie/uliWf/src/Server.jl:379
│     [23] #7
│        @ ~/.julia/packages/Genie/uliWf/src/Server.jl:121 [inlined]
│     [24] upgrade(f::Genie.Server.var"#7#13"{HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}}, http::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}}; suppress_close_error::Bool, maxframesize::Int64, maxfragmentation::Int64, nagle::Bool, quickack::Bool, kw::@Kwargs{})
│        @ HTTP.WebSockets ~/.julia/packages/HTTP/sJD5V/src/WebSockets.jl:456
│     [25] upgrade
│        @ ~/.julia/packages/HTTP/sJD5V/src/WebSockets.jl:425 [inlined]
│     [26] (::Genie.Server.var"#6#12")(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
│        @ Genie.Server ~/.julia/packages/Genie/uliWf/src/Server.jl:120
│     [27] #invokelatest#2
│        @ ./essentials.jl:892 [inlined]
│     [28] invokelatest
│        @ ./essentials.jl:889 [inlined]
│     [29] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Nothing)
│        @ HTTP.Servers ~/.julia/packages/HTTP/sJD5V/src/Servers.jl:469
│     [30] (::HTTP.Servers.var"#16#17"{Genie.Server.var"#6#12", HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Nothing, ReentrantLock, Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})()
│        @ HTTP.Servers ~/.julia/packages/HTTP/sJD5V/src/Servers.jl:401
└ @ Stipple ~/.julia/packages/Stipple/gle3a/src/stipple/mutators.jl:54
`
hhaensel commented 2 weeks ago

There's a typo in line 9, should be

@vars Inverter begin
    process = false
    input = ""
    output::String = "", READONLY
end

Fixed the README, thanks for pointing to it!