Skip to content

Commit

Permalink
replace all variables in @onchange macro
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 16, 2024
1 parent 8be4d17 commit 5ca805a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,22 +1055,14 @@ macro onchange(location, vars, expr)
on_vars = fieldnames_to_fields(vars, known_vars)

expr, used_vars = mask(expr, known_vars)
do_vars = Symbol[]

for a in vars.args
push!(do_vars, a isa Symbol && ! in(a, used_vars) ? a : :_)
end

replace_reactive_vars = setdiff(known_reactive_vars, do_vars)
replace_non_reactive_vars = setdiff(known_non_reactive_vars, do_vars)

expr = fieldnames_to_fields(expr, known_non_reactive_vars, replace_non_reactive_vars)
expr = fieldnames_to_fieldcontent(expr, known_reactive_vars, replace_reactive_vars)
expr = unmask(expr, vcat(replace_reactive_vars, replace_non_reactive_vars))
expr = fieldnames_to_fields(expr, known_non_reactive_vars)
expr = fieldnames_to_fieldcontent(expr, known_reactive_vars)
expr = unmask(expr, vcat(known_reactive_vars, known_non_reactive_vars))

fn = length(vars.args) == 1 ? :on : :onany
ex = quote
$fn($(on_vars.args...)) do $(do_vars...)
$fn($(on_vars.args...)) do _...
$(expr.args...)
end
end
Expand Down

0 comments on commit 5ca805a

Please sign in to comment.