Browse Source

simplify worker to just use inline-blob. Just specify `worker: true` thats it.

pull/599/head
Jonathan Grimes 7 years ago
parent
commit
c89bfd874d
  1. 6
      docs/docs.html
  2. 2
      docs/faq.html
  3. 41
      papaparse.js

6
docs/docs.html

@ -749,12 +749,6 @@ var csv = Papa.unparse({ @@ -749,12 +749,6 @@ var csv = Papa.unparse({
Whether or not the browser supports HTML5 Web Workers. If false, <code>worker: true</code> will have no effect.
</td>
</tr>
<tr>
<td><code>Papa.SCRIPT_PATH</code></td>
<td>
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 <i>not</i> read-only and you should set it!)
</td>
</tr>
</table>
</div>

2
docs/faq.html

@ -96,7 +96,7 @@ @@ -96,7 +96,7 @@
<h6 id="async">Can Papa Parse be loaded asynchronously (after the page loads)?</h6>
<p>
Yes. But if you want to use Web Workers, you'll need to specify the relative path to Papa Parse. To do this, set <a href="/docs#readonly">Papa.SCRIPT_PATH</a> to the relative path of the Papa Parse file. In synchronous loading, this is automatically detected.
Yes.
</p>

41
papaparse.js

@ -62,8 +62,7 @@ if (!Array.isArray) @@ -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) @@ -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) @@ -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) @@ -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++;

Loading…
Cancel
Save