easy-web-worker 1.0.11 → 1.0.13
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
CHANGED
|
@@ -70,7 +70,7 @@ easyWorker: IEasyWorkerInstance<IPayload, IResult>,
|
|
|
70
70
|
* This is the context of the worker, you can use it to access to the global scope of the worker
|
|
71
71
|
* */
|
|
72
72
|
context: any) => void;
|
|
73
|
-
export interface IEasyWebWorkerMessage<
|
|
73
|
+
export interface IEasyWebWorkerMessage<TPayload = null, TResult = void> {
|
|
74
74
|
/**
|
|
75
75
|
* This is the message id
|
|
76
76
|
*/
|
|
@@ -78,7 +78,7 @@ export interface IEasyWebWorkerMessage<IPayload = null, IResult = void> {
|
|
|
78
78
|
/**
|
|
79
79
|
* This are the parameters included in the message
|
|
80
80
|
* */
|
|
81
|
-
payload:
|
|
81
|
+
payload: TPayload;
|
|
82
82
|
/**
|
|
83
83
|
* This method is used to reject the message from inside the worker
|
|
84
84
|
* */
|
|
@@ -90,12 +90,14 @@ export interface IEasyWebWorkerMessage<IPayload = null, IResult = void> {
|
|
|
90
90
|
/**
|
|
91
91
|
* This method is used to resolve the message from inside the worker
|
|
92
92
|
* */
|
|
93
|
-
resolve:
|
|
93
|
+
resolve: TResult extends void ? () => void : (payload: TResult) => void;
|
|
94
94
|
/**
|
|
95
95
|
* This method is used to cancel the message from inside the worker
|
|
96
96
|
* */
|
|
97
97
|
cancel: (reason?: unknown) => void;
|
|
98
98
|
}
|
|
99
|
+
export declare const createBlobFromString: (source: string, imports?: string[]) => string;
|
|
100
|
+
export declare const createBlobWorker: <IPayload = null, IResult = void>(source: EasyWebWorkerBody<IPayload, IResult> | EasyWebWorkerBody<IPayload, IResult>[], imports?: string[]) => string;
|
|
99
101
|
/**
|
|
100
102
|
* This is a class to create global-store objects
|
|
101
103
|
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
package/lib/EasyWebWorker.js
CHANGED
|
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.EasyWebWorker = void 0;
|
|
28
|
+
exports.EasyWebWorker = exports.createBlobWorker = exports.createBlobFromString = void 0;
|
|
29
29
|
var EasyWebWorkerMessage_1 = require("./EasyWebWorkerMessage");
|
|
30
30
|
var EasyWebWorkerFixtures_1 = require("./EasyWebWorkerFixtures");
|
|
31
31
|
var getImportScriptsTemplate = function (scripts) {
|
|
@@ -34,14 +34,15 @@ var getImportScriptsTemplate = function (scripts) {
|
|
|
34
34
|
return '';
|
|
35
35
|
return "self.importScripts([\"".concat(scripts.join('","'), "\"]);");
|
|
36
36
|
};
|
|
37
|
-
var
|
|
37
|
+
var createBlobFromString = function (source, imports) {
|
|
38
38
|
if (imports === void 0) { imports = []; }
|
|
39
39
|
var content = "".concat(getImportScriptsTemplate(imports), "\n ").concat(source);
|
|
40
40
|
return (window.URL || window.webkitURL).createObjectURL(new Blob([content], {
|
|
41
41
|
type: 'application/javascript',
|
|
42
42
|
}));
|
|
43
43
|
};
|
|
44
|
-
|
|
44
|
+
exports.createBlobFromString = createBlobFromString;
|
|
45
|
+
var createBlobWorker = function (source, imports) {
|
|
45
46
|
if (imports === void 0) { imports = []; }
|
|
46
47
|
var template = (0, EasyWebWorkerFixtures_1.WorkerTemplate)();
|
|
47
48
|
var contentCollection = Array.isArray(source) ? source : [source];
|
|
@@ -53,6 +54,7 @@ var blobWorker = function (source, imports) {
|
|
|
53
54
|
.join('\n\n')),
|
|
54
55
|
], { type: 'application/javascript' }));
|
|
55
56
|
};
|
|
57
|
+
exports.createBlobWorker = createBlobWorker;
|
|
56
58
|
/**
|
|
57
59
|
* This is a class to create global-store objects
|
|
58
60
|
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
|
@@ -203,7 +205,7 @@ var EasyWebWorker = /** @class */ (function () {
|
|
|
203
205
|
if (this.isExternalWorkerFile) {
|
|
204
206
|
return this.workerBody;
|
|
205
207
|
}
|
|
206
|
-
return
|
|
208
|
+
return (0, exports.createBlobWorker)(this.workerBody, this.scripts);
|
|
207
209
|
};
|
|
208
210
|
EasyWebWorker.prototype.createWorker = function () {
|
|
209
211
|
var _this = this;
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { CancelablePromise } from 'cancelable-promise-jq';
|
|
2
1
|
import { IEasyWebWorkerMessage, IEasyWorkerInstance, IMessageData } from './EasyWebWorker';
|
|
3
2
|
/**
|
|
4
3
|
* This message wrap the interaction with the worker to ensure that the message is correctly synchronized with the EasyWebWorker
|
|
5
4
|
*/
|
|
6
|
-
export declare class WorkerMessage<
|
|
7
|
-
payload:
|
|
5
|
+
export declare class WorkerMessage<TPayload = null, TResult = void> implements IEasyWebWorkerMessage<TPayload, TResult> {
|
|
6
|
+
payload: TPayload;
|
|
8
7
|
messageId: string;
|
|
9
8
|
protected messageTargetOrigin: string;
|
|
10
9
|
/**
|
|
11
|
-
* @param {
|
|
10
|
+
* @param {TPayload} payload - This are the parameters included in the message
|
|
12
11
|
* @param {string} messageId - This is the message id
|
|
13
12
|
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
14
13
|
*/
|
|
15
|
-
constructor(payload:
|
|
14
|
+
constructor(payload: TPayload, messageId: string, messageTargetOrigin?: string);
|
|
16
15
|
/**
|
|
17
16
|
* This method is used to resolve the message from inside the worker
|
|
18
17
|
*/
|
|
19
|
-
resolve:
|
|
18
|
+
resolve: TResult extends void ? () => void : (payload: TResult) => void;
|
|
20
19
|
/**
|
|
21
20
|
* This method is used to reject the message from inside the worker
|
|
22
21
|
* */
|
|
@@ -42,9 +41,9 @@ export declare class WorkerMessage<IPayload = null, IResult = void> implements I
|
|
|
42
41
|
* @param {MessageEvent} onMessageCallback.event - This is the event that was received
|
|
43
42
|
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
44
43
|
*/
|
|
45
|
-
export declare class StaticEasyWebWorker<
|
|
46
|
-
onMessageCallback: (message: IEasyWebWorkerMessage<
|
|
47
|
-
constructor(onMessageCallback: (message: IEasyWebWorkerMessage<
|
|
44
|
+
export declare class StaticEasyWebWorker<TPayload = null, TResult = void> implements IEasyWorkerInstance<TPayload, TResult> {
|
|
45
|
+
onMessageCallback: (message: IEasyWebWorkerMessage<TPayload, TResult>, event: MessageEvent<IMessageData<TPayload>>) => void;
|
|
46
|
+
constructor(onMessageCallback: (message: IEasyWebWorkerMessage<TPayload, TResult>, event: MessageEvent<IMessageData<TPayload>>) => void, messageTargetOrigin?: string);
|
|
48
47
|
/**
|
|
49
48
|
* This method is used to define the onMessage callback
|
|
50
49
|
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
@@ -61,5 +60,5 @@ export declare class StaticEasyWebWorker<IPayload = null, IResult = void> implem
|
|
|
61
60
|
* @param {IEasyWebWorkerMessage} callback.message.resolve - This method is used to resolve the message from inside the worker
|
|
62
61
|
* @param {MessageEvent} callback.event - This is the event that was received
|
|
63
62
|
*/
|
|
64
|
-
onMessage(callback: (message: IEasyWebWorkerMessage<
|
|
63
|
+
onMessage(callback: (message: IEasyWebWorkerMessage<TPayload, TResult>, event: MessageEvent<IMessageData<TPayload>>) => void): void;
|
|
65
64
|
}
|
|
@@ -6,7 +6,7 @@ exports.StaticEasyWebWorker = exports.WorkerMessage = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
var WorkerMessage = /** @class */ (function () {
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {TPayload} payload - This are the parameters included in the message
|
|
10
10
|
* @param {string} messageId - This is the message id
|
|
11
11
|
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
12
12
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-web-worker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
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
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|