mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00

* fix cordova resume error In cordova browser error is thrown everytime tab/window is reactivated: Uncaught TypeError: Cannot read property 'detail' of undefined at Channel.<anonymous> (util.js:10) at Channel.fire (cordova.js:798) at HTMLDocument.<anonymous> (cordova.js:1511) That was fixed in previous commits, by in latest was reintroduced again. * update types
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { ElementRef } from '@angular/core';
|
|
import { Subject } from 'rxjs';
|
|
|
|
export function inputs(instance: any, el: ElementRef, props: string[]) {
|
|
props.forEach(propName => {
|
|
Object.defineProperty(instance, propName, {
|
|
get: () => el.nativeElement[propName], set: (val: any) => el.nativeElement[propName] = val
|
|
});
|
|
});
|
|
}
|
|
|
|
export function proxyEvent<T>(emitter: Subject<T>, el: EventTarget, eventName: string) {
|
|
el.addEventListener(eventName, (ev: Event | undefined | null) => {
|
|
// ?? cordova might emit "null" events
|
|
emitter.next(ev != null ? (ev as any).detail as T : undefined);
|
|
});
|
|
}
|
|
|
|
export function proxyMethod(ctrlName: string, methodName: string, ...args: any[]) {
|
|
const controller = ensureElementInBody(ctrlName);
|
|
return controller.componentOnReady()
|
|
.then(() => (controller as any)[methodName].apply(controller, args));
|
|
}
|
|
|
|
export function ensureElementInBody(elementName: string) {
|
|
let element = document.querySelector(elementName);
|
|
if (!element) {
|
|
element = document.createElement(elementName);
|
|
document.body.appendChild(element);
|
|
}
|
|
return element as HTMLStencilElement;
|
|
}
|
|
|
|
export function deepEqual(x: any, y: any) {
|
|
if (x === y) {
|
|
return true;
|
|
} else if (typeof x === 'object' && x != null && (typeof y === 'object' && y != null)) {
|
|
if (Object.keys(x).length !== Object.keys(y).length) { return false; }
|
|
|
|
for (const prop in x) {
|
|
if (y.hasOwnProperty(prop)) {
|
|
if (!deepEqual(x[prop], y[prop])) { return false; }
|
|
} else { return false; }
|
|
}
|
|
|
|
return true;
|
|
} else { return false; }
|
|
}
|