diff --git a/src/Core/IUI.js b/src/Core/IUI.js index 1791a58..5904d09 100644 --- a/src/Core/IUI.js +++ b/src/Core/IUI.js @@ -3,6 +3,7 @@ import { Binding, BindingType } from "./Binding.js"; //import Route from '../Router/Route.js'; import BindingList from "./BindingList.js"; +const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor; export class IUI { @@ -228,7 +229,7 @@ export class IUI { bindings.addEvent(attr.name.substr(1), handler); } - else if (attr.name.startsWith(":::")) + else if (attr.name.startsWith("event:")) { // make events let code = attr.value; @@ -238,9 +239,20 @@ export class IUI { func.call(element, event, ...scopeValues); } - bindings.addEvent(attr.name.substr(3), handler); + bindings.addEvent(attr.name.substr(6), handler); } + else if (attr.name.startsWith("async-event:")) { + // make events + let code = attr.value; + //let code = `try {\r\n context.value = ${script}; \r\n}\r\n catch(ex) { context.error = ex; }` + let func = new AsyncFunction("event", ...scopeArgs, code); + let handler = (event) => { + func.call(element, event, ...scopeValues); + } + + bindings.addEvent(attr.name.substr(12), handler); + } else { let b = Binding.create(attr, bindings.scope); diff --git a/src/Data/Repeat.js b/src/Data/Repeat.js index dd25442..723aaa9 100644 --- a/src/Data/Repeat.js +++ b/src/Data/Repeat.js @@ -144,12 +144,17 @@ export default IUI.module(class Repeat extends IUIElement this.list.push(el); - await IUI.create(el); + try { + await IUI.create(el); + + IUI.bind(el, false, "repeat", + IUI.extend(this.__i_bindings?.scope, + {index: i, repeat: this}, true)); + + } catch (ex) { + console.log(ex); + } - IUI.bind(el, false, "repeat", - IUI.extend(this.__i_bindings?.scope, - {index: i, repeat: this}, true)); - this._container.insertBefore(el, this._beforeNode); // update referencing