Refactor utils.ts for improved code readability and maintainability
This commit is contained in:
parent
eb4443ebe7
commit
259b707ca8
4 changed files with 95 additions and 70 deletions
122
data/bindata.go
122
data/bindata.go
File diff suppressed because one or more lines are too long
|
|
@ -34,9 +34,16 @@ func Render(process *process.Process) interface{} {
|
||||||
return fmt.Sprintf("<div class='text-danger'> %s </div>", err.Error())
|
return fmt.Sprintf("<div class='text-danger'> %s </div>", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
c, _, err := r.MakeCache()
|
var c *core.Cache = nil
|
||||||
if err != nil {
|
if !r.Request.DisableCache() {
|
||||||
return fmt.Sprintf("<div class='text-danger'> %s </div>", err.Error())
|
c = core.GetCache(r.File)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == nil {
|
||||||
|
c, _, err = r.MakeCache()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Sprintf("<div class='text-danger'> %s </div>", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c == nil {
|
if c == nil {
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,8 @@ function $$(selector) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __sui_component_root(elm, name) {
|
function __sui_component_root(elm: Element, name: string) {
|
||||||
while (elm && elm.getAttribute("s:cn") !== name) {
|
return elm.closest(`[s\\:cn=${name}]`);
|
||||||
elm = elm.parentElement;
|
|
||||||
}
|
|
||||||
return elm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __sui_state(component) {
|
function __sui_state(component) {
|
||||||
|
|
@ -258,7 +255,7 @@ async function __sui_render(
|
||||||
|
|
||||||
// Prepare loader
|
// Prepare loader
|
||||||
let loader = `<span class="sui-render-loading">Loading...</span>`;
|
let loader = `<span class="sui-render-loading">Loading...</span>`;
|
||||||
if (option.showLoader) {
|
if (option.showLoader && option.replace) {
|
||||||
if (typeof option.showLoader === "string") {
|
if (typeof option.showLoader === "string") {
|
||||||
loader = option.showLoader;
|
loader = option.showLoader;
|
||||||
} else if (option.showLoader instanceof HTMLElement) {
|
} else if (option.showLoader instanceof HTMLElement) {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,27 @@ class __Query {
|
||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
elm(): Element | null {
|
||||||
|
return this.element;
|
||||||
|
}
|
||||||
|
|
||||||
|
elms(): NodeListOf<Element> | null {
|
||||||
|
return this.elements;
|
||||||
|
}
|
||||||
|
|
||||||
|
$$() {
|
||||||
|
if (!this.element) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const root = this.element.closest("[s\\:cn]");
|
||||||
|
if (!root) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
return $$(root);
|
||||||
|
}
|
||||||
|
|
||||||
each(callback: (element: __Query, index: number) => void) {
|
each(callback: (element: __Query, index: number) => void) {
|
||||||
if (!this.elements) {
|
if (!this.elements) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue