Stipple.jl: Using @in variable with same name as function's keyword argument yields "invalid keyword argument name"

If a keyword argument is used inside the @handlers, then an @in or @out variable with the same name cannot be defined.

Here’s a MWE

using GenieFramework
@genietools 

function test(;msg="hi")
    println(msg)
end

@handlers begin
    @in msg = ""
    @onchange msg begin
        test(;msg="")
    end
end

function ui()
    [textfield("Message", :msg)]
end

@page("/", ui)
Server.isrunning() || Server.up()

And the error I’m getting

julia> includet("mwe.jl")
ERROR: [ Info: 2023-01-11 16:05:53 Watching ["/Users/pere/genie/demos/GenieFrameworkDemos_NewAPI/Database/mwe"]
syntax: invalid keyword argument name "__model__.msg[]" around /Users/pere/genie/demos/GenieFrameworkDemos_NewAPI/Database/mwe/mwe.jl:11
Stacktrace:
 [1] top-level scope
   @ none:1
in expression starting at /Users/pere/genie/demos/GenieFrameworkDemos_NewAPI/Database/mwe/mwe.jl:8

If I change the variable’s name then it all works.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 21 (21 by maintainers)

Most upvoted comments

With #159 we now have

julia> @handlers begin
         @in i = 1
         @in j = 2
         @in k = 3
         @onchange i, j begin
           println("The value of i is: ", i)
           println("The value of k is: ", k)
         end
       end
__GF_AUTO_HANDLERS__ (generic function with 1 method)

julia> __HANDLERS__
1-element Vector{Expr}:
 :(onany(__model__.i, __model__.j) do i, j
      #= C:\Users\m136270\.julia\dev\Stipple\src\ReactiveTools.jl:442 =#
      begin
          #= REPL[55]:6 =#
          println("The value of i is: ", i)
          #= REPL[55]:7 =#
          println("The value of k is: ", __model__.k[])
      end
  end)

Note that it is no longer necessary to have @onchangeany

@hhaensel reading PR it’s mind blowing. What’s the use case for @clear? I am seeing we are pushing the handlers in HANDLERS as vector? @clear get rid of all the HANDLERS

@clear deletes REACTIVE_STORAGE and HANDLERS. The use case is interactive development of models at the REPL. We already have some ReactiveTools demos on StippleDemos.jl which are all working on the REPL. If you execute one after the other they might not work without calling @clear.

The new @model macro does clear the storage, so if we stick to that syntax in the future we won’t have problems.

This could be done, but I’m not sure how important this is for users. Furthermore, it’s not clear what should happen with the handler. If it is a specific handler with on() it’s clear, but if it’s a handler with mutliple input variables onany() we would need to see whether the variable is used and remove only the trigger from the list of observables. It would require a larger refactoring, I think. I could imagine a Dict rather than a vector, but what would we do with identical set of trigger variables…

Well to be specific the assumption was one model type per module, but I was talking of model instances