如何记录返回的事件发射器 [英] How to document an event emitter returned

查看:67
本文介绍了如何记录返回的事件发射器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用JSDoc记录MyFunc()中返回的stream发出的事件?

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;
}

推荐答案

您可以通过将事件(event1event2,...)记录为@event MyFunc#event1和MyFunc来记录这些行为,或者由谁进行记录用@fires MyFunc#event1发射.

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.

您还可以记录使用@listens MyFunc#event:event1侦听这些事件的函数.

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

以下是上述标记的官方JSDoc页面:

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自动在每个事件的名称前添加名称空间event:.通常,当您链接到另一个doclet中的事件时,必须包含此命名空间. (@fires标记是值得注意的异常;它允许您省略名称空间.)

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.)

这篇关于如何记录返回的事件发射器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆