Skip to content

Commit

Permalink
Merge pull request #280 from GenieFramework/hh-julia_to_vue
Browse files Browse the repository at this point in the history
remove julia_to_vue, make OptDict an OrderedDict
  • Loading branch information
hhaensel authored May 3, 2024
2 parents a9151d9 + 925e20a commit dff999a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
27 changes: 9 additions & 18 deletions src/Stipple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export JSONParser, JSONText, json, @json, jsfunction, @jsfunction_str
const config = Genie.config
const channel_js_name = "window.CHANNEL"

const OptDict = Dict{Symbol, Any}
const OptDict = OrderedDict{Symbol, Any}
opts(;kwargs...) = OptDict(kwargs...)

const IF_ITS_THAT_LONG_IT_CANT_BE_A_FILENAME = 500
Expand Down Expand Up @@ -734,7 +734,7 @@ 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)
webtransport().broadcast(channel, json(Dict("key" => vals[1], "value" => Stipple.render(vals[2], vals[1]))); except, restrict)
catch ex
@debug ex
false
Expand All @@ -746,7 +746,7 @@ function Base.push!(app::M, vals::Pair{Symbol,Reactive{T}};
except::Union{Nothing,UInt,Vector{UInt}} = nothing,
restrict::Union{Nothing,UInt,Vector{UInt}} = nothing)::Bool where {T,M<:ReactiveModel}
v = vals[2].r_mode != JSFUNCTION ? vals[2][] : replace_jsfunction(vals[2][])
push!(app, Symbol(julia_to_vue(vals[1])) => v; channel, except, restrict)
push!(app, vals[1] => v; channel, except, restrict)
end

function Base.push!(app::M;
Expand Down Expand Up @@ -1091,17 +1091,12 @@ function attributes(kwargs::Union{Vector{<:Pair}, Base.Iterators.Pairs, Dict},
end

k_str == "inner" && (v = join(v))
v_isa_jsexpr = v isa Symbol || !isa(v, Union{AbstractString, Bool, Number})
attr_key = string((v_isa_jsexpr && ! startswith(k_str, ":") &&
! (endswith(k_str, "!") || startswith(k_str, "v-") || startswith(k_str, "v" * Genie.config.html_parser_char_dash)) ? ":" : ""), k_str) |> Symbol
attr_val = if isa(v, Symbol) && ! startswith(k_str, ":")
Stipple.julia_to_vue(v)
elseif v isa Symbol || ! v_isa_jsexpr
v
else
js_attr(v)
end
attrs[attr_key] = attr_val

v_isa_jsexpr = !isa(v, Union{Symbol, AbstractString, Bool, Number})
attr_key = isa(v, Symbol) && !startswith(k_str, ":") && !endswith(k_str, "!") &&
!startswith(k_str, "v-") && !startswith(k_str, "v" * Genie.config.html_parser_char_dash) ? Symbol(":", k) : Symbol(k)

attrs[attr_key] = v_isa_jsexpr ? js_attr(v) : v
end

NamedTuple(attrs)
Expand All @@ -1113,10 +1108,6 @@ include("Pages.jl")

#===#

# function _deepcopy(r::R{T}) where T
# v_copy = deepcopy(r.o.val)
# :(R{$T}($v_copy, $(r.r_mode), $(r.no_backend_watcher), $(r.no_frontend_watcher), $(r.__source__)))
# end
_deepcopy(r::R{T}) where T = R(deepcopy(r.o.val), r.r_mode, r.no_backend_watcher, r.no_frontend_watcher)

_deepcopy(x) = deepcopy(x)
Expand Down
4 changes: 2 additions & 2 deletions src/stipple/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ jsrender(r::Reactive, args...) = jsrender(getfield(getfield(r,:o), :val), args..
Renders the Julia `ReactiveModel` `app` as the corresponding Vue.js JavaScript code.
"""
function Stipple.render(app::M)::Dict{Symbol,Any} where {M<:ReactiveModel}
result = Dict{String,Any}()
result = OptDict()

for field in fieldnames(typeof(app))
f = getfield(app, field)

occursin(SETTINGS.private_pattern, String(field)) && continue
f isa Reactive && f.r_mode == PRIVATE && continue

result[julia_to_vue(field)] = Stipple.jsrender(f, field)
result[field] = Stipple.jsrender(f, field)
end

vue = Dict( :el => JSONText("rootSelector"),
Expand Down

0 comments on commit dff999a

Please sign in to comment.