12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <!doctype html>
- <html>
- <head>
- <meta charset="utf8" />
- <title>Simple localForage-setItems example</title>
- </head>
- <body>
- <script src="../node_modules/localforage/dist/localforage.js"></script>
- <script src="../dist/localforage-setitems.js"></script>
- <script>
- var driverTestOrder = [
- localforage.INDEXEDDB,
- localforage.WEBSQL,
- localforage.LOCALSTORAGE
- ];
- var n = 10000;
- function getRandomItems() {
- var result = {};
- for (var i = 0; i < n; i++) {
- var key = ((Math.random() * n) | 0) + 'key';
- var value = ((Math.random() * n) | 0) + 'value';
- result[key] = value;
- }
- return result;
- }
-
- var items = getRandomItems();
- var driver = '';
- localforage.setDriver(driverTestOrder).then(function() {
- driver = localforage.driver();
- return localforage.clear();
- }).then(function() {
- var t0 = performance.now();
- var putDone = localforage.setItems(items);
- return putDone.then(function() {
- var t1 = performance.now();
- console.log('Completed setItems ' + driver + ' after ' + (t1 - t0) + ' milliseconds.');
- return localforage.keys().then(function (keys) {
- console.log(keys);
- return localforage.getItem(keys[0]).then(function (x) {
- console.log(keys[0], x);
- });
- });
- });
- }).then(function(){
- return localforage.clear();
- }).then(function(){
- if (driver !== localforage.LOCALSTORAGE) {
- var t0 = performance.now();
- var putDone = localforage.setItems.generic.call(localforage, items);
- return putDone.then(function() {
- var t1 = performance.now();
- console.log('Completed setItemsGeneric ' + driver + ' after ' + (t1 - t0) + ' milliseconds.');
- return localforage.keys().then(function (keys) {
- console.log(keys);
- return localforage.getItem(keys[0]).then(function (x) {
- console.log(keys[0], x);
- });
- });
- });
- }
- });
- </script>
- <p>
- Check your console log.
- </p>
- </body>
- </html>
|