snappymail/dev/Storage/Local.js

55 lines
1 KiB
JavaScript
Raw Normal View History

/* RainLoop Webmail (c) RainLoop Team | Licensed under CC BY-NC-SA 3.0 */
2014-09-05 06:49:03 +08:00
(function () {
2014-08-25 23:49:01 +08:00
'use strict';
2014-08-20 23:03:12 +08:00
/**
* @constructor
*/
function LocalStorage()
{
2014-08-20 23:03:12 +08:00
var
NextStorageDriver = require('_').find([
require('Storage/LocalDriver/LocalStorage'),
require('Storage/LocalDriver/Cookie')
2014-08-27 23:59:44 +08:00
], function (NextStorageDriver) {
return NextStorageDriver && NextStorageDriver.supported();
2014-08-20 23:03:12 +08:00
})
;
2014-08-25 23:49:01 +08:00
this.oDriver = null;
2014-08-20 23:03:12 +08:00
if (NextStorageDriver)
{
this.oDriver = new NextStorageDriver();
}
}
2014-08-20 23:03:12 +08:00
2014-09-02 19:34:17 +08:00
/**
* @type {LocalStorageDriver|CookieDriver|null}
*/
2014-08-20 23:03:12 +08:00
LocalStorage.prototype.oDriver = null;
/**
* @param {number} iKey
* @param {*} mData
* @return {boolean}
*/
LocalStorage.prototype.set = function (iKey, mData)
{
return this.oDriver ? this.oDriver.set('p' + iKey, mData) : false;
};
/**
* @param {number} iKey
* @return {*}
*/
LocalStorage.prototype.get = function (iKey)
{
return this.oDriver ? this.oDriver.get('p' + iKey) : null;
};
2014-08-21 23:08:34 +08:00
module.exports = new LocalStorage();
2014-08-20 23:03:12 +08:00
2014-09-05 06:49:03 +08:00
}());