How to document an event emitter returned

╄→гoц情女王★ 提交于 2019-12-07 04:00:36

问题


How to document the events emitted by stream returned in MyFunc() with 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;
}

回答1:


You can document these behaviors by documenting your events (event1, event2, ...) as @event MyFunc#event1 and MyFunc, or whoever does the emitting, with @fires MyFunc#event1.

You can also document functions that listen to those events with @listens MyFunc#event:event1.

Here are the official JSDoc pages for the aforementioned tags:

  • https://jsdoc.app/tags-event.html
  • https://jsdoc.app/tags-fires.html
  • https://jsdoc.app/tags-listens.html

Do note some nuance around "event" mentioned in the tags event page, repeating here:

JSDoc automatically prepends the namespace event: to each event's name. In general, you must include this namespace when you link to the event in another doclet. (The @fires tag is a notable exception; it allows you to omit the namespace.)



来源:https://stackoverflow.com/questions/34652398/how-to-document-an-event-emitter-returned

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!