primus / eventemitter3

EventEmitter3 - Because there's also a number 2. And we're faster.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docs: add simple example of event being emitted

0xDones opened this issue · comments

I missed this while looking at this package, a very simple example emitting and listening to an event on the usage part would be nice.

Let me rephrase it. What I can see when I read the README is just that:

var EventEmitter = require('eventemitter3');

What about adding something like this? Is that the way we should be doing?

var EventEmitter = require('eventemitter3');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
  console.log('an event occurred!');
});
myEmitter.emit('event');

You have that example here https://nodejs.org/api/events.html#emitteroneventname-listener. It is only 2 click away.

Is this link correct? I'm not sure which example you are trying to show me

Yes the link is correct, try to open it in different browser (it also does not work for me on Chrome).

Yep that was it, opening it on Safari worked. So my question was more about how the maintainers recommend the users to use it. In most open source projects there is are examples on the README or an examples directory containing some common use case, and I think that helps users to get started. This issue can be closed.

Yes, I understand but this module works like the Node.js EventEmitter so there is no reason to duplicate examples. This is documented.

For the API documentation, please follow the official Node.js documentation: http://nodejs.org/api/events.html

I'm closing this as answered.