Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Localstorage only removes single item, instead of clearing entire cache #30

Merged
merged 1 commit into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spid-localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function set(key, value, expiresInSeconds) {

function clear(key) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should maybe look into renaming this function name as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, I wasn´t bold enough to make any changes more than needed.
I think the name might be there because it was called 'clear' in the cookie module.

If changed it think it should be changed there as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that renaming the method is probably a thing for a separate PR (as that's more an issue of style), if we decide that it's the right thing to do.

try {
window.localStorage.clear(key);
window.localStorage.removeItem(key);
} catch(e) {
log.info(e);
}
Expand Down
15 changes: 14 additions & 1 deletion test/spec/spid-localstorage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ describe('SPiD.Localstorage', function() {
assert.isNull(storage.get('test'));
});

it(' clear only clears one key', function () {

var preExistingKey = 'a';
var valueStored = 'foo';
storage.set(preExistingKey, valueStored);

storage.set('b');
storage.clear('b');

var preExistingValueRead = storage.get('a');

assert.equal(valueStored, preExistingValueRead);
});

it(' passing an expires parameter should add expires field that\'s in the future', function() {
var data = {'thought' : 'leader'};
storage.set('test', data, 100);
Expand All @@ -39,5 +53,4 @@ describe('SPiD.Localstorage', function() {
assert.isNull( window.localStorage.getItem('test'));
});


});