在electron中一个事件可以被添加监听多次么?

看了下electron的代码

class IncomingMessage extends EventEmitter {

    // Docs: http://electron.atom.io/docs/api/incoming-message

    /**
     * Emitted when a request has been canceled during an ongoing HTTP transaction.
     */
    on(event: 'aborted', listener: Function): this;
    once(event: 'aborted', listener: Function): this;
    addListener(event: 'aborted', listener: Function): this;
    removeListener(event: 'aborted', listener: Function): this;
    /**
     * The data event is the usual method of transferring response data into
     * applicative code.
     */
    on(event: 'data', listener: (
                                 /**
                                  * A chunk of response body's data.
                                  */
                                 chunk: Buffer) => void): this;
    once(event: 'data', listener: (
                                 /**
                                  * A chunk of response body's data.
                                  */
                                 chunk: Buffer) => void): this;
    addListener(event: 'data', listener: (
                                 /**
                                  * A chunk of response body's data.
                                  */
                                 chunk: Buffer) => void): this;
    removeListener(event: 'data', listener: (
                                 /**
                                  * A chunk of response body's data.
                                  */
                                 chunk: Buffer) => void): this;
    /**
     * Indicates that response body has ended.
     */
    on(event: 'end', listener: Function): this;
    once(event: 'end', listener: Function): this;
    addListener(event: 'end', listener: Function): this;
    removeListener(event: 'end', listener: Function): this;
    /**
     * error Error - Typically holds an error string identifying failure root cause.
     * Emitted when an error was encountered while streaming response data events. For
     * instance, if the server closes the underlying while the response is still
     * streaming, an error event will be emitted on the response object and a close
     * event will subsequently follow on the request object.
     */
    on(event: 'error', listener: Function): this;
    once(event: 'error', listener: Function): this;
    addListener(event: 'error', listener: Function): this;
    removeListener(event: 'error', listener: Function): this;
    headers: any;
    httpVersion: string;
    httpVersionMajor: number;
    httpVersionMinor: number;
    statusCode: number;
    statusMessage: string;
  }

对于进入消息提供的API

目前程序是一个与telet交互的程序,输出的内容渲染到了web页,所以on('data')已经用了,而且不能被移除。

移除了页面就不输出连续的内容了,必须保持监听。

现在因为要做触发器,所以需要在另外一个类里监听'data'事件

eventNames() 打印可以看到[ 'end', 'finish', '_socketEnd', 'data' ]

所以我的问题是,如何再增加一个对'data'的监听事件?

用过addListener,但是打印事件名还是[ 'end', 'finish', '_socketEnd', 'data' ]所以也没办法用removeListener移除。

求解

阅读 5.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题