Skip to content

Commit

Permalink
fix: EventEmmiter
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Dec 12, 2019
1 parent f23263b commit dc52b55
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/daf-cli/src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const listen = async (pollSeconds?: number) => {
})

await core.setupServices()
await core.listen()
await core.getMessagesSince(await dataStore.latestMessageTimestamps())

if (pollSeconds) {
Expand Down
5 changes: 2 additions & 3 deletions packages/daf-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -76,7 +76,6 @@ export class Core extends EventEmitter {
}

public async validateMessages(messages: Message[]): Promise<Message[]> {
debug('validateMessages %O', messages)
const result: Message[] = []
for (const message of messages) {
try {
Expand Down
3 changes: 1 addition & 2 deletions packages/daf-core/src/service/service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion packages/daf-data-store/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
Expand Down

0 comments on commit dc52b55

Please sign in to comment.