easy-web-worker 1.1.1 → 1.1.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/package.json +1 -1
- package/lib/EasyWebWorker.js +0 -252
- package/lib/EasyWebWorkerFixtures.js +0 -12
- package/lib/EasyWebWorkerMessage.js +0 -44
- package/lib/StaticEasyWebWorker.js +0 -100
- package/lib/bundle.js.LICENSE.txt +0 -1
- package/lib/index.js +0 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-web-worker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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
|
"types": "lib/index.d.ts",
|
package/lib/EasyWebWorker.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.EasyWebWorker = exports.createBlobWorker = exports.createBlobFromString = void 0;
|
|
29
|
-
var EasyWebWorkerMessage_1 = require("./EasyWebWorkerMessage");
|
|
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 createBlobFromString = 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
|
-
exports.createBlobFromString = createBlobFromString;
|
|
45
|
-
var createBlobWorker = function (source, imports) {
|
|
46
|
-
if (imports === void 0) { imports = []; }
|
|
47
|
-
var template = (0, EasyWebWorkerFixtures_1.WorkerTemplate)();
|
|
48
|
-
var contentCollection = Array.isArray(source) ? source : [source];
|
|
49
|
-
return (window.URL || window.webkitURL).createObjectURL(new Blob([
|
|
50
|
-
"".concat(getImportScriptsTemplate(imports), "\n \n ").concat(template, "\n \n ").concat(contentCollection
|
|
51
|
-
.map(function (content, index) {
|
|
52
|
-
return "// content #".concat(index, "\n(").concat(content.toString(), ")(easyWorker, self);");
|
|
53
|
-
})
|
|
54
|
-
.join('\n\n')),
|
|
55
|
-
], { type: 'application/javascript' }));
|
|
56
|
-
};
|
|
57
|
-
exports.createBlobWorker = createBlobWorker;
|
|
58
|
-
/**
|
|
59
|
-
* This is a class to create global-store objects
|
|
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 {EasyWebWorkerBody<IPayload, IResult> | EasyWebWorkerBody<IPayload, IResult>[]} workerBody -
|
|
63
|
-
* this parameter should be a function or set of functions that will become the body of your Web-Worker
|
|
64
|
-
* IMPORTANT!! all WORKERS content is gonna be transpiled on run time, so you can not use any variable, method of resource that weren't included into the WORKER.
|
|
65
|
-
* the above the reason of why we are injecting all worker context into the MessageBody Callbacks, so,
|
|
66
|
-
* you could easily identify what is on the context of your Worker.
|
|
67
|
-
* @param {Partial<IWorkerConfig>} WorkerConfig - You could add extra configuration to your worker,
|
|
68
|
-
* consult IWorkerConfig description to have more information
|
|
69
|
-
* */
|
|
70
|
-
var EasyWebWorker = /** @class */ (function () {
|
|
71
|
-
function EasyWebWorker(
|
|
72
|
-
/**
|
|
73
|
-
* this parameter should be a function or set of functions that will become the body of your Web-Worker
|
|
74
|
-
* IMPORTANT!! all WORKERS content is gonna be transpiled on run time, so you can not use any variable, method of resource that weren't included into the WORKER.
|
|
75
|
-
* the above the reason of why we are injecting all worker context into the MessageBody Callbacks, so,
|
|
76
|
-
* you could easily identify what is on the context of your Worker.
|
|
77
|
-
*/
|
|
78
|
-
workerBody,
|
|
79
|
-
/**
|
|
80
|
-
* You could import scripts into your worker, this is useful if you want to use external libraries
|
|
81
|
-
*/
|
|
82
|
-
_a) {
|
|
83
|
-
var
|
|
84
|
-
/**
|
|
85
|
-
* You could import scripts into your worker, this is useful if you want to use external libraries
|
|
86
|
-
*/
|
|
87
|
-
_b = _a === void 0 ? {} : _a, _c = _b.scripts, scripts = _c === void 0 ? [] : _c, name = _b.name, _d = _b.onWorkerError, onWorkerError = _d === void 0 ? null : _d;
|
|
88
|
-
var _this = this;
|
|
89
|
-
this.workerBody = workerBody;
|
|
90
|
-
/**
|
|
91
|
-
* These where send to the worker but not yet resolved
|
|
92
|
-
*/
|
|
93
|
-
this.messagesQueue = new Map();
|
|
94
|
-
/**
|
|
95
|
-
* This is the list of scripts that will be imported into the worker
|
|
96
|
-
*/
|
|
97
|
-
this.scripts = [];
|
|
98
|
-
/**
|
|
99
|
-
* Send a message to the worker queue
|
|
100
|
-
* @param {IPayload} payload - whatever json data you want to send to the worker
|
|
101
|
-
* @returns {IMessagePromise<IResult>} generated defer that will be resolved when the message completed
|
|
102
|
-
*/
|
|
103
|
-
this.send = (function () {
|
|
104
|
-
var _a;
|
|
105
|
-
var payload = [];
|
|
106
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
107
|
-
payload[_i] = arguments[_i];
|
|
108
|
-
}
|
|
109
|
-
var _b = __read(payload, 1), $payload = _b[0];
|
|
110
|
-
var message = new EasyWebWorkerMessage_1.EasyWebWorkerMessage($payload);
|
|
111
|
-
var messageId = message.messageId;
|
|
112
|
-
_this.messagesQueue.set(message.messageId, message);
|
|
113
|
-
(_a = _this.worker) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
114
|
-
messageId: messageId,
|
|
115
|
-
payload: $payload,
|
|
116
|
-
});
|
|
117
|
-
return message.decoupledPromise.promise;
|
|
118
|
-
});
|
|
119
|
-
/**
|
|
120
|
-
* This method terminate all current messages and send a new one to the worker queue
|
|
121
|
-
* @param {IPayload} payload - whatever json data you want to send to the worker, should be serializable
|
|
122
|
-
* @param {unknown} reason - reason why the worker was terminated
|
|
123
|
-
* @returns {IMessagePromise<IResult>} generated defer that will be resolved when the message completed
|
|
124
|
-
*/
|
|
125
|
-
this.override = (function () {
|
|
126
|
-
var _a = [];
|
|
127
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
128
|
-
_a[_i] = arguments[_i];
|
|
129
|
-
}
|
|
130
|
-
var _b = __read(_a, 2), payload = _b[0], reason = _b[1];
|
|
131
|
-
_this.cancelAll(reason);
|
|
132
|
-
return _this.send.apply(_this, __spreadArray([], __read([payload]), false));
|
|
133
|
-
});
|
|
134
|
-
/**
|
|
135
|
-
* This method will alow the current message to be completed and send a new one to the worker queue after it, all the messages after the current one will be canceled
|
|
136
|
-
* @param {IPayload} payload - whatever json data you want to send to the worker should be serializable
|
|
137
|
-
* @param {unknown} reason - reason why the worker was terminated
|
|
138
|
-
* @returns {IMessagePromise<IResult>} generated defer that will be resolved when the message completed
|
|
139
|
-
*/
|
|
140
|
-
this.overrideAfterCurrent = (function () {
|
|
141
|
-
var _a = [];
|
|
142
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
143
|
-
_a[_i] = arguments[_i];
|
|
144
|
-
}
|
|
145
|
-
var _b = __read(_a, 2), payload = _b[0], reason = _b[1];
|
|
146
|
-
if (_this.messagesQueue.size) {
|
|
147
|
-
var _c = __read(_this.messagesQueue, 1), firstItem = _c[0];
|
|
148
|
-
var _d = __read(firstItem, 2), currentMessage = _d[1];
|
|
149
|
-
_this.messagesQueue.delete(currentMessage.messageId);
|
|
150
|
-
_this.cancelAll(reason);
|
|
151
|
-
_this.messagesQueue.set(currentMessage.messageId, currentMessage);
|
|
152
|
-
}
|
|
153
|
-
return _this.send.apply(_this, __spreadArray([], __read([payload]), false));
|
|
154
|
-
});
|
|
155
|
-
this.name = name || (0, EasyWebWorkerFixtures_1.generatedId)();
|
|
156
|
-
this.scripts = scripts;
|
|
157
|
-
this.worker = this.createWorker();
|
|
158
|
-
this.onWorkerError = onWorkerError;
|
|
159
|
-
}
|
|
160
|
-
Object.defineProperty(EasyWebWorker.prototype, "isExternalWorkerFile", {
|
|
161
|
-
get: function () {
|
|
162
|
-
return typeof this.workerBody === 'string';
|
|
163
|
-
},
|
|
164
|
-
enumerable: false,
|
|
165
|
-
configurable: true
|
|
166
|
-
});
|
|
167
|
-
EasyWebWorker.prototype.RemoveMessageFromQueue = function (messageId) {
|
|
168
|
-
this.messagesQueue.delete(messageId);
|
|
169
|
-
};
|
|
170
|
-
/**
|
|
171
|
-
* Categorizes the worker response and executes the corresponding callback
|
|
172
|
-
*/
|
|
173
|
-
EasyWebWorker.prototype.executeMessageCallback = function (event) {
|
|
174
|
-
var _a;
|
|
175
|
-
var message = (_a = this.messagesQueue.get(event.data.messageId)) !== null && _a !== void 0 ? _a : null;
|
|
176
|
-
if (!message)
|
|
177
|
-
return;
|
|
178
|
-
var _b = event.data, payload = _b.payload, reason = _b.reason, wasCanceled = _b.wasCanceled, progressPercentage = _b.progressPercentage;
|
|
179
|
-
// worker was disposed before the message was resolved
|
|
180
|
-
if (!this.worker) {
|
|
181
|
-
this.RemoveMessageFromQueue(message.messageId);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
// execute progress callback
|
|
185
|
-
if (progressPercentage !== undefined) {
|
|
186
|
-
message.reportProgress(progressPercentage);
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
// remove message from queue
|
|
190
|
-
this.RemoveMessageFromQueue(message.messageId);
|
|
191
|
-
message.wasCompleted = false;
|
|
192
|
-
if (wasCanceled) {
|
|
193
|
-
message.cancel(reason);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
if (reason) {
|
|
197
|
-
message.reject(reason);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
message.wasCompleted = true;
|
|
201
|
-
// resolve message with the serialized payload
|
|
202
|
-
message.resolve.apply(message, __spreadArray([], __read((payload !== null && payload !== void 0 ? payload : [])), false));
|
|
203
|
-
};
|
|
204
|
-
EasyWebWorker.prototype.getWorkerUrl = function () {
|
|
205
|
-
if (this.isExternalWorkerFile) {
|
|
206
|
-
return this.workerBody;
|
|
207
|
-
}
|
|
208
|
-
return (0, exports.createBlobWorker)(this.workerBody, this.scripts);
|
|
209
|
-
};
|
|
210
|
-
EasyWebWorker.prototype.createWorker = function () {
|
|
211
|
-
var _this = this;
|
|
212
|
-
this.workerUrl = this.getWorkerUrl();
|
|
213
|
-
var worker = new Worker(this.workerUrl, {
|
|
214
|
-
name: this.name,
|
|
215
|
-
});
|
|
216
|
-
worker.onmessage = function (event) {
|
|
217
|
-
_this.executeMessageCallback(event);
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* If not handled, the error will be thrown to the global scope
|
|
221
|
-
*/
|
|
222
|
-
worker.onerror = function (reason) {
|
|
223
|
-
if (!_this.onWorkerError)
|
|
224
|
-
throw reason;
|
|
225
|
-
_this.onWorkerError(reason);
|
|
226
|
-
};
|
|
227
|
-
return worker;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Terminates the worker and remove all messages from the queue
|
|
231
|
-
* Execute the cancel callback of each message in the queue if provided
|
|
232
|
-
* @param {unknown} reason - reason why the worker was terminated
|
|
233
|
-
*/
|
|
234
|
-
EasyWebWorker.prototype.cancelAll = function (reason) {
|
|
235
|
-
var _a;
|
|
236
|
-
(_a = this.worker) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
237
|
-
var messages = Array.from(this.messagesQueue.values());
|
|
238
|
-
messages.forEach(function (message) { return message.cancel(reason); });
|
|
239
|
-
this.messagesQueue = new Map();
|
|
240
|
-
};
|
|
241
|
-
/**
|
|
242
|
-
* This method will remove the WebWorker and the BlobUrl
|
|
243
|
-
*/
|
|
244
|
-
EasyWebWorker.prototype.dispose = function () {
|
|
245
|
-
this.cancelAll();
|
|
246
|
-
URL.revokeObjectURL(this.workerUrl);
|
|
247
|
-
this.worker = null;
|
|
248
|
-
};
|
|
249
|
-
return EasyWebWorker;
|
|
250
|
-
}());
|
|
251
|
-
exports.EasyWebWorker = EasyWebWorker;
|
|
252
|
-
exports.default = EasyWebWorker;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WorkerTemplate = exports.generatedId = void 0;
|
|
4
|
-
var generatedId = function () {
|
|
5
|
-
return "".concat(new Date().getTime()).concat(Math.random().toString(36).substr(2, 9));
|
|
6
|
-
};
|
|
7
|
-
exports.generatedId = generatedId;
|
|
8
|
-
/**
|
|
9
|
-
* This is the template of the worker, should be and string to avoid compilation issues
|
|
10
|
-
*/
|
|
11
|
-
var WorkerTemplate = function () { return "\n //this-code-was auto-generated\n const easyWorker = new (class {\n onMessageCallback = () => {\n throw \"you didn't defined a message-callback, please assign a callback by calling IEasyWorkerInstance.onMessage\";\n };\n\n onMessage = (callback) => {\n this.onMessageCallback = callback;\n };\n })();\n\n self.onmessage = (event) => {\n const { messageId, payload } = event.data;\n\n // each message should have his own resolution methods\n const message = new (class {\n payload = payload;\n\n messageId = messageId;\n\n resolve = (...result) => self.postMessage({ messageId, payload: result });\n\n reject = (reason) => self.postMessage({ messageId, reason });\n\n cancel = (reason) => self.postMessage({ messageId, reason, wasCanceled: true });\n\n reportProgress = (progressPercentage) => self.postMessage({ messageId, progressPercentage });\n })();\n\n easyWorker.onMessageCallback(message, event);\n };\n"; };
|
|
12
|
-
exports.WorkerTemplate = WorkerTemplate;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EasyWebWorkerMessage = void 0;
|
|
4
|
-
var cancelable_promise_jq_1 = require("cancelable-promise-jq");
|
|
5
|
-
var EasyWebWorkerFixtures_1 = require("./EasyWebWorkerFixtures");
|
|
6
|
-
/**
|
|
7
|
-
* This class represents a message that will be send to a worker
|
|
8
|
-
*/
|
|
9
|
-
var EasyWebWorkerMessage = /** @class */ (function () {
|
|
10
|
-
/**
|
|
11
|
-
* This is the constructor of the class
|
|
12
|
-
* @param {TPayload} payload - This are the parameters included in the message
|
|
13
|
-
*/
|
|
14
|
-
function EasyWebWorkerMessage(payload) {
|
|
15
|
-
var _this = this;
|
|
16
|
-
this.payload = payload;
|
|
17
|
-
/**
|
|
18
|
-
* This flag will be true when the message was completed
|
|
19
|
-
*/
|
|
20
|
-
this.wasCompleted = false;
|
|
21
|
-
/**
|
|
22
|
-
* This flag will be true when the message was canceled
|
|
23
|
-
*/
|
|
24
|
-
this.wasCanceled = false;
|
|
25
|
-
/**
|
|
26
|
-
* This method will report the progress of the message
|
|
27
|
-
* @param {number} progressPercentage - This is the progress percentage
|
|
28
|
-
*/
|
|
29
|
-
this.reportProgress = function () {
|
|
30
|
-
throw new Error('Message should receive a progress-callback in order to be able to report... send(..).onProgressCallback');
|
|
31
|
-
};
|
|
32
|
-
this.messageId = (0, EasyWebWorkerFixtures_1.generatedId)();
|
|
33
|
-
this.decoupledPromise = (0, cancelable_promise_jq_1.createDecoupledPromise)();
|
|
34
|
-
this.resolve = this.decoupledPromise.resolve;
|
|
35
|
-
this.reject = this.decoupledPromise.reject;
|
|
36
|
-
this.cancel = this.decoupledPromise.cancel;
|
|
37
|
-
this.reportProgress = this.decoupledPromise.promise.reportProgress;
|
|
38
|
-
this.decoupledPromise.onCancel(function () {
|
|
39
|
-
_this.wasCanceled = true;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return EasyWebWorkerMessage;
|
|
43
|
-
}());
|
|
44
|
-
exports.EasyWebWorkerMessage = EasyWebWorkerMessage;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StaticEasyWebWorker = exports.WorkerMessage = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* This message wrap the interaction with the worker to ensure that the message is correctly synchronized with the EasyWebWorker
|
|
6
|
-
*/
|
|
7
|
-
var WorkerMessage = /** @class */ (function () {
|
|
8
|
-
/**
|
|
9
|
-
* @param {TPayload} payload - This are the parameters included in the message
|
|
10
|
-
* @param {string} messageId - This is the message id
|
|
11
|
-
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
12
|
-
*/
|
|
13
|
-
function WorkerMessage(payload, messageId, messageTargetOrigin) {
|
|
14
|
-
if (messageTargetOrigin === void 0) { messageTargetOrigin = '*'; }
|
|
15
|
-
var _this = this;
|
|
16
|
-
this.payload = payload;
|
|
17
|
-
this.messageId = messageId;
|
|
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
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* This method is used to reject the message from inside the worker
|
|
33
|
-
* */
|
|
34
|
-
WorkerMessage.prototype.reject = function (reason) {
|
|
35
|
-
self.postMessage({ reason: reason }, this.messageTargetOrigin);
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* This method is used to cancel the message from inside the worker
|
|
39
|
-
*/
|
|
40
|
-
WorkerMessage.prototype.cancel = function (reason) {
|
|
41
|
-
self.postMessage({ wasCanceled: true, reason: reason }, this.messageTargetOrigin);
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* This method is used to report the progress of the message from inside the worker
|
|
45
|
-
* */
|
|
46
|
-
WorkerMessage.prototype.reportProgress = function (progressPercentage) {
|
|
47
|
-
var messageId = this.messageId;
|
|
48
|
-
self.postMessage({ messageId: messageId, progressPercentage: progressPercentage }, this.messageTargetOrigin);
|
|
49
|
-
};
|
|
50
|
-
return WorkerMessage;
|
|
51
|
-
}());
|
|
52
|
-
exports.WorkerMessage = WorkerMessage;
|
|
53
|
-
/**
|
|
54
|
-
* This class is used to create a static worker
|
|
55
|
-
* @param {function} onMessageCallback - This is the callback that will be executed when a message is received
|
|
56
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message - This is the message that was received
|
|
57
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message.messageId - This is the message id
|
|
58
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message.payload - This are the parameters included in the message
|
|
59
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message.reject - This method is used to reject the message from inside the worker
|
|
60
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message.reportProgress - This method is used to report the progress of the message from inside the worker
|
|
61
|
-
* @param {IEasyWebWorkerMessage} onMessageCallback.message.resolve - This method is used to resolve the message from inside the worker
|
|
62
|
-
* @param {MessageEvent} onMessageCallback.event - This is the event that was received
|
|
63
|
-
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
64
|
-
*/
|
|
65
|
-
var StaticEasyWebWorker = /** @class */ (function () {
|
|
66
|
-
function StaticEasyWebWorker(onMessageCallback, messageTargetOrigin) {
|
|
67
|
-
if (messageTargetOrigin === void 0) { messageTargetOrigin = '*'; }
|
|
68
|
-
this.onMessageCallback = onMessageCallback;
|
|
69
|
-
this.defineOnMessage(messageTargetOrigin);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* This method is used to define the onMessage callback
|
|
73
|
-
* @param {string} messageTargetOrigin - This is the target origin of the message
|
|
74
|
-
* */
|
|
75
|
-
StaticEasyWebWorker.prototype.defineOnMessage = function (messageTargetOrigin) {
|
|
76
|
-
var _this = this;
|
|
77
|
-
self.onmessage = function (event) {
|
|
78
|
-
var _a = event.data, messageId = _a.messageId, payload = _a.payload;
|
|
79
|
-
// each message should have his own resolution methods
|
|
80
|
-
var message = new WorkerMessage(payload, messageId, messageTargetOrigin);
|
|
81
|
-
_this.onMessageCallback.call(_this, message, event);
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* This method is used to define the onMessage callback
|
|
86
|
-
* @param {function} callback - This is the callback that will be executed when a message is received
|
|
87
|
-
* @param {IEasyWebWorkerMessage} callback.message - This is the message that was received
|
|
88
|
-
* @param {IEasyWebWorkerMessage} callback.message.messageId - This is the message id
|
|
89
|
-
* @param {IEasyWebWorkerMessage} callback.message.payload - This are the parameters included in the message
|
|
90
|
-
* @param {IEasyWebWorkerMessage} callback.message.reject - This method is used to reject the message from inside the worker
|
|
91
|
-
* @param {IEasyWebWorkerMessage} callback.message.reportProgress - This method is used to report the progress of the message from inside the worker
|
|
92
|
-
* @param {IEasyWebWorkerMessage} callback.message.resolve - This method is used to resolve the message from inside the worker
|
|
93
|
-
* @param {MessageEvent} callback.event - This is the event that was received
|
|
94
|
-
*/
|
|
95
|
-
StaticEasyWebWorker.prototype.onMessage = function (callback) {
|
|
96
|
-
this.onMessageCallback = callback;
|
|
97
|
-
};
|
|
98
|
-
return StaticEasyWebWorker;
|
|
99
|
-
}());
|
|
100
|
-
exports.StaticEasyWebWorker = StaticEasyWebWorker;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! For license information please see bundle.js.LICENSE.txt */
|
package/lib/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./EasyWebWorker"), exports);
|
|
18
|
-
__exportStar(require("./StaticEasyWebWorker"), exports);
|