web-background 0.0.1 → 0.0.3

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
@@ -2,8 +2,8 @@
2
2
  This module is implemented as a web walker and is available in web browsers.
3
3
  해당 모듈은 웹 워커로 구현되며 브라우저에서 사용할 수 있습니다.
4
4
 
5
- It runs in an isolated environment and cannot be referenced by external variables and external module.
6
- 격리된 환경에서 실행되므로 외부의 변수에 참조하지 못합니다.
5
+ It runs in isolation, can't be access external variables and modules
6
+ 격리된 환경에서 실행되므로 외부 모듈 및 외부 변수에 접근할 수 없습니다.
7
7
 
8
8
  In most cases, this module is not required.
9
9
  Recommended for long task
@@ -14,7 +14,7 @@ WebWorker에서 실행되므로 DOM API를 포함한 WebAPI를 사용하지 못
14
14
 
15
15
  ## Example
16
16
 
17
- **worker**
17
+ **background**
18
18
  ```ts
19
19
  async function runLongTask () {
20
20
  const getCoordinate = background((imageData: ImageData) => {
@@ -1,7 +1 @@
1
- type ReturnFn<ReturnValue> = () => ReturnValue;
2
- type ReturnFnWithPayload<Payload, ReturnValue> = (payload: Payload) => ReturnValue;
3
- export declare function background<Payload = never, ReturnValue = void>(fn: (payload: Payload) => ReturnValue): {
4
- (): Promise<ReturnValue>;
5
- (payload: Payload): Promise<ReturnValue>;
6
- } | (Payload extends never ? ReturnFn<Promise<ReturnValue>> : ReturnFnWithPayload<Payload, Promise<ReturnValue>>);
7
- export {};
1
+ export declare function background<Payload = never, ReturnValue = void>(fn: (payload: Payload) => ReturnValue): any;
package/dist/index.js CHANGED
@@ -83,15 +83,17 @@ class WorkerBuilder {
83
83
 
84
84
  function background(fn) {
85
85
  function createWorker() {
86
- return WorkerBuilder.fromModule((UtilWorker), { module: fn, type: 'module' });
86
+ return WorkerBuilder.fromModule((UtilWorker), { module: fn });
87
87
  }
88
88
  if (typeof window === 'undefined') {
89
89
  function runWithCreatingWorker(payload) {
90
- return createWorker().request(payload);
90
+ const worker = createWorker();
91
+ return worker.request.call(worker, payload);
91
92
  }
92
93
  return runWithCreatingWorker;
93
94
  }
94
- return createWorker().request;
95
+ const worker = createWorker();
96
+ return worker.request.bind(worker);
95
97
  }
96
98
 
97
99
  export { background };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "Worker",
7
7
  "Background"
8
8
  ],
9
- "version": "0.0.1",
9
+ "version": "0.0.3",
10
10
  "main": "dist/index.js",
11
11
  "module": "dist/index.js",
12
12
  "type": "module",