diff --git a/src/Pages.jl b/src/Pages.jl index 7a4c9ff5..ddfe7785 100644 --- a/src/Pages.jl +++ b/src/Pages.jl @@ -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, @@ -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 diff --git a/src/ReactiveTools.jl b/src/ReactiveTools.jl index e3ee0615..b15581f4 100644 --- a/src/ReactiveTools.jl +++ b/src/ReactiveTools.jl @@ -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 @@ -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 @@ -997,7 +997,7 @@ macro page(expressions...) :model => () -> @eval(__module__, @init()) ) ) -@show args + :(Stipple.Pages.Page($(args...), $url, view = $view)) |> esc end @@ -1257,4 +1257,10 @@ macro notify(args...) end |> esc end +macro modelstorage() + quote + using Stipple.ModelStorage.Sessions + end |> esc +end + end diff --git a/src/Tools.jl b/src/Tools.jl index 6310cac5..3f720def 100644 --- a/src/Tools.jl +++ b/src/Tools.jl @@ -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