diff --git a/example/WorkerShim.js b/example/WorkerShim.js deleted file mode 100644 index 0724825..0000000 --- a/example/WorkerShim.js +++ /dev/null @@ -1,37 +0,0 @@ -import EventDispatcher from 'EventDispatcher'; - -export default class WorkerShim extends EventDispatcher { - constructor(path) { - super(); - - this._worker = new Worker('./WorkerShim.worker.js'); - this._worker.postMessage(path); - this._loaded = false; - this._postMessageStack = []; - - this._worker.addEventListener('message', (event) => { - - if (event.data === 'WEBWORKER_FINISH_LOADING') { - this._loaded = true; - - for (const { message, transferList } of this._postMessageStack) { - this._worker.postMessage(message, transferList); - } - } else { - this.dispatchEvent(event); - } - }); - } - - postMessage(message, transferList) { - if (this._loaded) { - this._worker.postMessage(message, transferList); - } else { - this._postMessageStack.push({ message, transferList }); - } - } - - terminate() { - this._worker.terminate(); - } -} diff --git a/example/WorkerShim.worker.js b/example/WorkerShim.worker.js deleted file mode 100644 index 1aed1e4..0000000 --- a/example/WorkerShim.worker.js +++ /dev/null @@ -1,13 +0,0 @@ -importScripts('/jspm_packages/system.js', '/jspm.config.js'); - -var loaded = false; -self.onmessage = function(message) { - if (loaded) return; - loaded = true; - - var path = message.data; - - System.import(path).then(function() { - self.postMessage('WEBWORKER_FINISH_LOADING'); - }); -}; diff --git a/example/index.js b/example/index.js index a636903..6e1511d 100644 --- a/example/index.js +++ b/example/index.js @@ -1,7 +1,8 @@ import { transfer } from '/src/index.js'; -import Worker from './WorkerShim.js'; +import Worker from 'worker/WorkerShim'; +import workerSrc from './worker.js!worker'; -const worker = new Worker('./worker.js'); +const worker = new Worker(workerSrc); worker.addEventListener('message', ({ data }) => { const canvas = transfer.decode(data); diff --git a/jspm.config.js b/jspm.config.js index f039bbd..1e67172 100644 --- a/jspm.config.js +++ b/jspm.config.js @@ -12,7 +12,9 @@ SystemJS.config({ "babel-runtime": "npm:babel-runtime@5.8.38", "core-js": "npm:core-js@1.2.7", "plugin-babel": "npm:systemjs-plugin-babel@0.0.12", - "EventDispatcher": "github:mrdoob/eventdispatcher.js@1.0.0" + "EventDispatcher": "github:mrdoob/eventdispatcher.js@1.0.0", + "worker": "github:casperlamboo/plugin-worker@master", + "module": "github:jspm/nodelibs-module@0.2.0-alpha" }, "packages": { "npm:babel-runtime@5.8.38": { diff --git a/package.json b/package.json index b42ae81..5148617 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,9 @@ "EventDispatcher": "github:mrdoob/eventdispatcher.js@^1.0.0", "babel-runtime": "npm:babel-runtime@^5.8.24", "core-js": "npm:core-js@^1.1.4", - "plugin-babel": "npm:systemjs-plugin-babel@^0.0.12" + "module": "github:jspm/nodelibs-module@^0.2.0-alpha", + "plugin-babel": "npm:systemjs-plugin-babel@^0.0.12", + "worker": "github:casperlamboo/plugin-worker@master" }, "peerDependencies": { "assert": "github:jspm/nodelibs-assert@^0.2.0-alpha",