Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit('eventName') returns as emit(undefined) #89

Open
selfagency opened this issue Aug 31, 2021 · 2 comments
Open

emit('eventName') returns as emit(undefined) #89

selfagency opened this issue Aug 31, 2021 · 2 comments

Comments

@selfagency
Copy link

My emitter:

import Emittery from 'emittery'
import { logger } from './'

const eventBus: Emittery = new Emittery({
  debug: {
    name: 'eventBus',
    enabled: process.env.ENVIRONMENT !== 'production',
    logger: (type, debugName, eventName, eventData) => {
      logger.debug(`${debugName}: ${type} ${JSON.stringify(eventName)}`, eventData)
    }
  }
})

export default eventBus

My handler

eventBus.on('closeMailer', () => {
  logger.debug('Closing mailer')
  mailer.close()
})

My event

eventBus.emit('closeMailer')

The result:

[1630369974586] DEBUG (20026 on selfagency-m1mini.local): eventBus: subscribe "closeMailer"
[1630369974587] DEBUG (20026 on selfagency-m1mini.local): eventBus: emit undefined

When I try to use a Symbol instead of a string, as specified in the README, TypeScript says it's an invalid type for the parameter.

@selfagency
Copy link
Author

Never mind I just saw the TypeScript instructions

@selfagency
Copy link
Author

selfagency commented Aug 31, 2021

Wait no, even after adding the correct typings...

type Events = {
  closeMailer: undefined
}

const eventBus: Emittery<Events> = new Emittery<Events>({
  debug: {
    name: 'eventBus',
    enabled: process.env.ENVIRONMENT !== 'production',
    logger: (type, debugName, eventName, eventData) => {
      logger.debug(`${debugName}: ${type} ${JSON.stringify(eventName)}`, eventData)
    }
  }
})

I get:

[1630376409736] DEBUG (23571 on selfagency-m1mini.local): eventBus: subscribe "closeMailer"
[1630376409737] DEBUG (23571 on selfagency-m1mini.local): eventBus: emit undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants