forked from pouchdb/pouchdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
40 lines (38 loc) · 827 Bytes
/
worker.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
/* jshint worker: true */
'use strict';
function bigTest(name) {
new PouchDB(name, function (err, db) {
if (err) {
throw err;
}
db.post({
_id: 'blablah',
key: 'lala'
}, function (err) {
if (err) {
throw err;
}
db.get('blablah', function (err, doc) {
if (err) {
throw err;
}
self.postMessage(doc.key);
PouchDB.destroy(name);
});
});
});
}
self.addEventListener('message', function (e) {
if (typeof e.data === 'string' && e.data.indexOf('/dist/') > -1) {
importScripts(e.data);
}
if (e.data === 'ping') {
self.postMessage('pong');
}
if (e.data === 'version') {
self.postMessage(PouchDB.version);
}
if (Array.isArray(e.data) && e.data[0] === 'create') {
bigTest(e.data[1]);
}
});