@gravity-ui/app-builder 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -299,7 +299,7 @@ declare module '*.worker.ts' {
299
299
  ```ts
300
300
  import {Worker} from '@gravity-ui/app-builder/worker';
301
301
 
302
- const MyWorker = new Worker(new URL('./my.worker'), import.meta.url);
302
+ const MyWorker = new Worker(new URL('./my.worker', import.meta.url));
303
303
  ```
304
304
 
305
305
  To use the web worker in your main script, you need to communicate with it using the postMessage and onmessage methods. For example:
@@ -1,4 +1,7 @@
1
1
  declare class WebWorker extends Worker {
2
2
  constructor(url: string | URL, options?: WorkerOptions);
3
3
  }
4
- export { WebWorker as Worker };
4
+ declare class SharedWebWorker extends SharedWorker {
5
+ constructor(url: string | URL, options?: string | WorkerOptions);
6
+ }
7
+ export { WebWorker as Worker, SharedWebWorker as SharedWorker };
@@ -1,23 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Worker = void 0;
3
+ exports.SharedWorker = exports.Worker = void 0;
4
4
  class WebWorker extends Worker {
5
5
  constructor(url, options) {
6
- // eslint-disable-next-line camelcase
7
- const publicPath = __webpack_public_path__;
8
- const workerPublicPath = publicPath.match(/^https?:\/\//)
9
- ? publicPath
10
- : new URL(publicPath, window.location.href).toString();
11
- const objectURL = URL.createObjectURL(new Blob([
12
- [
13
- `self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
14
- `importScripts(${JSON.stringify(url.toString())});`,
15
- ].join('\n'),
16
- ], {
17
- type: 'application/javascript',
18
- }));
6
+ const objectURL = generateWorkerLoader(url);
19
7
  super(objectURL, options);
20
8
  URL.revokeObjectURL(objectURL);
21
9
  }
22
10
  }
23
11
  exports.Worker = WebWorker;
12
+ class SharedWebWorker extends SharedWorker {
13
+ constructor(url, options) {
14
+ const objectURL = generateWorkerLoader(url);
15
+ super(objectURL, options);
16
+ URL.revokeObjectURL(objectURL);
17
+ }
18
+ }
19
+ exports.SharedWorker = SharedWebWorker;
20
+ function generateWorkerLoader(url) {
21
+ // eslint-disable-next-line camelcase
22
+ const publicPath = __webpack_public_path__;
23
+ const workerPublicPath = publicPath.match(/^https?:\/\//)
24
+ ? publicPath
25
+ : new URL(publicPath, window.location.href).toString();
26
+ const objectURL = URL.createObjectURL(new Blob([
27
+ [
28
+ `self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
29
+ `importScripts(${JSON.stringify(url.toString())});`,
30
+ ].join('\n'),
31
+ ], {
32
+ type: 'application/javascript',
33
+ }));
34
+ return objectURL;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",