Skip to content

Commit

Permalink
support generic modeltypes in @page, add @modelstorage to switch …
Browse files Browse the repository at this point in the history
…on model storage
  • Loading branch information
hhaensel committed Sep 9, 2023
1 parent d1f993c commit 143db04
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/Pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pages() = _pages

function Page( route::Union{Route,String};
view::Union{Genie.Renderers.FilePath,<:AbstractString,ParsedHTMLString,Vector{<:AbstractString},Function},
model::Union{M,Function,Nothing,Expr,Module} = Stipple.init(EmptyModel),
model::Union{M,Function,Nothing,Expr,Module,Type{M}} = Stipple.init(EmptyModel),
layout::Union{Genie.Renderers.FilePath,<:AbstractString,ParsedHTMLString,Nothing,Function} = nothing,
context::Module = @__MODULE__,
debounce::Int = Stipple.JS_DEBOUNCE_TIME,
Expand All @@ -42,7 +42,9 @@ function Page( route::Union{Route,String};
Core.eval(context, model)
elseif isa(model, Module)
context = model
@eval(context, @init(debounce = debounce, transport = transport, core_theme = core_theme))
@eval(context, Stipple.ReactiveTools.@init(debounce = $debounce, transport = $transport, core_theme = $core_theme))
elseif model isa DataType
@eval(context, Stipple.ReactiveTools.@init($model; debounce = $debounce, transport = $transport, core_theme = $core_theme))
else
model
end
Expand Down
12 changes: 9 additions & 3 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export @onchange, @onbutton, @event, @notify
export @clear, @clear_vars, @clear_handlers

# app handling
export @page, @init, @handlers, @app, @appname
export @page, @init, @handlers, @app, @appname, @modelstorage

# js functions on the front-end (see Vue.js docs)
export @methods, @watch, @computed, @client_data, @add_client_data
Expand Down Expand Up @@ -591,7 +591,7 @@ macro init(args...)
else
identity
end

instance = let model = initfn($(init_args...))
new_handlers ? Base.invokelatest(handlersfn, model) : handlersfn(model)
end
Expand Down Expand Up @@ -997,7 +997,7 @@ macro page(expressions...)
:model => () -> @eval(__module__, @init())
)
)
@show args

:(Stipple.Pages.Page($(args...), $url, view = $view)) |> esc
end

Expand Down Expand Up @@ -1257,4 +1257,10 @@ macro notify(args...)
end |> esc
end

macro modelstorage()
quote
using Stipple.ModelStorage.Sessions
end |> esc
end

end
2 changes: 1 addition & 1 deletion src/Tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function expressions_to_args(@nospecialize(expressions); args_to_kwargs::Vector{
if ex isa Expr && ex.head == :(=)
ex.head = :kw
push!(keys, ex.args[1])
elseif ex.head != :parameters
elseif !isa(ex, Expr) || ex.head != :parameters
push!(inds, i)
end
end
Expand Down

0 comments on commit 143db04

Please sign in to comment.