Skip to content

Commit

Permalink
Break circular dep: src/index.ts ... src/util/web_worker.ts -> src/in…
Browse files Browse the repository at this point in the history
…dex.ts (#2156)
  • Loading branch information
zhangyiatmicrosoft authored Feb 9, 2023
1 parent 7351d2f commit b5cc0c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ const exported = {
config.MAX_PARALLEL_IMAGE_REQUESTS = numRequests;
},

workerUrl: '',
get workerUrl(): string {
return config.WORKER_URL;
},

set workerUrl(value: string) {
config.WORKER_URL = value;
},

/**
* Sets a custom load tile function that will be called when using a source that starts with a custom url schema.
Expand Down
2 changes: 2 additions & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ type Config = {
MAX_PARALLEL_IMAGE_REQUESTS: number;
MAX_PARALLEL_IMAGE_REQUESTS_PER_FRAME: number;
REGISTERED_PROTOCOLS: {[x: string]: any};
WORKER_URL: string;
};

const config: Config = {
MAX_PARALLEL_IMAGE_REQUESTS: 16,
MAX_PARALLEL_IMAGE_REQUESTS_PER_FRAME: 8,
REGISTERED_PROTOCOLS: {},
WORKER_URL: ''
};

export default config;
4 changes: 2 additions & 2 deletions src/util/web_worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import maplibregl from '../index';
import config from './config';

import type {WorkerSource} from '../source/worker_source';

Expand Down Expand Up @@ -29,5 +29,5 @@ export interface WorkerGlobalScopeInterface {
}

export default function workerFactory() {
return new Worker(maplibregl.workerUrl);
return new Worker(config.WORKER_URL);
}

0 comments on commit b5cc0c1

Please sign in to comment.