amplify.store - 101

HTML

<script src="https://raw.github.com/appendto/amplify/master/store/amplify.store.js"></script>
<script src="http://codeseven.github.com/toastr/toastr.js"></script>
<link rel="stylesheet" href="http://codeseven.github.com/toastr/toastr.css">
<link rel="stylesheet" href="http://codeseven.github.com/toastr/toastr-responsive.css">

JavaScript

toastr.options = {
    timeOut: 10000
};

var testKey = 'WEB101';
var testVal = 'KnockoutJS 101';

var testKey2 = 'people';
var testVal2 = [
    {
    name: 'John',
        age: 34, pets: [{name: 'Fido', type: 'dog'}, {name: 'Tink', type: 'cat'} ]},
{
    name: 'Ella',
    age: 24, pets: [{name: 'Ginnie', type: 'cat'} ]},
{
    name: 'Landon',
    age: 14, pets: [{name: 'Iron Man', type: 'dog'}, {name: 'McQueen', type: 'dog'} ]}];

/* Store a simple value */
/*
amplify.store(testKey, testVal);
toastr.info('saved ' + testKey + ' === ' + testVal);

var fetchedVal = amplify.store(testKey);
toastr.info('fetched ' + testKey + ' === ' + fetchedVal);

fetchedVal = amplify.store(testKey, null);
toastr.info('cleared ' + testKey + ' === ' + fetchedVal);
*/
/* Store an array of objects */
amplify.store(testKey2, testVal2);
toastr.info('saved ' + testKey2 + '. 1st person is === ' + testVal2[0].name);

var fetchedVal2 = amplify.store(testKey2);
toastr.info('fetched ' + testKey2 + '. 1st person is === ' + fetchedVal2[0].name);

//fetchedVal2 = amplify.store(testKey2, null);
//toastr.info('cleared ' + testKey2 + ' === ' + fetchedVal2);



/* Fetch all hash values */

amplify.store(testKey, testVal);
toastr.success('saved ' + testKey + ' === ' + testVal);

var allVals = amplify.store();
toastr.success(JSON.stringify(allVals));

var allVals = amplify.store();
console.log(allVals);
for(key in allVals){
    console.log(key);
}





/* Store an array of objects, and set expiration */
amplify.store(testKey2, testVal2, {
    expires: 1000
});
toastr.warning('saved ' + testKey2 + '. 1st person is === ' + testVal2[0].name);

fetchedVal2 = amplify.store(testKey2);
toastr.warning('fetched ' + testKey2 + '. 1st person is === ' + fetchedVal2[0].name);

window.setTimeout(

function() {
    fetchedVal2 = amplify.store(testKey2);
    toastr.warning('fetched after delay ' + testKey2 + '. 1st person is === ' + (fetchedVal2 ? fetchedVal2[0].name : 'undefined'));
}, 2000);