Add s:route attribute to real time render components
This commit is contained in:
parent
d00b62caf1
commit
07353d0084
6 changed files with 84 additions and 66 deletions
120
data/bindata.go
120
data/bindata.go
File diff suppressed because one or more lines are too long
|
|
@ -34,14 +34,23 @@ func (page *Page) BindEvent(ctx *BuildContext, sel *goquery.Selection, cn string
|
|||
// This is temporarily used in the JIT mode. It will be refectored in the future.
|
||||
func (parser *TemplateParser) BindEvent(sel *goquery.Selection, ns string, cn string) {
|
||||
|
||||
hasEvent := false
|
||||
sel.FindMatcher(eventMatcher).Each(func(i int, s *goquery.Selection) {
|
||||
if _, has := s.Attr("s:event-cn"); has {
|
||||
return
|
||||
}
|
||||
id := fmt.Sprintf("%s-%d-%d", ns, parser.sequence, i+1)
|
||||
s.SetAttr("s:event", id)
|
||||
ReplaceEventData(s)
|
||||
s.SetAttr("s:event-cn", cn)
|
||||
parser.sequence++
|
||||
hasEvent = true
|
||||
})
|
||||
|
||||
if !hasEvent {
|
||||
return
|
||||
}
|
||||
|
||||
// Bind page event
|
||||
compSel := sel.Children().First()
|
||||
id := fmt.Sprintf("%s-%d", ns, parser.sequence)
|
||||
|
|
|
|||
|
|
@ -141,6 +141,9 @@ func (parser *TemplateParser) newJitComponentSel(sel *goquery.Selection, comp *J
|
|||
compSel.SetAttr(fmt.Sprintf("prop:%s", key), val)
|
||||
}
|
||||
|
||||
// Mark as jit component
|
||||
compSel.SetAttr("s:route", comp.route)
|
||||
|
||||
// Replace the slots
|
||||
slots := sel.Find("slot")
|
||||
if slots.Length() > 0 {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ var allowUsePropAttrs = map[string]bool{
|
|||
"s:render": true,
|
||||
"s:public": true,
|
||||
"s:assets": true,
|
||||
"s:route": true,
|
||||
}
|
||||
|
||||
var keepAttrs = map[string]bool{
|
||||
|
|
@ -89,6 +90,7 @@ var keepAttrs = map[string]bool{
|
|||
"s:render": true,
|
||||
"s:public": true,
|
||||
"s:assets": true,
|
||||
"s:route": true,
|
||||
}
|
||||
|
||||
// NewTemplateParser create a new template parser
|
||||
|
|
|
|||
|
|
@ -348,7 +348,14 @@ async function __sui_render(
|
|||
_data = { ..._data, ...__sui_data };
|
||||
}
|
||||
|
||||
const route = window.location.pathname;
|
||||
// get s:route attribute
|
||||
const elm = comp.root.closest("[s\\:route]");
|
||||
const routeAttr = elm ? elm.getAttribute("s:route") : false;
|
||||
const root = document.body.getAttribute("s:public") || "";
|
||||
const route = routeAttr ? `${root}${routeAttr}` : window.location.pathname;
|
||||
|
||||
console.log("Route", route, elm, root);
|
||||
|
||||
const url = `/api/__yao/sui/v1/render${route}`;
|
||||
const payload = { name, data: { ..._data, ...data }, option };
|
||||
const headers = {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,8 @@ func (tmpl *Template) Build(option *core.BuildOption) ([]string, error) {
|
|||
for _, route := range jitComponents {
|
||||
page, has := tmpl.loaded[route]
|
||||
if !has {
|
||||
err = multierror.Append(fmt.Errorf("The page %s is not loaded", route))
|
||||
// err = multierror.Append(fmt.Errorf("The page %s is not loaded", route))
|
||||
log.Warn("The page %s is not loaded", route)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -120,10 +121,6 @@ func (tmpl *Template) Build(option *core.BuildOption) ([]string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return warnings, err
|
||||
}
|
||||
|
||||
// Add sui lib to the global
|
||||
err = tmpl.UpdateJSSDK(option)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue