-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.html
75 lines (74 loc) · 1.9 KB
/
spec.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<head>
<title>spec.html</title>
</head>
<body>
<script src="bower_components/bluebird/js/browser/bluebird.js"></script>
<script src="storage.js"></script>
<script>
function next(callback) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(callback());
}, 1);
});
}
var data = {
person: {
age: 42,
happy: true,
name: {
first: 'John',
middle: 'X',
last: 'Doe'
}
},
'null': null
};
for ( var key in data ) {
data[key] = JSON.stringify(data[key]);
}
var storage = new Storage({
get: function(key) {
return next(function() {
return data[key];
});
//return Promise.resolve(data[key]);
},
all: function() {
return next(function() {
return data;
});
},
set: function(key, value) {
return next(function() {
console.log(data, key, value);
return data[key] = value;
});
},
remove: function(key) {
return next(function() {
delete data[key];
});
},
clear: function(key) {
return next(function() {
data = {};
});
},
decode: JSON.parse,
encode: JSON.stringify
});
storage.set(['an','array','key'], 'success').then(function() {
storage.get('an.array.key').then(function(value) {
console.log(value, 'success');
});
});
storage.set(['an','array','key'], 'success').then(function() {
storage.get('an.array.key').then(function(value) {
console.log(value, 'success');
});
});
</script>
</body>
</html>