]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/EventEmitter.ts
Fix SelectionManager initializing
[mirror_xterm.js.git] / src / EventEmitter.ts
index 80bd303515dff3c546ba07a5e177d29d26ab4d78..a4fd4542c3c8a97ad4e2aa9b88696a407890ccc0 100644 (file)
@@ -11,7 +11,9 @@ export class EventEmitter {
   private _events: {[type: string]: ListenerType[]};
 
   constructor() {
-    this._events = {};
+    // Restore the previous events if available, this will happen if the
+    // constructor is called multiple times on the same object (terminal reset).
+    this._events = this._events || {};
   }
 
   public on(type, listener): void {
@@ -44,21 +46,18 @@ export class EventEmitter {
   public once(type, listener): any {
     function on() {
       let args = Array.prototype.slice.call(arguments);
-      this.removeListener(type, on);
+      this.off(type, on);
       return listener.apply(this, args);
     }
     (<any>on).listener = listener;
     return this.on(type, on);
   }
 
-  public emit(type): void {
+  public emit(type: string, ...args: any[]): void {
     if (!this._events[type]) {
       return;
     }
-
-    let args = Array.prototype.slice.call(arguments, 1);
     let obj = this._events[type];
-
     for (let i = 0; i < obj.length; i++) {
       obj[i].apply(this, args);
     }