Browse Source

Implement Output interface and DOMOutput

-Fix DOMInterface implementation
Lucas de Souza 5 years ago
parent
commit
cc806a3654
3 changed files with 22 additions and 13 deletions
  1. 1 13
      js/io/domInput.js
  2. 15 0
      js/io/domOutput.js
  3. 6 0
      js/io/output.js

+ 1 - 13
js/io/domInput.js

@@ -4,6 +4,7 @@ import $ from 'jquery';
 export class DOMInput extends Input{
 
   constructor (element) {
+    super();
     this.el = $(element);
     this.listeners = [];
     this.setupEvents();
@@ -21,24 +22,11 @@ export class DOMInput extends Input{
     });
   }
 
-  registerListener (listener) {
-    if(!listener.notify) {
-      throw new Error("InternalError: Input listener must implement a notify function.");
-    }
-    this.listeners.push(listener);
-  }
-
   requestInput (callback) {
     this.listeners.push(callback);
     this.el.focus();
   }
 
-  removeListener (listener) {
-    const idx = this.listeners.indexOf(listener);
-    if (idx)
-      this.listeners.splice(idx, 1);
-  }
-
   notifyInput (text) {
     this.listeners.forEach(resolve => {
       resolve(l);

+ 15 - 0
js/io/domOutput.js

@@ -0,0 +1,15 @@
+import { Output } from './output';
+import $ from 'jquery';
+
+export class DOMOutput extends Output {
+
+  constructor (selector) {
+    super();
+    this.el = $(selector);
+  }
+
+  sendOutput (text) {
+    const line = $(`<span class='ivprog-io-output> ${text} </span>`);
+    this.el.append(line);
+  }
+}

+ 6 - 0
js/io/output.js

@@ -0,0 +1,6 @@
+export class Output {
+
+  sendOutput (text) {
+    throw new Error("Must be implemented");
+  }
+}