12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <!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.WEBSQL,
- localforage.INDEXEDDB,
- localforage.LOCALSTORAGE
- ];
- var items = [
- { key: 'user-2-todo-4', value: 'bb44ccaa4444' },
- { key: 'user-2-todo-3', value: 'bb33ccaa3333' },
- { key: 'user-2-todo-2', value: 'bb22ccaa2222' },
- { key: 'user-2-todo-1', value: 'bb11ccaa1111' },
- { key: 'user-1-todo-4', value: '44aa4444bbcc' },
- { key: 'user-1-todo-3', value: '33aa3333bbcc' },
- { key: 'user-1-todo-2', value: '22aa2222bbcc' },
- { key: 'user-1-todo-1', value: '11aa1111bbcc' }
- ];
- 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>
|