mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] Code prettification
This commit is contained in:
committed by
Aaron Bohy
parent
4cceb239dd
commit
80cb6b7a91
@@ -1,4 +1,4 @@
|
||||
export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[], data: any[]} {
|
||||
export function filterOutModifiersFromData(dataList: any[]): { modifiers: string[]; data: any[] } {
|
||||
dataList = dataList.slice();
|
||||
const modifiers = [];
|
||||
let elm;
|
||||
|
||||
@@ -76,6 +76,8 @@ function setupSyntheticEvent(evName: string, eventKey: string, capture: boolean
|
||||
if (CONFIGURED_SYNTHETIC_EVENTS[eventKey]) {
|
||||
return;
|
||||
}
|
||||
document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), { capture });
|
||||
document.addEventListener(evName, (event) => nativeToSyntheticEvent(eventKey, event), {
|
||||
capture,
|
||||
});
|
||||
CONFIGURED_SYNTHETIC_EVENTS[eventKey] = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { filterOutModifiersFromData } from "../blockdom/config";
|
||||
|
||||
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget|null) => {
|
||||
export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarget | null) => {
|
||||
const { data: _data, modifiers } = filterOutModifiersFromData(data);
|
||||
data = _data;
|
||||
let stopped = false;
|
||||
@@ -9,9 +9,20 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg
|
||||
const isSelf = ev.target === currentTarget;
|
||||
for (const mod of modifiers) {
|
||||
switch (mod) {
|
||||
case "self": selfMode = true; if (isSelf) { continue; } else { return stopped; };
|
||||
case "prevent": if ((selfMode && isSelf) || (!selfMode)) ev.preventDefault(); continue;
|
||||
case "stop": if ((selfMode && isSelf) || (!selfMode)) ev.stopPropagation() ; stopped = true; continue;
|
||||
case "self":
|
||||
selfMode = true;
|
||||
if (isSelf) {
|
||||
continue;
|
||||
} else {
|
||||
return stopped;
|
||||
}
|
||||
case "prevent":
|
||||
if ((selfMode && isSelf) || !selfMode) ev.preventDefault();
|
||||
continue;
|
||||
case "stop":
|
||||
if ((selfMode && isSelf) || !selfMode) ev.stopPropagation();
|
||||
stopped = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,4 +34,4 @@ export const mainEventHandler = (data: any, ev: Event, currentTarget?: EventTarg
|
||||
data[0].__owl__.component[method](...args, ev);
|
||||
}
|
||||
return stopped;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -474,7 +474,10 @@ export class QWebCompiler {
|
||||
args = _args.slice(1, -1);
|
||||
return "";
|
||||
});
|
||||
const modifiers = rawEvent.split(".").slice(1).map(m => `"${m}"`);
|
||||
const modifiers = rawEvent
|
||||
.split(".")
|
||||
.slice(1)
|
||||
.map((m) => `"${m}"`);
|
||||
let modifiersCode = "";
|
||||
if (modifiers.length) {
|
||||
modifiersCode = `${modifiers.join(",")}, `;
|
||||
|
||||
Reference in New Issue
Block a user