How to document a returned event emitter

How to document events emitted by stream returned to MyFunc() using JSDoc?

 /** * [MyFunc description] * @param {Object} opts - [description] * @return {Stream} - [description] */ function MyFunc (opts) { // stream is an EventEmitter var stream = new MyEventEmitter(); stream.emit('event1', ... ); stream.emit('event2', ... ); return stream; } 
+6
source share
1 answer

You can document this behavior by documenting your events ( event1 , event2 , ...) as @event MyFunc#event1 and MyFunc, or whoever @fires MyFunc#event1 , with @fires MyFunc#event1 .

You can also document the functions that listen to these events using @listens MyFunc#event:event1 .

Here are the official JSDoc pages for the above tags:

Pay attention to some nuance around the "event" mentioned on the tag event page, repeating here:

JSDoc automatically adds event: namespaces to each event name. In general, you should include this namespace when referencing an event in another report. (The @fires tag is a notable exception; it allows you to skip the namespace.)

+2
source

Source: https://habr.com/ru/post/1240072/


All Articles