-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from simianhacker/fix/395
Split storage service in to two new services sessionStorage and localStorage
- Loading branch information
Showing
6 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,42 @@ | ||
define(function (require) { | ||
var modules = require('modules'); | ||
|
||
modules.get('kibana/storage') | ||
.service('storage', function ($window) { | ||
function Storage() { | ||
var self = this; | ||
self.store = $window.localStorage; | ||
function Storage(store) { | ||
var self = this; | ||
self.store = store; | ||
|
||
self.get = function (key) { | ||
try { | ||
return JSON.parse(self.store.getItem(key)); | ||
} catch (e) { | ||
return null; | ||
} | ||
}; | ||
|
||
self.get = function (key) { | ||
try { | ||
return JSON.parse(self.store.getItem(key)); | ||
} catch (e) { | ||
return null; | ||
} | ||
}; | ||
self.set = function (key, value) { | ||
try { | ||
return self.store.setItem(key, JSON.stringify(value)); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
|
||
self.set = function (key, value) { | ||
try { | ||
return self.store.setItem(key, JSON.stringify(value)); | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
self.remove = function (key) { | ||
return self.store.removeItem(key); | ||
}; | ||
|
||
self.remove = function (key) { | ||
return self.store.removeItem(key); | ||
}; | ||
self.clear = function () { | ||
return self.store.clear(); | ||
}; | ||
} | ||
|
||
self.clear = function () { | ||
return self.store.clear(); | ||
}; | ||
} | ||
var createService = function (type) { | ||
return function ($window) { | ||
return new Storage($window[type]); | ||
}; | ||
}; | ||
|
||
return new Storage(); | ||
}); | ||
modules.get('kibana/storage') | ||
.service('localStorage', createService('localStorage')) | ||
.service('sessionStorage', createService('sessionStorage')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters