-
Notifications
You must be signed in to change notification settings - Fork 1
/
parseparams.go
35 lines (33 loc) · 919 Bytes
/
parseparams.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package jaws
import "html/template"
// ParseParams parses the parameters passed to UI() when creating a new Element,
// returning UI tags, event handlers and HTML attributes.
func ParseParams(params []any) (tags []any, handlers []EventHandler, attrs []string) {
for i := range params {
switch data := params[i].(type) {
case template.HTMLAttr:
attrs = append(attrs, string(data))
case []template.HTMLAttr:
for _, s := range data {
attrs = append(attrs, string(s))
}
case string:
attrs = append(attrs, data)
case []string:
attrs = append(attrs, data...)
case EventFn:
if data != nil {
handlers = append(handlers, eventFnWrapper{data})
}
default:
if h, ok := data.(ClickHandler); ok {
handlers = append(handlers, clickHandlerWapper{h})
}
if h, ok := data.(EventHandler); ok {
handlers = append(handlers, h)
}
tags = append(tags, data)
}
}
return
}