meilisearch-admin/app/lib/action-invoker.js
2022-09-15 13:30:58 +03:00

24 lines
482 B
JavaScript

import { registerDestructor } from '@ember/destroyable';
import { action } from '@ember/object';
export default class ActionInvoker {
constructor() {
this.contexts = new Set();
}
@action
invoke(action, ...args) {
this.contexts.forEach((item) => {
item[action]?.(...args);
});
}
@action
subscribe(context) {
this.contexts = this.contexts.add(context);
registerDestructor(context, () => {
this.contexts.delete(context);
});
}
}