index.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf8" />
  5. <title>Simple localForage-setItems example</title>
  6. </head>
  7. <body>
  8. <script src="../node_modules/localforage/dist/localforage.js"></script>
  9. <script src="../dist/localforage-setitems.js"></script>
  10. <script>
  11. var driverTestOrder = [
  12. localforage.WEBSQL,
  13. localforage.INDEXEDDB,
  14. localforage.LOCALSTORAGE
  15. ];
  16. var items = [
  17. { key: 'user-2-todo-4', value: 'bb44ccaa4444' },
  18. { key: 'user-2-todo-3', value: 'bb33ccaa3333' },
  19. { key: 'user-2-todo-2', value: 'bb22ccaa2222' },
  20. { key: 'user-2-todo-1', value: 'bb11ccaa1111' },
  21. { key: 'user-1-todo-4', value: '44aa4444bbcc' },
  22. { key: 'user-1-todo-3', value: '33aa3333bbcc' },
  23. { key: 'user-1-todo-2', value: '22aa2222bbcc' },
  24. { key: 'user-1-todo-1', value: '11aa1111bbcc' }
  25. ];
  26. var driver = '';
  27. localforage.setDriver(driverTestOrder).then(function() {
  28. driver = localforage.driver();
  29. return localforage.clear();
  30. }).then(function() {
  31. var t0 = performance.now();
  32. var putDone = localforage.setItems(items);
  33. return putDone.then(function() {
  34. var t1 = performance.now();
  35. console.log('Completed setItems ' + driver + ' after ' + (t1 - t0) + ' milliseconds.');
  36. return localforage.keys().then(function (keys) {
  37. console.log(keys);
  38. return localforage.getItem(keys[0]).then(function (x) {
  39. console.log(keys[0], x);
  40. });
  41. });
  42. });
  43. }).then(function(){
  44. return localforage.clear();
  45. }).then(function(){
  46. if (driver !== localforage.LOCALSTORAGE) {
  47. var t0 = performance.now();
  48. var putDone = localforage.setItems.generic.call(localforage, items);
  49. return putDone.then(function() {
  50. var t1 = performance.now();
  51. console.log('Completed setItemsGeneric ' + driver + ' after ' + (t1 - t0) + ' milliseconds.');
  52. return localforage.keys().then(function (keys) {
  53. console.log(keys);
  54. return localforage.getItem(keys[0]).then(function (x) {
  55. console.log(keys[0], x);
  56. });
  57. });
  58. });
  59. }
  60. });
  61. </script>
  62. <p>
  63. Check your console log.
  64. </p>
  65. </body>
  66. </html>