@plteam/chat-ui
Version:
CUI Kit is a free and open-source library for creating AI assistant chat interfaces, built with React, Material UI, and TypeScript
35 lines (34 loc) • 868 B
JavaScript
import Emittery from 'emittery';
import { NOOP } from '../utils/NOOP';
export class EventsEmitter {
instance = new Emittery();
on = (name, listener) => {
return this.instance.on(name, listener);
};
when = (name, predicate) => {
return this.instance.once(name, predicate);
};
off = (name, listener) => {
this.instance.off(name, listener);
};
emit = (name, data) => {
this.instance.emit(name, data);
};
getMethods = () => {
return {
on: this.on,
off: this.off,
when: this.when,
};
};
static getMockMethods = () => {
return {
on: () => NOOP,
off: NOOP,
when: () => ({
off: NOOP,
// TODO: #ANY
}),
};
};
}