From c89bfd874d06d7e44395713f3f99510ffbb1bf64 Mon Sep 17 00:00:00 2001 From: Jonathan Grimes Date: Mon, 19 Nov 2018 14:02:10 -0600 Subject: [PATCH] simplify worker to just use inline-blob. Just specify `worker: true` thats it. --- docs/docs.html | 6 ------ docs/faq.html | 2 +- papaparse.js | 41 +++-------------------------------------- 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/docs/docs.html b/docs/docs.html index b424c7a..cdd0f06 100644 --- a/docs/docs.html +++ b/docs/docs.html @@ -749,12 +749,6 @@ var csv = Papa.unparse({ Whether or not the browser supports HTML5 Web Workers. If false, worker: true will have no effect. - - Papa.SCRIPT_PATH - - The relative path to Papa Parse. This is automatically detected when Papa Parse is loaded synchronously. However, if you load Papa Parse asynchronously (e.g. with RequireJS), you need to set this variable manually in order to use Web Workers. (In those cases, this variable is not read-only and you should set it!) - - diff --git a/docs/faq.html b/docs/faq.html index 9af0863..02d9594 100644 --- a/docs/faq.html +++ b/docs/faq.html @@ -96,7 +96,7 @@
Can Papa Parse be loaded asynchronously (after the page loads)?

- Yes. But if you want to use Web Workers, you'll need to specify the relative path to Papa Parse. To do this, set Papa.SCRIPT_PATH to the relative path of the Papa Parse file. In synchronous loading, this is automatically detected. + Yes.

diff --git a/papaparse.js b/papaparse.js index 3ca414e..14edf60 100755 --- a/papaparse.js +++ b/papaparse.js @@ -62,8 +62,7 @@ if (!Array.isArray) } var IS_WORKER = !global.document && !!global.postMessage, - IS_PAPA_WORKER = IS_WORKER && (/blob:/i.test(global.location.protocol) || /(\?|&)papaworker(=|&|$)/.test(global.location.search)), - LOADED_SYNC = false, AUTO_SCRIPT_PATH; + IS_PAPA_WORKER = IS_WORKER && /blob:/i.test((global.location || {}).protocol); var workers = {}, workerIdCounter = 0; var Papa = {}; @@ -76,7 +75,6 @@ if (!Array.isArray) Papa.BYTE_ORDER_MARK = '\ufeff'; Papa.BAD_DELIMITERS = ['\r', '\n', '"', Papa.BYTE_ORDER_MARK]; Papa.WORKERS_SUPPORTED = !IS_WORKER && !!global.Worker; - Papa.SCRIPT_PATH = null; // Must be set by your code if you use workers and this lib is loaded asynchronously Papa.NODE_STREAM_INPUT = 1; // Configurable chunk sizes for local and remote files, respectively @@ -194,23 +192,6 @@ if (!Array.isArray) { global.onmessage = workerThreadReceivedMessage; } - else if (Papa.WORKERS_SUPPORTED) - { - AUTO_SCRIPT_PATH = getScriptPath(); - - // Check if the script was loaded synchronously - if (!document.body) - { - // Body doesn't exist yet, must be synchronous - LOADED_SYNC = true; - } - else - { - document.addEventListener('DOMContentLoaded', function() { - LOADED_SYNC = true; - }, true); - } - } @@ -1695,28 +1676,12 @@ if (!Array.isArray) } - // If you need to load Papa Parse asynchronously and you also need worker threads, hard-code - // the script path here. See: https://github.com/mholt/PapaParse/issues/87#issuecomment-57885358 - function getScriptPath() - { - var scripts = document.getElementsByTagName('script'); - return scripts.length ? scripts[scripts.length - 1].src : ''; - } - function newWorker() { if (!Papa.WORKERS_SUPPORTED) return false; - if (!LOADED_SYNC && Papa.SCRIPT_PATH === null) - throw new Error( - 'Script path cannot be determined automatically when Papa Parse is loaded asynchronously. ' + - 'You need to set Papa.SCRIPT_PATH manually.' - ); - var workerUrl = Papa.SCRIPT_PATH || AUTO_SCRIPT_PATH; - // Append 'papaworker' to the search string to tell papaparse that this is our worker. - workerUrl += (workerUrl.indexOf('?') !== -1 ? '&' : '?') + 'papaworker'; - if (Papa.SCRIPT_PATH === 'blob') - workerUrl = getWorkerBlob(); + + var workerUrl = getWorkerBlob(); var w = new global.Worker(workerUrl); w.onmessage = mainThreadReceivedMessage; w.id = workerIdCounter++;