2
0
mirror of https://github.com/esiur/iui.git synced 2025-05-06 06:42:58 +00:00

Repeat+Event

This commit is contained in:
Ahmed Zamil 2023-06-07 14:21:17 +03:00
parent 90e9fb5c71
commit 95884c4f2d
2 changed files with 24 additions and 7 deletions

View File

@ -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);

View File

@ -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