easy-web-worker 1.0.7 → 1.0.9
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/lib/EasyWebWorker.d.ts +97 -1
- package/lib/EasyWebWorker.js +26 -2
- package/lib/StaticEasyWebWorker.d.ts +3 -2
- package/lib/StaticEasyWebWorker.js +14 -13
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +2 -3
- package/lib/EasyWebWorker.d.ts.map +0 -1
- package/lib/EasyWebWorkerFactory.d.ts +0 -8
- package/lib/EasyWebWorkerFactory.d.ts.map +0 -1
- package/lib/EasyWebWorkerFactory.js +0 -35
- package/lib/EasyWebWorkerFixtures.d.ts.map +0 -1
- package/lib/EasyWebWorkerMessage.d.ts.map +0 -1
- package/lib/EasyWebWorkerTypes.d.ts +0 -97
- package/lib/EasyWebWorkerTypes.d.ts.map +0 -1
- package/lib/EasyWebWorkerTypes.js +0 -2
- package/lib/StaticEasyWebWorker.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
package/lib/EasyWebWorker.d.ts
CHANGED
|
@@ -1,5 +1,101 @@
|
|
|
1
|
-
import { EasyWebWorkerBody, IWorkerConfig } from './EasyWebWorkerTypes';
|
|
2
1
|
import { CancelablePromise } from 'cancelable-promise-jq';
|
|
2
|
+
/**
|
|
3
|
+
* EasyWorker Config
|
|
4
|
+
* */
|
|
5
|
+
export interface IWorkerConfig {
|
|
6
|
+
/**
|
|
7
|
+
** External scripts that you want to include in your worker
|
|
8
|
+
*/
|
|
9
|
+
scripts: string[];
|
|
10
|
+
/**
|
|
11
|
+
** Identifier of your worker, this is in case you want to add a name to your worker file, otherwise an unique generic Id will be added as a name
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* Callback that will be executed when the worker fails, this not necessary affect the current message execution
|
|
16
|
+
* */
|
|
17
|
+
onWorkerError: (error: ErrorEvent) => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* This is the structure that the messages of the worker will have
|
|
21
|
+
*/
|
|
22
|
+
export interface IMessageData<IPayload = null> {
|
|
23
|
+
/**
|
|
24
|
+
* This are the parameters included in the message
|
|
25
|
+
*/
|
|
26
|
+
payload: IPayload;
|
|
27
|
+
/**
|
|
28
|
+
* The messages from the worker could include errors if something went wrong
|
|
29
|
+
* */
|
|
30
|
+
reason: unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Indicates if the message was canceled
|
|
33
|
+
* */
|
|
34
|
+
wasCanceled: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The messages from the worker could include a progress percentage
|
|
37
|
+
* */
|
|
38
|
+
progressPercentage?: number;
|
|
39
|
+
/**
|
|
40
|
+
* This is the message id
|
|
41
|
+
* */
|
|
42
|
+
messageId: string;
|
|
43
|
+
}
|
|
44
|
+
export interface IEasyWorkerInstance<IPayload = null, IResult = void> {
|
|
45
|
+
/**
|
|
46
|
+
* Use this method to defined which will be the functionality of your worker when a message is send to it
|
|
47
|
+
* @param {function} callback - This is the callback that will be executed when a message is received
|
|
48
|
+
* @param {IEasyWebWorkerMessage} callback.message - This is the message that was received
|
|
49
|
+
* @param {IEasyWebWorkerMessage} callback.message.messageId - This is the message id
|
|
50
|
+
* @param {IEasyWebWorkerMessage} callback.message.payload - This are the parameters included in the message
|
|
51
|
+
* @param {IEasyWebWorkerMessage} callback.message.reject - This method is used to reject the message from inside the worker
|
|
52
|
+
* @param {IEasyWebWorkerMessage} callback.message.reportProgress - This method is used to report the progress of the message from inside the worker
|
|
53
|
+
* @param {IEasyWebWorkerMessage} callback.message.resolve - This method is used to resolve the message from inside the worker
|
|
54
|
+
* @param {MessageEvent} callback.event - This is the event that was received
|
|
55
|
+
* */
|
|
56
|
+
onMessage(callback: (message: IEasyWebWorkerMessage<IPayload, IResult>, event: MessageEvent<IMessageData<IPayload>>) => void): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* This type defined the structure that a WorkerBody should have.
|
|
60
|
+
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
|
61
|
+
* @template IResult - Indicates if your WORKERS messages has a result... NULL indicates all you messages are Promise<void>
|
|
62
|
+
* @param {IEasyWorkerInstance<IPayload, IResult>} easyWorker - ,
|
|
63
|
+
*/
|
|
64
|
+
export type EasyWebWorkerBody<IPayload = null, IResult = void> = (
|
|
65
|
+
/**
|
|
66
|
+
* This is the instance of the worker that you can use to communicate with the main thread
|
|
67
|
+
*/
|
|
68
|
+
easyWorker: IEasyWorkerInstance<IPayload, IResult>,
|
|
69
|
+
/**
|
|
70
|
+
* This is the context of the worker, you can use it to access to the global scope of the worker
|
|
71
|
+
* */
|
|
72
|
+
context: any) => void;
|
|
73
|
+
export interface IEasyWebWorkerMessage<IPayload = null, IResult = void> {
|
|
74
|
+
/**
|
|
75
|
+
* This is the message id
|
|
76
|
+
*/
|
|
77
|
+
messageId: string;
|
|
78
|
+
/**
|
|
79
|
+
* This are the parameters included in the message
|
|
80
|
+
* */
|
|
81
|
+
payload: IPayload;
|
|
82
|
+
/**
|
|
83
|
+
* This method is used to reject the message from inside the worker
|
|
84
|
+
* */
|
|
85
|
+
reject: (reason?: unknown) => void;
|
|
86
|
+
/**
|
|
87
|
+
* This method is used to report the progress of the message from inside the worker
|
|
88
|
+
* */
|
|
89
|
+
reportProgress(progressPercentage: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* This method is used to resolve the message from inside the worker
|
|
92
|
+
* */
|
|
93
|
+
resolve: IPayload extends null ? (reason?: unknown) => CancelablePromise<IResult> : (payload: IPayload, reason?: unknown) => CancelablePromise<IResult>;
|
|
94
|
+
/**
|
|
95
|
+
* This method is used to cancel the message from inside the worker
|
|
96
|
+
* */
|
|
97
|
+
cancel: (reason?: unknown) => void;
|
|
98
|
+
}
|
|
3
99
|
/**
|
|
4
100
|
* This is a class to create global-store objects
|
|
5
101
|
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
package/lib/EasyWebWorker.js
CHANGED
|
@@ -27,8 +27,32 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
exports.EasyWebWorker = void 0;
|
|
29
29
|
var EasyWebWorkerMessage_1 = require("./EasyWebWorkerMessage");
|
|
30
|
-
var EasyWebWorkerFactory_1 = require("./EasyWebWorkerFactory");
|
|
31
30
|
var EasyWebWorkerFixtures_1 = require("./EasyWebWorkerFixtures");
|
|
31
|
+
var getImportScriptsTemplate = function (scripts) {
|
|
32
|
+
if (scripts === void 0) { scripts = []; }
|
|
33
|
+
if (!scripts.length)
|
|
34
|
+
return '';
|
|
35
|
+
return "self.importScripts([\"".concat(scripts.join('","'), "\"]);");
|
|
36
|
+
};
|
|
37
|
+
var blob = function (source, imports) {
|
|
38
|
+
if (imports === void 0) { imports = []; }
|
|
39
|
+
var content = "".concat(getImportScriptsTemplate(imports), "\n ").concat(source);
|
|
40
|
+
return (window.URL || window.webkitURL).createObjectURL(new Blob([content], {
|
|
41
|
+
type: 'application/javascript',
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
var blobWorker = function (source, imports) {
|
|
45
|
+
if (imports === void 0) { imports = []; }
|
|
46
|
+
var template = (0, EasyWebWorkerFixtures_1.WorkerTemplate)();
|
|
47
|
+
var contentCollection = Array.isArray(source) ? source : [source];
|
|
48
|
+
return (window.URL || window.webkitURL).createObjectURL(new Blob([
|
|
49
|
+
"".concat(getImportScriptsTemplate(imports), "\n \n ").concat(template, "\n \n ").concat(contentCollection
|
|
50
|
+
.map(function (content, index) {
|
|
51
|
+
return "// content #".concat(index, "\n(").concat(content.toString(), ")(easyWorker, self);");
|
|
52
|
+
})
|
|
53
|
+
.join('\n\n')),
|
|
54
|
+
], { type: 'application/javascript' }));
|
|
55
|
+
};
|
|
32
56
|
/**
|
|
33
57
|
* This is a class to create global-store objects
|
|
34
58
|
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
|
@@ -179,7 +203,7 @@ var EasyWebWorker = /** @class */ (function () {
|
|
|
179
203
|
if (this.isExternalWorkerFile) {
|
|
180
204
|
return this.workerBody;
|
|
181
205
|
}
|
|
182
|
-
return
|
|
206
|
+
return blobWorker(this.workerBody, this.scripts);
|
|
183
207
|
};
|
|
184
208
|
EasyWebWorker.prototype.createWorker = function () {
|
|
185
209
|
var _this = this;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CancelablePromise } from 'cancelable-promise-jq';
|
|
2
|
+
import { IEasyWebWorkerMessage, IEasyWorkerInstance, IMessageData } from './EasyWebWorker';
|
|
2
3
|
/**
|
|
3
4
|
* This message wrap the interaction with the worker to ensure that the message is correctly synchronized with the EasyWebWorker
|
|
4
5
|
*/
|
|
@@ -15,7 +16,7 @@ export declare class WorkerMessage<IPayload = null, IResult = void> implements I
|
|
|
15
16
|
/**
|
|
16
17
|
* This method is used to resolve the message from inside the worker
|
|
17
18
|
*/
|
|
18
|
-
resolve
|
|
19
|
+
resolve: IPayload extends null ? (reason?: unknown) => CancelablePromise<IResult> : (payload: IPayload, reason?: unknown) => CancelablePromise<IResult>;
|
|
19
20
|
/**
|
|
20
21
|
* This method is used to reject the message from inside the worker
|
|
21
22
|
* */
|
|
@@ -12,32 +12,33 @@ var WorkerMessage = /** @class */ (function () {
|
|
|
12
12
|
*/
|
|
13
13
|
function WorkerMessage(payload, messageId, messageTargetOrigin) {
|
|
14
14
|
if (messageTargetOrigin === void 0) { messageTargetOrigin = '*'; }
|
|
15
|
+
var _this = this;
|
|
15
16
|
this.payload = payload;
|
|
16
17
|
this.messageId = messageId;
|
|
17
18
|
this.messageTargetOrigin = messageTargetOrigin;
|
|
19
|
+
/**
|
|
20
|
+
* This method is used to resolve the message from inside the worker
|
|
21
|
+
*/
|
|
22
|
+
this.resolve = (function () {
|
|
23
|
+
var payload = [];
|
|
24
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
25
|
+
payload[_i] = arguments[_i];
|
|
26
|
+
}
|
|
27
|
+
var messageId = _this.messageId;
|
|
28
|
+
self.postMessage({ messageId: messageId, payload: payload }, _this.messageTargetOrigin);
|
|
29
|
+
});
|
|
18
30
|
}
|
|
19
|
-
/**
|
|
20
|
-
* This method is used to resolve the message from inside the worker
|
|
21
|
-
*/
|
|
22
|
-
WorkerMessage.prototype.resolve = function () {
|
|
23
|
-
var payload = [];
|
|
24
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
25
|
-
payload[_i] = arguments[_i];
|
|
26
|
-
}
|
|
27
|
-
var messageId = this.messageId;
|
|
28
|
-
self.postMessage({ messageId: messageId, payload: payload }, this.messageTargetOrigin);
|
|
29
|
-
};
|
|
30
31
|
/**
|
|
31
32
|
* This method is used to reject the message from inside the worker
|
|
32
33
|
* */
|
|
33
34
|
WorkerMessage.prototype.reject = function (reason) {
|
|
34
|
-
|
|
35
|
+
self.postMessage({ reason: reason }, this.messageTargetOrigin);
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
38
|
* This method is used to cancel the message from inside the worker
|
|
38
39
|
*/
|
|
39
40
|
WorkerMessage.prototype.cancel = function (reason) {
|
|
40
|
-
|
|
41
|
+
self.postMessage({ wasCanceled: true, reason: reason }, this.messageTargetOrigin);
|
|
41
42
|
};
|
|
42
43
|
/**
|
|
43
44
|
* This method is used to report the progress of the message from inside the worker
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./EasyWebWorker"), exports);
|
|
18
|
-
__exportStar(require("./EasyWebWorkerTypes"), exports);
|
|
19
18
|
__exportStar(require("./StaticEasyWebWorker"), exports);
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-web-worker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "This is a library to easily handle and create web-workers, if you are a web developer and never tried this... do not wait any longer! Workers are an amazing option to improve user experience and make your webpages even greater",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"types": "lib/EasyWebWorker.d.ts",
|
|
5
|
+
"main": "lib/index.js",
|
|
7
6
|
"files": [
|
|
8
7
|
"lib"
|
|
9
8
|
],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EasyWebWorker.d.ts","sourceRoot":"","sources":["../src/EasyWebWorker.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAEjB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;;;;KAWK;AAEL,qBAAa,aAAa,CAAC,QAAQ,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI;IAkCtD;;;;;OAKG;IACH,SAAS,CAAC,UAAU,EAChB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACpC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,GACtC,MAAM;IA1CL,IAAI,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACI,MAAM,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,aAAa,CACT;IAEZ;;OAEG;IACI,SAAS,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACI,OAAO,EAAE,MAAM,EAAE,CAAM;IAE9B;;OAEG;IACI,aAAa,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAElD,SAAS,KAAK,oBAAoB,IAAI,OAAO,CAE5C;;IAGC;;;;;OAKG;IACO,UAAU,EAChB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACpC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,GACtC,MAAM;IAEV;;OAEG;IACH,EAAE,OAAY,EAAE,IAAI,EAAE,aAAoB,EAAE,GAAE,OAAO,CAAC,aAAa,CAAM;IAQ3E,OAAO,CAAC,sBAAsB;IAI9B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkD9B,SAAS,CAAC,YAAY,IAAI,MAAM;IAahC,SAAS,CAAC,YAAY,IAAI,MAAM;IAuBhC;;;;OAIG;IACI,SAAS,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAUxC;;;;OAIG;IACI,IAAI,gCAeD,kBAAkB,OAAO,CAAC,aACtB,QAAQ,KAAK,kBAAkB,OAAO,CAAC,CAAC;IAEtD;;;;;OAKG;IACI,QAAQ,oCASD,OAAO,KAAK,kBAAkB,OAAO,CAAC,aACtC,QAAQ,WAAW,OAAO,KAAK,kBAAkB,OAAO,CAAC,CAAC;IAExE;;;;;OAKG;IACI,oBAAoB,oCAkBb,OAAO,KAAK,kBAAkB,OAAO,CAAC,aACtC,QAAQ,WAAW,OAAO,KAAK,kBAAkB,OAAO,CAAC,CAAC;IAExE;;OAEG;IACI,OAAO,IAAI,IAAI;CAOvB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { EasyWebWorkerBody } from './EasyWebWorkerTypes';
|
|
2
|
-
declare class EasyWebWorkerFactory {
|
|
3
|
-
private getImportScriptsTemplate;
|
|
4
|
-
blob(source: string, imports?: string[]): string;
|
|
5
|
-
blobWorker<IPayload = null, IResult = void>(source: EasyWebWorkerBody<IPayload, IResult> | EasyWebWorkerBody<IPayload, IResult>[], imports?: string[]): string;
|
|
6
|
-
}
|
|
7
|
-
export declare const easyWebWorkerFactory: EasyWebWorkerFactory;
|
|
8
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EasyWebWorkerFactory.d.ts","sourceRoot":"","sources":["../src/EasyWebWorkerFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,cAAM,oBAAoB;IACxB,OAAO,CAAC,wBAAwB;IAMzB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO;IAW3C,UAAU,CAAC,QAAQ,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI,EAC/C,MAAM,EACF,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,GACpC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,EAC1C,OAAO,GAAE,MAAM,EAAO;CAyBzB;AAED,eAAO,MAAM,oBAAoB,sBAA6B,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.easyWebWorkerFactory = void 0;
|
|
4
|
-
var EasyWebWorkerFixtures_1 = require("./EasyWebWorkerFixtures");
|
|
5
|
-
var EasyWebWorkerFactory = /** @class */ (function () {
|
|
6
|
-
function EasyWebWorkerFactory() {
|
|
7
|
-
}
|
|
8
|
-
EasyWebWorkerFactory.prototype.getImportScriptsTemplate = function (scripts) {
|
|
9
|
-
if (scripts === void 0) { scripts = []; }
|
|
10
|
-
if (!scripts.length)
|
|
11
|
-
return '';
|
|
12
|
-
return "self.importScripts([\"".concat(scripts.join('","'), "\"]);");
|
|
13
|
-
};
|
|
14
|
-
EasyWebWorkerFactory.prototype.blob = function (source, imports) {
|
|
15
|
-
if (imports === void 0) { imports = []; }
|
|
16
|
-
var content = "".concat(this.getImportScriptsTemplate(imports), "\n ").concat(source);
|
|
17
|
-
return (window.URL || window.webkitURL).createObjectURL(new Blob([content], {
|
|
18
|
-
type: 'application/javascript',
|
|
19
|
-
}));
|
|
20
|
-
};
|
|
21
|
-
EasyWebWorkerFactory.prototype.blobWorker = function (source, imports) {
|
|
22
|
-
if (imports === void 0) { imports = []; }
|
|
23
|
-
var template = (0, EasyWebWorkerFixtures_1.WorkerTemplate)();
|
|
24
|
-
var contentCollection = Array.isArray(source) ? source : [source];
|
|
25
|
-
return (window.URL || window.webkitURL).createObjectURL(new Blob([
|
|
26
|
-
"".concat(this.getImportScriptsTemplate(imports), "\n \n ").concat(template, "\n \n ").concat(contentCollection
|
|
27
|
-
.map(function (content, index) {
|
|
28
|
-
return "// content #".concat(index, "\n(").concat(content.toString(), ")(easyWorker, self);");
|
|
29
|
-
})
|
|
30
|
-
.join('\n\n')),
|
|
31
|
-
], { type: 'application/javascript' }));
|
|
32
|
-
};
|
|
33
|
-
return EasyWebWorkerFactory;
|
|
34
|
-
}());
|
|
35
|
-
exports.easyWebWorkerFactory = new EasyWebWorkerFactory();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EasyWebWorkerFixtures.d.ts","sourceRoot":"","sources":["../src/EasyWebWorkerFixtures.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAO,MACsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,cAAc,cAgC1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EasyWebWorkerMessage.d.ts","sourceRoot":"","sources":["../src/EasyWebWorkerMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAE3B,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAG/B;;GAEG;AACH,qBAAa,oBAAoB,CAAC,QAAQ,GAAG,IAAI,EAAE,OAAO,GAAG,IAAI;IAwD5C,OAAO,EAAE,QAAQ;IAvDpC;;OAEG;IACI,SAAS,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACI,YAAY,UAAS;IAE5B;;OAEG;IACI,WAAW,UAAS;IAE3B;;OAEG;IACI,MAAM,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACI,gBAAgB,EAAE,2BAA2B,CAAC,OAAO,CAAC,CAAC;IAE9D;;OAEG;IACI,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,SAAS,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAE9E;;OAEG;IACI,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAEzC;;OAEG;IACI,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAEzC;;;OAGG;IACI,cAAc,EAAE,mBAAmB,CAIxC;IAEF;;;OAGG;gBACgB,OAAO,EAAE,QAAQ;CAiBrC"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EasyWorker Config
|
|
3
|
-
* */
|
|
4
|
-
export interface IWorkerConfig {
|
|
5
|
-
/**
|
|
6
|
-
** External scripts that you want to include in your worker
|
|
7
|
-
*/
|
|
8
|
-
scripts: string[];
|
|
9
|
-
/**
|
|
10
|
-
** Identifier of your worker, this is in case you want to add a name to your worker file, otherwise an unique generic Id will be added as a name
|
|
11
|
-
*/
|
|
12
|
-
name: string;
|
|
13
|
-
/**
|
|
14
|
-
* Callback that will be executed when the worker fails, this not necessary affect the current message execution
|
|
15
|
-
* */
|
|
16
|
-
onWorkerError: (error: ErrorEvent) => void;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* This is the structure that the messages of the worker will have
|
|
20
|
-
*/
|
|
21
|
-
export interface IMessageData<IPayload = null> {
|
|
22
|
-
/**
|
|
23
|
-
* This are the parameters included in the message
|
|
24
|
-
*/
|
|
25
|
-
payload: IPayload;
|
|
26
|
-
/**
|
|
27
|
-
* The messages from the worker could include errors if something went wrong
|
|
28
|
-
* */
|
|
29
|
-
reason: unknown;
|
|
30
|
-
/**
|
|
31
|
-
* Indicates if the message was canceled
|
|
32
|
-
* */
|
|
33
|
-
wasCanceled: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* The messages from the worker could include a progress percentage
|
|
36
|
-
* */
|
|
37
|
-
progressPercentage?: number;
|
|
38
|
-
/**
|
|
39
|
-
* This is the message id
|
|
40
|
-
* */
|
|
41
|
-
messageId: string;
|
|
42
|
-
}
|
|
43
|
-
export interface IEasyWorkerInstance<IPayload = null, IResult = void> {
|
|
44
|
-
/**
|
|
45
|
-
* Use this method to defined which will be the functionality of your worker when a message is send to it
|
|
46
|
-
* @param {function} callback - This is the callback that will be executed when a message is received
|
|
47
|
-
* @param {IEasyWebWorkerMessage} callback.message - This is the message that was received
|
|
48
|
-
* @param {IEasyWebWorkerMessage} callback.message.messageId - This is the message id
|
|
49
|
-
* @param {IEasyWebWorkerMessage} callback.message.payload - This are the parameters included in the message
|
|
50
|
-
* @param {IEasyWebWorkerMessage} callback.message.reject - This method is used to reject the message from inside the worker
|
|
51
|
-
* @param {IEasyWebWorkerMessage} callback.message.reportProgress - This method is used to report the progress of the message from inside the worker
|
|
52
|
-
* @param {IEasyWebWorkerMessage} callback.message.resolve - This method is used to resolve the message from inside the worker
|
|
53
|
-
* @param {MessageEvent} callback.event - This is the event that was received
|
|
54
|
-
* */
|
|
55
|
-
onMessage(callback: (message: IEasyWebWorkerMessage<IPayload, IResult>, event: MessageEvent<IMessageData<IPayload>>) => void): void;
|
|
56
|
-
}
|
|
57
|
-
export interface IEasyWebWorkerMessage<IPayload = null, IResult = void> {
|
|
58
|
-
/**
|
|
59
|
-
* This is the message id
|
|
60
|
-
*/
|
|
61
|
-
messageId: string;
|
|
62
|
-
/**
|
|
63
|
-
* This are the parameters included in the message
|
|
64
|
-
* */
|
|
65
|
-
payload: IPayload;
|
|
66
|
-
/**
|
|
67
|
-
* This method is used to reject the message from inside the worker
|
|
68
|
-
* */
|
|
69
|
-
reject: (reason?: unknown) => void;
|
|
70
|
-
/**
|
|
71
|
-
* This method is used to report the progress of the message from inside the worker
|
|
72
|
-
* */
|
|
73
|
-
reportProgress(progressPercentage: number): void;
|
|
74
|
-
/**
|
|
75
|
-
* This method is used to resolve the message from inside the worker
|
|
76
|
-
* */
|
|
77
|
-
resolve: (...args: IResult extends void ? [null?] : [IResult]) => void;
|
|
78
|
-
/**
|
|
79
|
-
* This method is used to cancel the message from inside the worker
|
|
80
|
-
* */
|
|
81
|
-
cancel: (reason?: unknown) => void;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* This type defined the structure that a WorkerBody should have.
|
|
85
|
-
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
|
86
|
-
* @template IResult - Indicates if your WORKERS messages has a result... NULL indicates all you messages are Promise<void>
|
|
87
|
-
* @param {IEasyWorkerInstance<IPayload, IResult>} easyWorker - ,
|
|
88
|
-
*/
|
|
89
|
-
export type EasyWebWorkerBody<IPayload = null, IResult = void> = (
|
|
90
|
-
/**
|
|
91
|
-
* This is the instance of the worker that you can use to communicate with the main thread
|
|
92
|
-
*/
|
|
93
|
-
easyWorker: IEasyWorkerInstance<IPayload, IResult>,
|
|
94
|
-
/**
|
|
95
|
-
* This is the context of the worker, you can use it to access to the global scope of the worker
|
|
96
|
-
* */
|
|
97
|
-
context: any) => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EasyWebWorkerTypes.d.ts","sourceRoot":"","sources":["../src/EasyWebWorkerTypes.ts"],"names":[],"mappings":"AAAA;;KAEK;AACL,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;SAEK;IACL,aAAa,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,QAAQ,GAAG,IAAI;IAC3C;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;IAElB;;SAEK;IACL,MAAM,EAAE,OAAO,CAAC;IAEhB;;SAEK;IACL,WAAW,EAAE,OAAO,CAAC;IAErB;;SAEK;IACL,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B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