forked from shexSpec/spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiDemoStreamingWorker.js
44 lines (35 loc) · 1.26 KB
/
apiDemoStreamingWorker.js
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
39
40
41
42
43
importScripts('Util.js');
importScripts('Validator.js');
var fixedMap = null, validator = null;
onmessage = function (msg) {
switch (msg.data.request) {
case "create":
fixedMap = msg.data.fixedMap;
validator = Validator.create(msg.data.fixedMap);
postMessage({ response: "created" });
break;
case "validate":
var currentEntry = 0, options = msg.data.options || {};
var results = Util.createResults();
for (var currentEntry = 0; currentEntry < fixedMap.length; ) {
var queryMap = [fixedMap[currentEntry++]]; // ShapeMap with single entry.
var newResults = validator.validate(queryMap, results.getShapeMap());
// Merge into results.
results.merge(newResults);
// Notify caller.
postMessage({ response: "update", results: newResults });
// Skip entries that were already processed.
while (currentEntry < fixedMap.length &&
results.has(fixedMap[currentEntry]))
++currentEntry;
}
// Done -- show results and restore interface.
if (options.includeDoneResults)
postMessage({ response: "done", results: results.getShapeMap() });
else
postMessage({ response: "done" });
break;
default:
throw "unknown request: " + JSON.stringify(msg.data);
}
}