forked from localForage/localForage-getItems
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
55 lines (48 loc) · 1.46 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
requirejs.config({
paths: {
localforage: '../node_modules/localforage/dist/localforage'
}
});
define([
'localforage',
'../dist/localforage-getitems'
], function(localforage, getItems) {
var driverTestOrder = [
localforage.WEBSQL,
localforage.INDEXEDDB,
localforage.LOCALSTORAGE
];
localforage.setDriver(driverTestOrder).then(function() {
console.log(localforage.driver());
var keyValuePairs = [
{ key: 'user-1-todo-1', value: '11aa1111bbcc' },
{ key: 'user-1-todo-2', value: '22aa2222bbcc' },
{ key: 'user-1-todo-3', value: '33aa3333bbcc' },
{ key: 'user-1-todo-4', value: '44aa4444bbcc' },
{ key: 'user-2-todo-1', value: 'bb11ccaa1111' },
{ key: 'user-2-todo-2', value: 'bb22ccaa2222' },
{ key: 'user-2-todo-3', value: 'bb33ccaa3333' },
{ key: 'user-2-todo-4', value: 'bb44ccaa4444' }
];
var promises = keyValuePairs.map(function(x) {
return localforage.setItem(x.key, x.value);
});
return Promise.all(promises);
}).then(function(){
return localforage.keys();
}).then(function(keys){
console.log(keys);
var itemKeys = [
'user-1-todo-4',
'user-1-todo-3',
'user-2-todo-2',
'user-2-todo-1'
];
var t0 = performance.now();
localforage.getItems(itemKeys).then(function(results){
console.log(results);
var t1 = performance.now();
console.log("Completed after " + (t1 - t0) + " milliseconds.");
});
});
});