Skip to content

Commit b73fb64

Browse files
committed
fix(worker-prop): cant instantiate arrow functions
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
1 parent 00df746 commit b73fb64

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/components/QrcodeStream.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { keepScanning } from "../misc/scanner.js";
2929
import { thinSquare } from "../misc/track-func.js";
3030
import Camera from "../misc/camera.js";
3131
import CommonAPI from "../mixins/CommonAPI.vue";
32-
import Worker from "../worker/jsqr.js";
32+
import spawnWorker from "../worker/jsqr.js";
3333
3434
export default {
3535
name: "qrcode-stream",
@@ -58,7 +58,7 @@ export default {
5858
5959
worker: {
6060
type: Function,
61-
default: Worker
61+
default: spawnWorker
6262
}
6363
},
6464

src/misc/scanner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { eventOn } from "callforth";
22

3-
export async function scan(Worker, imageData) {
4-
const worker = new Worker();
3+
export const scan = async (spawnWorker, imageData) => {
4+
const worker = spawnWorker();
55

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

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

2222
let contentBefore = null;
2323
let locationBefore = null;
2424
let lastScanned = performance.now();
2525

26-
const worker = new Worker();
26+
const worker = spawnWorker();
2727

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

0 commit comments

Comments
 (0)