From dc52b55aad6c612266ce136636f6aa65e524b59b Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Thu, 12 Dec 2019 11:53:48 +0200 Subject: [PATCH] fix: EventEmmiter --- packages/daf-cli/src/services.ts | 1 + packages/daf-core/src/core.ts | 5 ++--- packages/daf-core/src/service/service-manager.ts | 3 +-- packages/daf-data-store/src/graphql.ts | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/daf-cli/src/services.ts b/packages/daf-cli/src/services.ts index ab55d97bb..2b505b664 100644 --- a/packages/daf-cli/src/services.ts +++ b/packages/daf-cli/src/services.ts @@ -19,6 +19,7 @@ export const listen = async (pollSeconds?: number) => { }) await core.setupServices() + await core.listen() await core.getMessagesSince(await dataStore.latestMessageTimestamps()) if (pollSeconds) { diff --git a/packages/daf-core/src/core.ts b/packages/daf-core/src/core.ts index 2603662a0..66814f7a2 100644 --- a/packages/daf-core/src/core.ts +++ b/packages/daf-core/src/core.ts @@ -65,8 +65,8 @@ export class Core extends EventEmitter { } async listen() { - debug('Listening...') - this.serviceManager.on(ServiceEventTypes.NewMessages, this.validateMessages) + debug('Listening for new messages') + this.serviceManager.on(ServiceEventTypes.NewMessages, this.validateMessages.bind(this)) this.serviceManager.listen() } @@ -76,7 +76,6 @@ export class Core extends EventEmitter { } public async validateMessages(messages: Message[]): Promise { - debug('validateMessages %O', messages) const result: Message[] = [] for (const message of messages) { try { diff --git a/packages/daf-core/src/service/service-manager.ts b/packages/daf-core/src/service/service-manager.ts index 7959b446b..09496c6bd 100644 --- a/packages/daf-core/src/service/service-manager.ts +++ b/packages/daf-core/src/service/service-manager.ts @@ -39,14 +39,13 @@ export class ServiceManager extends EventEmitter { for (const controller of this.controllers) { const instance = new controller(issuer, this.didResolver) await instance.ready - instance.on(ServiceEventTypes.NewMessages, this.onNewMessages) + instance.on(ServiceEventTypes.NewMessages, this.onNewMessages.bind(this)) this.controllerInstances.push(instance) } } } private onNewMessages(messages: Message[]) { - debug('onNewMessage kakakaka %O', messages) this.emit(ServiceEventTypes.NewMessages, messages) } diff --git a/packages/daf-data-store/src/graphql.ts b/packages/daf-data-store/src/graphql.ts index ca427b668..17041df2e 100644 --- a/packages/daf-data-store/src/graphql.ts +++ b/packages/daf-data-store/src/graphql.ts @@ -10,7 +10,6 @@ export const resolvers = { metaData: async (message: any, {}, { dataStore }: Context) => dataStore.messageMetaData(message.id), thread: async (message: any, {}, { dataStore }: Context) => { const messages = await dataStore.findMessages({ threadId: message.threadId }) - console.log('AAAA', messages) return messages.filter((item: any) => item.id !== message.id) }, },