n8n/packages/editor-ui/src/mixins/emitter.ts
Iván Ovejero 0e4cda5763
refactor: Phase out TSLint in editor-ui (no-changelog) (#4935)
* 🔥 Remove `tslint.json`

* 🔥 Remove TSLint commands

* 🔥 Remove exceptions in `editor-ui`

* 🔥 Remove from `.npmignore`

* 🔥 Remove from `eslint-config`

* 🔥 Remove exception from `design-system`

* 🎨 Prettify

* 📦 Update pnpm-lock

* 🔥 Remove duplicate import

* 🔥 Remove exemption for `no-explicit-any`

* 👕 Inline `no-explicit-any` exemptions
2022-12-15 14:06:00 +01:00

45 lines
1.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import Vue from 'vue';
function broadcast(componentName: string, eventName: string, params: any) {
// @ts-ignore
(this as Vue).$children.forEach((child) => {
const name = child.$options.name;
if (name === componentName) {
// @ts-ignore
// eslint-disable-next-line prefer-spread
child.$emit.apply(child, [eventName].concat(params));
} else {
// @ts-ignore
broadcast.apply(child, [componentName, eventName].concat([params]));
}
});
}
export default Vue.extend({
methods: {
$dispatch(componentName: string, eventName: string, params: any) {
let parent = this.$parent || this.$root;
let name = parent.$options.name;
while (parent && (!name || name !== componentName)) {
parent = parent.$parent;
if (parent) {
name = parent.$options.name;
}
}
if (parent) {
// @ts-ignore
// eslint-disable-next-line prefer-spread
parent.$emit.apply(parent, [eventName].concat(params));
}
},
$broadcast(componentName: string, eventName: string, params: any) {
broadcast.call(this, componentName, eventName, params);
},
},
});