Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Jan 18, 2024
2 parents aaf114c + 5a999ed commit 8500549
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ macro init(args...)
end

instance = let model = initfn($(init_args...))
new_handlers ? Base.invokelatest(handlersfn, model) : handlersfn(model)
new_handlers ? Base.invokelatest(handlersfn, model) : handlersfn(model)
end
for p in Stipple.Pages._pages
p.context == $__module__ && (p.model = instance)
Expand Down 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 Stipple.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 Stipple.INTERNALFIELDS && continue
push!(v <: Reactive ? reactive_vars : non_reactive_vars, k)
end
reactive_vars, non_reactive_vars
Expand Down
13 changes: 3 additions & 10 deletions src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,10 @@ function init_storage()
ch = channelfactory()

LittleDict{Symbol, Expr}(
CHANNELFIELDNAME =>
:($(Stipple.CHANNELFIELDNAME)::$(Stipple.ChannelName) = $ch),
CHANNELFIELDNAME => :($(Stipple.CHANNELFIELDNAME)::$(Stipple.ChannelName) = $ch),
:modes__ => :(modes__::Stipple.LittleDict{Symbol,Int} = Stipple.LittleDict{Symbol,Int}()),
:isready => :(isready::Stipple.R{Bool} = false),
:isprocessing => :(isprocessing::Stipple.R{Bool} = false),
:channel_ => :(channel_::String = $ch),
:fileuploads => :(fileuploads::Stipple.R{Dict{AbstractString,AbstractString}} = Dict{AbstractString,AbstractString}())
)
end
Expand Down Expand Up @@ -455,13 +453,8 @@ function init(t::Type{M};
transport == Genie.WebChannels || (Genie.config.websockets_server = false)
ok_response = "OK"

channel = if channel !== nothing
setchannel(model, channel)
elseif hasproperty(model, CHANNELFIELDNAME)
getchannel(model)
else
setchannel(model, channel)
end
channel === nothing && (channel = channelfactory())
setchannel(model, channel)

# make sure we store the channel name in the model
Stipple.ModelStorage.Sessions.store(model)
Expand Down
3 changes: 2 additions & 1 deletion src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ 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, :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)
channel__::Stipple.ChannelName = Stipple.channelfactory()
modes__::LittleDict{Symbol, Int} = LittleDict(:modes__ => PRIVATE, :channel__ => PRIVATE)
isready::Stipple.R{Bool} = false
isprocessing::Stipple.R{Bool} = false
channel_::String = "" # not sure what this does if it's empty
Expand Down
50 changes: 28 additions & 22 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ using Test

version = Genie.Assets.package_version(Stipple)

function string_get(x)
String(HTTP.get(x, retries = 0, status_exception = false).body)
function string_get(x; kwargs...)
String(HTTP.get(x, retries = 0, status_exception = false; kwargs...).body)
end

function get_channel(s::String)
Expand Down Expand Up @@ -42,9 +42,9 @@ end

# channels have to be different
@test model.channel__ != model2.channel__

# check whether fields are correctly defined
@test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i, :s)
@test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i, :s)

# check reactivity
model.i[] = 20
Expand All @@ -69,7 +69,7 @@ end
end

model = TestApp |> init |> handlers
@test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i, :s, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)
@test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i, :s, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)
end

using Stipple.ReactiveTools
Expand All @@ -84,14 +84,14 @@ using Stipple.ReactiveTools
end
end

model = TestApp2 |> init |> handlers
model2 = TestApp2 |> init |> handlers
model = @init TestApp2
model2 = @init TestApp2

# channels have to be different
@test model.channel__ != model2.channel__

# check whether fields are correctly defined
@test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i, :s)
@test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i, :s)

# check reactivity
model.i[] = 20
Expand All @@ -113,7 +113,7 @@ end
end

@eval model = TestApp |> init |> handlers
@test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i, :s, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)
@test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i, :s, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)

# check reactivity
@eval model.i[] = 20
Expand All @@ -132,12 +132,12 @@ end

@eval model = @init
@eval model2 = @init

# channels have to be different
@eval @test model.channel__ != model2.channel__

# check whether fields are correctly defined
@eval @test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i2, :s2)
@eval @test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i2, :s2)

# check reactivity
@eval model.i2[] = 20
Expand All @@ -159,7 +159,7 @@ end
end

@eval model = @init
@eval @test propertynames(model) == (:channel__, :modes__, :isready, :isprocessing, :i3, :s3, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)
@eval @test propertynames(model) == tuple(Stipple.INTERNALFIELDS..., Stipple.AUTOFIELDS..., :i3, :s3, :j, :t, :mixin_j, :mixin_t, :pre_j_post, :pre_t_post)

@eval model.i3[] = 20
@test model.s3[] == "20"
Expand Down Expand Up @@ -243,12 +243,15 @@ end

s1 = string_get("http://localhost:$port/")
s2 = string_get("http://localhost:$port/")

s3 = string_get("http://localhost:$port/static")
s3 = string_get("http://localhost:$port/", cookies = false)

s4 = string_get("http://localhost:$port/static")
s5 = string_get("http://localhost:$port/static")
s6 = string_get("http://localhost:$port/static", cookies = false)

@test get_channel(s2) != get_channel(s1)
@test get_channel(s3) == get_channel(s4)
@test get_channel(s2) == get_channel(s1)
@test get_channel(s3) != get_channel(s1)
@test get_channel(s4) == get_channel(s5) == get_channel(s6)

@clear_cache
down()
Expand Down Expand Up @@ -300,13 +303,16 @@ end

s1 = string_get("http://localhost:$port/")
s2 = string_get("http://localhost:$port/")
s3 = string_get("http://localhost:$port/", cookies = false)

s4 = string_get("http://localhost:$port/static")
s5 = string_get("http://localhost:$port/static")
s6 = string_get("http://localhost:$port/static", cookies = false)

s3 = string_get("http://localhost:$port/static1")
s4 = string_get("http://localhost:$port/static1")

@test get_channel(s2) != get_channel(s1)
@test get_channel(s3) == get_channel(s4)

@test get_channel(s2) == get_channel(s1)
@test get_channel(s3) != get_channel(s1)
@test get_channel(s4) == get_channel(s5) == get_channel(s6)

@clear_cache MyApp
down()
end
Expand Down

2 comments on commit 8500549

@hhaensel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/99096

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.27.32 -m "<description of version>" 8500549bc90cb5f2344f751329437e88938a63ab
git push origin v0.27.32

Please sign in to comment.