mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +08:00
feature(react): add react directory to make the react-framework-delegate a first-class citizen and to make it easier to keep APIs in sync
This commit is contained in:
24
packages/react/src/utils/wc-shim.ts
Normal file
24
packages/react/src/utils/wc-shim.ts
Normal file
@ -0,0 +1,24 @@
|
||||
export function wc(events = {}, obj = {}) {
|
||||
let storedEl: HTMLElement;
|
||||
|
||||
return function (el: HTMLElement) {
|
||||
|
||||
(Object as any).entries(events).forEach((keyValues: string[]) => {
|
||||
const name = keyValues[0];
|
||||
const value = keyValues[1];
|
||||
const action = (el) ? el.addEventListener : storedEl.removeEventListener;
|
||||
if (typeof value === 'function') {
|
||||
action(name, value);
|
||||
return;
|
||||
}
|
||||
});
|
||||
if (el) {
|
||||
(Object as any).entries(obj).forEach((keyValues: string[]) => {
|
||||
const name = keyValues[0];
|
||||
const value = keyValues[1];
|
||||
(el as any)[name] = value;
|
||||
});
|
||||
}
|
||||
storedEl = el;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user