/
githubmirror
/
ionic
Обзор
Документация
Войти
/
githubmirror
/
ionic
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular/src/directives/angular-component-lib/utils.ts
65 строк
2 KB
Liam DeBeasi
fix(angular): standalone form components do not error when multiple are used (#28423)
27 окт 2023, 22:08
Не верифицирован
27 окт 2023, 22:08
89698b3
Код
Авторство
О чём код?
/* eslint-disable */ /* tslint:disable */ import { fromEvent } from 'rxjs'; export const proxyInputs = (Cmp: any, inputs: string[]) => { const Prototype = Cmp.prototype; inputs.forEach((item) => { Object.defineProperty(Prototype, item, { get() { return this.el[item]; }, set(val: any) { this.z.runOutsideAngular(() => (this.el[item] = val)); }, /** * In the event that proxyInputs is called * multiple times re-defining these inputs * will cause an error to be thrown. As a result * we set configurable: true to indicate these * properties can be changed. */ configurable: true, }); }); }; export const proxyMethods = (Cmp: any, methods: string[]) => { 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: any, el: any, events: string[]) => { events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName))); }; export const defineCustomElement = (tagName: string, customElement: any) => { if (customElement !== undefined && typeof customElements !== 'undefined' && !customElements.get(tagName)) { customElements.define(tagName, customElement); } }; // tslint:disable-next-line: only-arrow-functions export function ProxyCmp(opts: { defineCustomElementFn?: () => void; inputs?: any; methods?: any }) { const decorator = function (cls: any) { const { defineCustomElementFn, inputs, methods } = opts; if (defineCustomElementFn !== undefined) { defineCustomElementFn(); } if (inputs) { proxyInputs(cls, inputs); } if (methods) { proxyMethods(cls, methods); } return cls; }; return decorator; }