Comparing version 18.1.0 to 18.2.0
# CHANGELOG | ||
## 18.2.0 | ||
Fixed refs when switched instances during one render. | ||
Custom events in WebComponent wrapper making it complete. | ||
## 18.1.0 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "bobril", | ||
"version": "18.1.0", | ||
"version": "18.2.0", | ||
"description": "Component Oriented MVC Framework with virtual DOM and CSS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,6 +19,10 @@ import { | ||
interface WebComponentCtx<TData extends IWebComponentData> extends IBobrilCtx<TData> { | ||
evMap?: Map<string, EventListenerObject>; | ||
} | ||
export function wrapWebComponent<TData extends IWebComponentData>( | ||
name: string, | ||
props: string[] = [], | ||
_events?: { [name: string]: string } | ||
events?: { [name: string]: string } | ||
): (data?: TData) => IBobrilNode { | ||
@@ -46,2 +50,38 @@ props = ["id", ...props]; | ||
} as IBobrilComponent<TData, IBobrilCtx<TData>>; | ||
if (events != undefined) { | ||
const eventProps = Object.keys(events); | ||
component.init = (ctx: WebComponentCtx<TData>) => { | ||
ctx.evMap = undefined; | ||
}; | ||
component.postInitDom = component.postUpdateDom = (ctx: WebComponentCtx<TData>) => { | ||
let d = ctx.data; | ||
for (const n of eventProps) { | ||
let e = (d as any)[n]; | ||
if (e == undefined) continue; | ||
let es = ctx.evMap; | ||
if (es == undefined) { | ||
es = new Map(); | ||
ctx.evMap = es; | ||
} | ||
let en = events[n] as string; | ||
if (!es.has(en)) { | ||
let el = { | ||
handleEvent(event: Event) { | ||
e(event); | ||
}, | ||
}; | ||
(ctx.me.element as HTMLElement).addEventListener(en, el); | ||
es.set(en, el); | ||
} | ||
} | ||
}; | ||
component.destroy = (ctx: WebComponentCtx<TData>) => { | ||
let es = ctx.evMap; | ||
if (es != undefined) { | ||
es.forEach(function (this: HTMLElement, value: EventListenerObject, key: string) { | ||
this.removeEventListener(key, value); | ||
}, ctx.me.element as HTMLElement); | ||
} | ||
}; | ||
} | ||
@@ -48,0 +88,0 @@ return (data?: TData): IBobrilNode => ({ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
388091
9248