Skip to content

Commit

Permalink
protect :channel_
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 17, 2024
1 parent bfcabf7 commit 72e5f83
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ function get_known_vars(M::Module)
reactive_vars = Symbol[]
non_reactive_vars = Symbol[]
for (k, v) in REACTIVE_STORAGE[M]
k in [:channel__, :modes__] && continue
k in INTERNALFIELDS && continue
is_reactive = startswith(string(Stipple.split_expr(v)[2]), r"(Stipple\.)?R(eactive)?($|{)")
push!(is_reactive ? reactive_vars : non_reactive_vars, k)
end
Expand All @@ -848,7 +848,7 @@ function get_known_vars(::Type{M}) where M<:ReactiveModel
reactive_vars = Symbol[]
non_reactive_vars = Symbol[]
for (k, v) in zip(fieldnames(CM), fieldtypes(CM))
k in [:channel__, :modes__] && continue
k in INTERNALFIELDS && continue
push!(v <: Reactive ? reactive_vars : non_reactive_vars, k)
end
reactive_vars, non_reactive_vars
Expand Down
2 changes: 1 addition & 1 deletion src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ macro mixin_old(expr, prefix = "", postfix = "")
values = getfield.(Ref(mix), fnames)
output = quote end
for (f, type, v) in zip(Symbol.(pre, fnames, post), fieldtypes(get_concrete_type(T)), values)
f in Symbol.(prefix, [:channel__, :modes__, AUTOFIELDS...], postfix) && continue
f in Symbol.(prefix, vcat(INTERNALFIELDS, AUTOFIELDS), postfix) && continue
v_copy = Stipple._deepcopy(v)
push!(output.args, v isa Symbol ? :($f::$type = $(QuoteNode(v))) : :($f::$type = $v_copy))
end
Expand Down
2 changes: 1 addition & 1 deletion src/stipple/reactive_props.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
isprivate(field::Reactive) = field.r_mode == PRIVATE

function isprivate(fieldname::Symbol, model::M)::Bool where {M<:ReactiveModel}
fieldname in [Stipple.CHANNELFIELDNAME, :modes__] && return true
fieldname in INTERNALFIELDS && return true

field = getfield(model, fieldname)
field isa Reactive ? isprivate(field) : get(model.modes__, fieldname, 0) == PRIVATE
Expand Down
6 changes: 4 additions & 2 deletions src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function setchannel(m::M, value) where {M<:ReactiveModel}
end

const AUTOFIELDS = [:isready, :isprocessing, :fileuploads] # not DRY but we need a reference to the auto-set fields
const INTERNALFIELDS = [CHANNELFIELDNAME, :channel_, :modes__] # not DRY but we need a reference to the auto-set fields

@pour reactors begin
modes__::LittleDict{Symbol, Int} = LittleDict(:modes__ => PRIVATE, :channel__ => PRIVATE)
Expand Down Expand Up @@ -201,7 +202,7 @@ function model_to_storage(::Type{T}, prefix = "", postfix = "") where T# <: Reac
values = getfield.(Ref(M()), fields)
storage = LittleDict{Symbol, Expr}()
for (f, type, v) in zip(fields, fieldtypes(M), values)
f = f in [:channel__, :modes__, AUTOFIELDS...] ? f : Symbol(prefix, f, postfix)
f = f in vcat(INTERNALFIELDS, AUTOFIELDS) ? f : Symbol(prefix, f, postfix)
storage[f] = v isa Symbol ? :($f::$type = $(QuoteNode(v))) : :($f::$type = Stipple._deepcopy($v))
end
# fix channel field, which is not reconstructed properly by the code above
Expand Down Expand Up @@ -491,7 +492,8 @@ end

macro define_mixin(mixin_name, expr)
storage = @eval(__module__, Stipple.@var_storage($expr))
delete!.(Ref(storage), [:channel__, Stipple.AUTOFIELDS...])
# delete internal fields and autofields except :modes__
delete!.(Ref(storage), setdiff(vcat(INTERNALFIELDS, AUTOFIELDS), [:modes__]))

quote
Base.@kwdef struct $mixin_name
Expand Down

0 comments on commit 72e5f83

Please sign in to comment.