-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.js
More file actions
38 lines (30 loc) · 702 Bytes
/
service.js
File metadata and controls
38 lines (30 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"use strict";
exports.__esModule = true;
/**
* initial Service in WebWorker
* @returns {instance} instance Service
*/
exports.default = function Service() {
const subscribes = {};
self.onmessage = event => {
const request = JSON.parse(event.data);
const response = data => self.postMessage({
id: request.id,
data: data
});
/**
* on('name',(data, response)=>{})
*/
const process = subscribes[request.name];
process(request.data, response);
};
/**
* initial listener
* @param {string} name
* @param {function} process
* @returns {undefined} nothing
*/
this.on = (name, process) => {
subscribes[name] = process;
};
};