Skip to content

Commit

Permalink
Change Worker from inherit to member
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSodaSea committed Feb 17, 2024
1 parent e122e5f commit eb677e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ export function buildWorkerCode(source: string, moduleType: ModuleType)
let result = `\
const WORKER_CODE = ${JSON.stringify(source)};
let WORKER_URL = null;
class WorkerInstance extends Worker
class WorkerInstance
{
constructor()
{
if (!WORKER_URL)
{
WORKER_URL = URL.createObjectURL(new Blob([WORKER_CODE], { type: 'application/javascript' }));
}
super(WORKER_URL);
this.worker = new Worker(WORKER_URL);
}
}
WorkerInstance.revokeObjectURL = function revokeObjectURL()
Expand Down
4 changes: 2 additions & 2 deletions test/JestTransform.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ describe('Test', () =>
{
const worker = new AdderWorker();

worker.onmessage = (event) =>
worker.worker.onmessage = (event) =>
{
expect(event.data).toBe(2);
resolve();
};

worker.postMessage({ a: 1, b: 1 });
worker.worker.postMessage({ a: 1, b: 1 });
})
);
});
4 changes: 3 additions & 1 deletion test/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
declare module '*.worker.ts'
{
class WorkerInstance extends Worker
class WorkerInstance
{
public worker: Worker;

constructor();

static revokeObjectURL(): void;
Expand Down

0 comments on commit eb677e3

Please sign in to comment.