Skip to content

Commit

Permalink
fix(worker-prop): cant instantiate arrow functions
Browse files Browse the repository at this point in the history
When the function passed via the `worker` prop is an arrow function
than we can't construct instances of it with the `new` keyword.
The problem probably went unnoticed because in many implementations
arrow functions are transpiled to regular functions.

Issue: #197
  • Loading branch information
gruhn committed Nov 18, 2020
1 parent 00df746 commit ea50a14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/QrcodeStream.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { keepScanning } from "../misc/scanner.js";
import { thinSquare } from "../misc/track-func.js";
import Camera from "../misc/camera.js";
import CommonAPI from "../mixins/CommonAPI.vue";
import Worker from "../worker/jsqr.js";
import spawnWorker from "../worker/jsqr.js";
export default {
name: "qrcode-stream",
Expand Down Expand Up @@ -58,7 +58,7 @@ export default {
worker: {
type: Function,
default: Worker
default: spawnWorker
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/misc/scanner.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { eventOn } from "callforth";

export async function scan(Worker, imageData) {
const worker = new Worker();
export const scan = async (spawnWorker, imageData) => {
const worker = spawnWorker();

worker.postMessage(imageData, [imageData.data.buffer]);

Expand All @@ -16,14 +16,14 @@ export async function scan(Worker, imageData) {
* Continuously extracts frames from camera stream and tries to read
* potentially pictured QR codes.
*/
export function keepScanning(Worker, camera, options) {
export const keepScanning = (spawnWorker, camera, options) => {
const { detectHandler, locateHandler, minDelay } = options;

let contentBefore = null;
let locationBefore = null;
let lastScanned = performance.now();

const worker = new Worker();
const worker = spawnWorker();

// If worker can't process frames fast enough, memory will quickly full up.
// Make sure to process only one frame at a time.
Expand Down

0 comments on commit ea50a14

Please sign in to comment.