Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear amplify.store()?

I need to clear amplifyjs storage, remove all key-values. Smth similar to localStorage.clear().

Thanks in advance.

like image 385
Vladimir Melekh Avatar asked Jun 04 '14 14:06

Vladimir Melekh


1 Answers

The docs for amplifyjs indicate that you can clear (remove) a specific storage key by storing the value null to that key:

amplify.store( "MyKeyName", null );

We can get all of the current storage key names with: amplify.store() and then use jQuery $.each to go through the list and clear (remove) each of the items currently stored in 'amplifyjs storage':

$.each(amplify.store(), function (storeKey) {
    // Delete the current key from Amplify storage
    amplify.store(storeKey, null);
});

You could put this code into a function and call it or use it inline somewhere, but I'd probably add the function to amplifyjs at runtime with something like:

amplify.clearStore = function() {
    $.each(amplify.store(), function (storeKey) {
        // Delete the current key from Amplify storage
        amplify.store(storeKey, null);
    });
};

and then call that with amplify.clearStore();

like image 99
David Tansey Avatar answered Sep 29 '22 11:09

David Tansey