Skip to content

Commit

Permalink
fix uploadService arrow functions 'this'
Browse files Browse the repository at this point in the history
in 31d472e, the reader.onprogress, reader.onerror, and reader.onload functions here were changed from regular `function` declarations to arrow functions.

Usually this makes no difference in the operation of the code, but there is one exception.
Arrow functions don't get their own `this`, they just inherit it from the scope. When I swapped this out and made it an arrow function, I didn't notice it used `this`.

In this instance, `this` was the same thing as `reader`, which we already have a reference to. So it's an easy swap.
  • Loading branch information
JGreenlee committed Feb 21, 2024
1 parent 9174545 commit 2bf2e3e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions www/js/control/uploadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function readDBFile(parentDir, database, callbackFn) {
};

reader.onerror = (error) => {
logDebug('Error while reading file ' + JSON.stringify(this.error));
reject({ error: { message: this.error } });
logDebug('Error while reading file ' + JSON.stringify(reader.error));
reject({ error: { message: reader.error } });

Check warning on line 62 in www/js/control/uploadService.ts

View check run for this annotation

Codecov / codecov/patch

www/js/control/uploadService.ts#L61-L62

Added lines #L61 - L62 were not covered by tests
};

reader.onload = () => {
logDebug('Successful file read with ' + this.result?.['byteLength'] + ' characters');
resolve(new DataView(this.result as ArrayBuffer));
logDebug(`Successful file read with ${reader.result?.['byteLength']} characters`);
resolve(new DataView(reader.result as ArrayBuffer));
};

reader.readAsArrayBuffer(file);
Expand Down

0 comments on commit 2bf2e3e

Please sign in to comment.