2021-05-21 16:51:13 +02:00
|
|
|
import EventEmitter from 'events';
|
2021-05-02 21:11:17 +02:00
|
|
|
import { EventHook } from './types/option';
|
|
|
|
import {
|
2019-06-18 19:22:18 +02:00
|
|
|
FEATURE_CREATED,
|
|
|
|
FEATURE_UPDATED,
|
|
|
|
FEATURE_ARCHIVED,
|
|
|
|
FEATURE_REVIVED,
|
2021-05-02 21:11:17 +02:00
|
|
|
} from './types/events';
|
2019-06-18 19:22:18 +02:00
|
|
|
|
2021-05-02 21:11:17 +02:00
|
|
|
export const addEventHook = (
|
|
|
|
eventHook: EventHook,
|
|
|
|
eventStore: EventEmitter,
|
|
|
|
): void => {
|
2021-08-12 15:04:37 +02:00
|
|
|
eventStore.on(FEATURE_CREATED, (data) => {
|
2019-06-18 19:22:18 +02:00
|
|
|
eventHook(FEATURE_CREATED, data);
|
|
|
|
});
|
2021-08-12 15:04:37 +02:00
|
|
|
eventStore.on(FEATURE_UPDATED, (data) => {
|
2019-06-18 19:22:18 +02:00
|
|
|
eventHook(FEATURE_UPDATED, data);
|
|
|
|
});
|
2021-08-12 15:04:37 +02:00
|
|
|
eventStore.on(FEATURE_ARCHIVED, (data) => {
|
2019-06-18 19:22:18 +02:00
|
|
|
eventHook(FEATURE_ARCHIVED, data);
|
|
|
|
});
|
2021-08-12 15:04:37 +02:00
|
|
|
eventStore.on(FEATURE_REVIVED, (data) => {
|
2019-06-18 19:22:18 +02:00
|
|
|
eventHook(FEATURE_REVIVED, data);
|
|
|
|
});
|
|
|
|
};
|