Skip to content

Commit

Permalink
Support for file uploads, various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
essenciary committed Jan 5, 2024
1 parent 624af6e commit 758c4f4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Stipple"
uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998"
authors = ["Adrian <e@essenciary.com>"]
version = "0.27.26"
version = "0.27.27"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand All @@ -27,7 +27,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
DataFrames = "1"
Dates = "1.6"
FilePathsBase = "0.9"
Genie = "5.23.6"
Genie = "5.23.7"
GenieSession = "1"
GenieSessionFileSession = "1"
JSON = "0.20, 0.21"
Expand Down
1 change: 1 addition & 0 deletions assets/js/watchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const reviveMixin = {
const eventMixin = {
methods: {
handle_event: function (event_data, event_handler, mode) {
if (event_data === undefined) { event_data = {} }
console.debug('event: ' + JSON.stringify(event_data) + ":" + event_handler)
if (mode=='addclient') { event_data._addclient = true}
Genie.WebChannels.sendMessageTo(window.CHANNEL, 'events', {
Expand Down
1 change: 1 addition & 0 deletions src/Elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function vue_integration(::Type{M};
}
function app_ready() {
$vue_app_name.channel_ = window.CHANNEL;
$vue_app_name.isready = true;
Genie.Revivers.addReviver(window.$(vue_app_name).revive_jsfunction);
$(transport == Genie.WebChannels &&
Expand Down
14 changes: 11 additions & 3 deletions src/ModelStorage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ import GenieSessionFileSession

export init_from_storage

function model_id(::Type{M}) where M
Symbol(Stipple.routename(M))
end

function store(model::M) where M
GenieSession.set!(model_id(M), model)
nothing
end

function init_from_storage( t::Type{M};
channel::Union{Any,Nothing} = Stipple.channeldefault(t),
kwargs...) where M
model_id = Symbol(Stipple.routename(M))
model = Stipple.init(M; channel, kwargs...)
stored_model = GenieSession.get(model_id, nothing)
stored_model = GenieSession.get(model_id(M), nothing)

CM = Stipple.get_concrete_type(M)
for f in fieldnames(CM)
Expand All @@ -28,7 +36,7 @@ function init_from_storage( t::Type{M};
# register reactive handlers to automatically save model on session when model changes
if f [Stipple.AUTOFIELDS...]
on(field) do _
GenieSession.set!(model_id, model)
GenieSession.set!(model_id(M), model)
end
end
else
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function delete_events(::Type{M}) where M
end
end
nothing
end
end

function delete_handlers!(m::Module)
delete!(HANDLERS, m)
Expand Down Expand Up @@ -421,7 +421,7 @@ Declares a reactive variable that is public and can be written to from the UI.
end
```
"""
macro var"in" end
macro in end

"""
```julia
Expand Down
24 changes: 21 additions & 3 deletions src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,16 @@ function deletemode!(modes, fieldnames::Symbol...)
end

function init_storage()
ch = channelfactory()

LittleDict{Symbol, Expr}(
CHANNELFIELDNAME =>
:($(Stipple.CHANNELFIELDNAME)::$(Stipple.ChannelName) = Stipple.channelfactory()),
:modes__ => :(modes__::Stipple.LittleDict{Symbol, Int} = Stipple.LittleDict{Symbol, Int}()),
:($(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)
: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 @@ -457,6 +461,9 @@ function init(t::Type{M};
setchannel(model, channel)
end

# make sure we store the channel name in the model
Stipple.ModelStorage.Sessions.store(model)

# add a timer that checks if the model is outdated and if so prepare the model to be garbage collected
LAST_ACTIVITY[Symbol(getchannel(model))] = now()

Expand Down Expand Up @@ -667,6 +674,17 @@ function Base.push!(app::M, vals::Pair{Symbol,T};
channel::String = getchannel(app),
except::Union{Nothing,UInt,Vector{UInt}} = nothing,
restrict::Union{Nothing,UInt,Vector{UInt}} = nothing)::Bool where {T,M<:ReactiveModel}
try
_push!(vals, channel; except, restrict)
catch ex
@debug ex
false
end
end

function _push!(vals::Pair{Symbol,T}, channel::String;
except::Union{Nothing,UInt,Vector{UInt}} = nothing,
restrict::Union{Nothing,UInt,Vector{UInt}} = nothing)::Bool where {T}
try
webtransport().broadcast(channel, json(Dict("key" => julia_to_vue(vals[1]), "value" => Stipple.render(vals[2], vals[1]))); except, restrict)
catch ex
Expand Down
4 changes: 3 additions & 1 deletion src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ function setchannel(m::M, value) where {M<:ReactiveModel}
setfield!(m, CHANNELFIELDNAME, ChannelName(value))
end

const AUTOFIELDS = [:isready, :isprocessing] # not DRY but we need a reference to the auto-set fields
const AUTOFIELDS = [:isready, :isprocessing, :fileuploads] # 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()
isready::Stipple.R{Bool} = false
isprocessing::Stipple.R{Bool} = false
channel_::String = "" # not sure what this does if it's empty
fileuploads::Stipple.R{Dict{AbstractString,AbstractString}} = Dict{AbstractString,AbstractString}()
end

@mix Stipple.@with_kw mutable struct old_reactive
Expand Down

2 comments on commit 758c4f4

@essenciary
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/98332

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.27 -m "<description of version>" 758c4f4829daba45936144aab301c90081fbc0ce
git push origin v0.27.27

Please sign in to comment.