Refactor component event injection to handle missing event selectors
This commit is contained in:
parent
a91e47b072
commit
dc3c637c5e
2 changed files with 11 additions and 9 deletions
|
|
@ -684,7 +684,7 @@ func (page *Page) BuildScripts(ctx *BuildContext, option *BuildOption, component
|
|||
|
||||
arguments := "document.body"
|
||||
if !ispage {
|
||||
arguments = "arguments[0]"
|
||||
arguments = "component"
|
||||
}
|
||||
injectScript := componentInitScript(arguments)
|
||||
|
||||
|
|
@ -754,7 +754,7 @@ func (page *Page) BuildScripts(ctx *BuildContext, option *BuildOption, component
|
|||
parent := "body"
|
||||
if !ispage {
|
||||
parent = "head"
|
||||
code = fmt.Sprintf("function %s(){\n%s\n}\n", component, addTabToEachLine(code))
|
||||
code = fmt.Sprintf("function %s( component ){\n%s\n}\n", component, addTabToEachLine(code))
|
||||
}
|
||||
|
||||
scripts = append(scripts, ScriptNode{
|
||||
|
|
|
|||
|
|
@ -216,12 +216,14 @@ const pageEventScriptTmpl = `
|
|||
`
|
||||
|
||||
const compEventScriptTmpl = `
|
||||
document.querySelector("[s\\:event=%s]").addEventListener("%s", function (event) {
|
||||
const dataKeys = %s;
|
||||
const jsonKeys = %s;
|
||||
handler = new %s(this).%s;
|
||||
__sui_event_handler(event, dataKeys, jsonKeys, this, handler);
|
||||
});
|
||||
if (document.querySelector("[s\\:event=%s]")) {
|
||||
document.querySelector("[s\\:event=%s]").addEventListener("%s", function (event) {
|
||||
const dataKeys = %s;
|
||||
const jsonKeys = %s;
|
||||
handler = new %s(this).%s;
|
||||
__sui_event_handler(event, dataKeys, jsonKeys, this, handler);
|
||||
});
|
||||
}
|
||||
`
|
||||
|
||||
const componentInitScriptTmpl = `
|
||||
|
|
@ -262,7 +264,7 @@ func pageEventInjectScript(eventID, eventName, dataKeys, jsonKeys, handler strin
|
|||
}
|
||||
|
||||
func compEventInjectScript(eventID, eventName, component, dataKeys, jsonKeys, handler string) string {
|
||||
return fmt.Sprintf(compEventScriptTmpl, eventID, eventName, dataKeys, jsonKeys, component, handler)
|
||||
return fmt.Sprintf(compEventScriptTmpl, eventID, eventID, eventName, dataKeys, jsonKeys, component, handler)
|
||||
}
|
||||
|
||||
func componentInitScript(root string) string {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue