Skip to content

Commit

Permalink
fix: ensure KDBush worker works in prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
flekschas committed Aug 3, 2024
1 parent 109c20e commit c712ae6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.10.2

- Fix: expose x start/end and y start/end for horizontal and vertical line annotations.
- Fix: ensure KDBush worker works in prod build

## 1.10.1

Expand Down
14 changes: 9 additions & 5 deletions src/kdbush.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ const KDBush = createKDBushClass();
const WORKER_THRESHOLD = 1000000;

const createWorker = (fn) => {
let kdbushStr = createKDBushClass.toString();
kdbushStr = kdbushStr.substring(10, kdbushStr.length - 18);
let fnStr = fn.toString();
fnStr = fnStr.substring(10, fnStr.length - 2);
const kdbushStr = createKDBushClass.toString();
const fnStr = fn.toString();
const workerStr =
`const createKDBushClass = ${kdbushStr};` +
'KDBush = createKDBushClass();' +
`const createWorker = ${fnStr};` +
'createWorker();';

return new Worker(
window.URL.createObjectURL(
new Blob([`${kdbushStr};${fnStr}`], {
new Blob([workerStr], {
type: 'text/javascript',
})
)
Expand Down

0 comments on commit c712ae6

Please sign in to comment.