LocalForage Test

by LeeMellinger

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/localforage/0.9.1/localforage.js"></script>
<h3>Open console log to see results</h3>

TypeScript

let storageKey = 'abc123';
let data = {a: 1, b: 2, c: 3}

save(data)

// Get all keys.
localforage.keys().then((keys)=> {
	console.log('All Key',keys)
})

get(1).then(function(d) {
	console.log('get1 callback',d)
});

get(2).then(function(d) {
	console.log('get2 callback', d)
});

function save(data) {

  console.log('set');

	localforage.setItem(storageKey, data, function (data) {
  
    console.log('set callback');
  	console.log(data.length);
    
  });
}

function get(n) {
  console.log('get' + n)
  return localforage.getItem(storageKey);
}