How to clear amplify.store()?
Asked Answered
A

1

6

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

Thanks in advance.

Ankney answered 4/6, 2014 at 14:48 Comment(0)
H
8

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();

Healing answered 29/6, 2014 at 22:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.