@ionic/angular
Version:
Angular specific wrappers for @ionic/core
47 lines • 1.5 kB
JavaScript
// TODO: Is there a way we can grab this from angular-component-lib instead?
/* eslint-disable */
/* tslint:disable */
import { fromEvent } from 'rxjs';
export const proxyInputs = (Cmp, inputs) => {
const Prototype = Cmp.prototype;
inputs.forEach((item) => {
Object.defineProperty(Prototype, item, {
get() {
return this.el[item];
},
set(val) {
this.z.runOutsideAngular(() => (this.el[item] = val));
},
});
});
};
export const proxyMethods = (Cmp, methods) => {
const Prototype = Cmp.prototype;
methods.forEach((methodName) => {
Prototype[methodName] = function () {
const args = arguments;
return this.z.runOutsideAngular(() => this.el[methodName].apply(this.el, args));
};
});
};
export const proxyOutputs = (instance, el, events) => {
events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName)));
};
// tslint:disable-next-line: only-arrow-functions
export function ProxyCmp(opts) {
const decorator = function (cls) {
const { defineCustomElementFn, inputs, methods } = opts;
if (defineCustomElementFn !== undefined) {
defineCustomElementFn();
}
if (inputs) {
proxyInputs(cls, inputs);
}
if (methods) {
proxyMethods(cls, methods);
}
return cls;
};
return decorator;
}
//# sourceMappingURL=proxy.js.map