mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] bdom: support multiple synthetic events on one node
This commit is contained in:
+11
-5
@@ -47,14 +47,18 @@ function createElementHandler(evName: string, capture: boolean = false): EventHa
|
||||
|
||||
// Synthetic handler: a form of event delegation that allows placing only one
|
||||
// listener per event type.
|
||||
let nextSyntheticEventId = 1;
|
||||
function createSyntheticHandler(evName: string, capture: boolean = false): EventHandlerCreator {
|
||||
let eventKey = `__event__synthetic_${evName}`;
|
||||
if (capture) {
|
||||
eventKey = `${eventKey}_capture`;
|
||||
}
|
||||
setupSyntheticEvent(evName, eventKey, capture);
|
||||
const currentId = nextSyntheticEventId++;
|
||||
function setup(this: HTMLElement, data: any) {
|
||||
(this as any)[eventKey] = data;
|
||||
const _data = (this as any)[eventKey] || {};
|
||||
_data[currentId] = data;
|
||||
(this as any)[eventKey] = _data;
|
||||
}
|
||||
return { setup, update: setup };
|
||||
}
|
||||
@@ -62,10 +66,12 @@ function createSyntheticHandler(evName: string, capture: boolean = false): Event
|
||||
function nativeToSyntheticEvent(eventKey: string, event: Event) {
|
||||
let dom = event.target;
|
||||
while (dom !== null) {
|
||||
const data = (dom as any)[eventKey];
|
||||
if (data) {
|
||||
const stopped = config.mainEventHandler(data, event, dom);
|
||||
if (stopped) return;
|
||||
const _data = (dom as any)[eventKey];
|
||||
if (_data) {
|
||||
for (const data of Object.values(_data)) {
|
||||
const stopped = config.mainEventHandler(data, event, dom);
|
||||
if (stopped) return;
|
||||
}
|
||||
}
|
||||
dom = (dom as any).parentNode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user