Skip to content

Commit

Permalink
Abstracted out loadFile logic to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Feb 11, 2019
1 parent d71aa8d commit 13abbd2
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/web/InputWaiter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ class InputWaiter {
}

if (file) {
this.closeFile();
this.loaderWorker = new LoaderWorker();
this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this));
this.loaderWorker.postMessage({"file": file});
this.set(file);
this.loadFile(file);
}
}

Expand All @@ -259,16 +255,8 @@ class InputWaiter {
*/
inputOpen(e) {
e.preventDefault();

const file = e.srcElement.files[0];

if (file) {
this.closeFile();
this.loaderWorker = new LoaderWorker();
this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this));
this.loaderWorker.postMessage({"file": file});
this.set(file);
}
this.loadFile(file);
}


Expand Down Expand Up @@ -326,6 +314,22 @@ class InputWaiter {
}


/**
* Loads a file into the input.
*
* @param {File} file
*/
loadFile(file) {
if (file) {
this.closeFile();
this.loaderWorker = new LoaderWorker();
this.loaderWorker.addEventListener("message", this.handleLoaderMessage.bind(this));
this.loaderWorker.postMessage({"file": file});
this.set(file);
}
}


/**
* Handler for clear IO events.
* Resets the input, output and info areas.
Expand Down

0 comments on commit 13abbd2

Please sign in to comment.