-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support kwargs in @page
macro
#222
Conversation
Still thinking how we could support passing of more arguments to the init function ... |
…ge()`, `@page` and `@init` to `initfn()`
Now we can do: @init(debounce = 10) In order to change the settings after they have been already set, it is important to clear the cached route and DEPS. For this I introduced @clear_cache
@init(debounce = 12) |
Before we think about merging, I'm going to support semicolon parameter syntax |
Well, it's done. Needed to find out that macros only catch parameter syntax consistently when there is no positional argument in the definition. macro f(x, expressions...)
@show x expressions
return nothing
end
@f(a, b="b"; c=c)
# x = :($(Expr(:parameters, :($(Expr(:kw, :c, :c))))))
# expressions = (:a, :(b = "b")) |
Interesting, I've never attempted this. With functions the keyword args are collected in the named tuple. julia> f(args...; kwargs...) = print(args, kwargs)
f (generic function with 1 method)
julia> f(2, a=:a; b=3)
(2,)Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:a, :b), Tuple{Symbol, Int64}}}(:a => :a, :b => 3) Because it's passed before the |
Yeah, the functions do aggregate args and kwargs, I've used that a thousand times. EDIT:
|
…on model storage
…models for generic modeltypes; minor fixes
One thought. Should we enforce strict ordering so that kw arguments? (if it can be done) Now you can do something like @page("/model2", model = Model, ui ) which works since the macro rearranges the parameters inside. This may suggest that order is not important, but if one were to try @page(ui, model = Model, "/model2" ) it wouldn't work. Other than this, I like the changes and it's very useful for when you want to use multiple models without specifying a layout. |
I think it is known from functions that the order of positional arguments is important while the oder of kwargs is not. |
Currently different methods of the
@page
macro are distinguishable only by the number of arguments, requiring the argument orderurl
,view
,layout
,model
,context
.With the new macro tool
expressions_to_args()
we can support a kwarg-like macro call, e.g.for global models without the requirement to specify a layout.
EDIT: Note that the
;
-Syntax with auto duplication for kwargs is not supported in macros