UNPKG

2.07 kBHTMLView Raw
1<!doctype html>
2<html>
3 <head>
4 <meta charset="utf8" />
5 <title>LocalForage dropInstance example</title>
6 </head>
7 <body>
8 <script src="../dist/localforage.js"></script>
9 <script>
10 var driverOrder = [
11 localforage.INDEXEDDB,
12 localforage.WEBSQL,
13 localforage.LOCALSTORAGE,
14 ];
15 localforage.setDriver(driverOrder).then(function() {
16 console.log(localforage.driver());
17 var key = 'STORE_KEY';
18 var value = new Uint8Array(8);
19 value[0] = 65
20 var UNKNOWN_KEY = 'unknown_key';
21
22 return Promise.resolve().then(function() {
23 return localforage.setItem(key, value);
24 }).then(function() {
25 console.log('Saved: ' + value);
26 }).then(function() {
27 return Promise.all([
28 localforage.getItem(key).then(function(readValue) {
29 console.log('Read: ', readValue);
30 }),
31
32 // Since this key hasn't been set yet, we'll get a null value
33 localforage.getItem(UNKNOWN_KEY).then(function(readValue) {
34 console.log('Result of reading ' + UNKNOWN_KEY, readValue);
35 })
36 ]);
37 }).then(function() {
38 return localforage.dropInstance();
39 }).then(function(result) {
40 console.log('dropped', localforage.config().name, localforage.config().storeName);
41 }).then(function() {
42 return localforage.getItem(key);
43 }).then(function(value) {
44 console.log('getItem after delete', value);
45 }).then(function() {
46 var newValue = Date.now();
47 console.log('setItem', newValue);
48 return localforage.setItem(key, newValue);
49 }).then(function() {
50 console.log('setItem resolved');
51 return localforage.getItem(key);
52 }).then(function(value) {
53 console.log('getItem', value);
54 console.log('*** DONE ***');
55 }).catch(function(error) {
56 console.log('err', error);
57 });
58 });
59 </script>
60 </body>
61</html>