ES2015 first look / babeljs

This commit is contained in:
RainLoop Team 2015-11-15 03:23:16 +03:00
parent 5dcceaaca5
commit 445cd155e5
123 changed files with 3214 additions and 3680 deletions

View file

@ -1,99 +0,0 @@
(function () {
'use strict';
var
$ = require('$'),
JSON = require('JSON'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function CookieDriver()
{
}
/**
* @static
* @return {boolean}
*/
CookieDriver.supported = function ()
{
return !!(window.navigator && window.navigator.cookieEnabled);
};
/**
* @param {string} sKey
* @param {*} mData
* @return {boolean}
*/
CookieDriver.prototype.set = function (sKey, mData)
{
var
mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
bResult = false,
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
}
catch (e) {}
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
try
{
$.cookie(Consts.Values.ClientSideStorageIndexName, JSON.stringify(mResult), {
'expires': 30
});
bResult = true;
}
catch (e) {}
return bResult;
};
/**
* @param {string} sKey
* @return {*}
*/
CookieDriver.prototype.get = function (sKey)
{
var
mStorageValue = $.cookie(Consts.Values.ClientSideStorageIndexName),
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey]))
{
mResult = mResult[sKey];
}
else
{
mResult = null;
}
}
catch (e) {}
return mResult;
};
module.exports = CookieDriver;
}());

View file

@ -0,0 +1,72 @@
import {window, JSON, $} from 'common';
import Utils from 'Common/Utils';
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
class CookieDriver
{
/**
* @param {string} key
* @param {*} data
* @return {boolean}
*/
set(key, data) {
let
result = false,
storageResult = null
;
try
{
const storageValue = $.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME);
storageResult = null === storageValue ? null : JSON.parse(storageValue);
}
catch (e) {}
(storageResult || (storageResult = {}))[key] = data;
try
{
$.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME, JSON.stringify(storageResult), {
'expires': 30
});
result = true;
}
catch (e) {}
return result;
}
/**
* @param {string} key
* @return {*}
*/
get(sKey) {
let result = null;
try
{
const
storageValue = $.cookie(CLIENT_SIDE_STORAGE_INDEX_NAME),
storageResult = null === storageValue ? null : JSON.parse(storageValue)
;
result = (storageResult && !Utils.isUnd(storageResult[key])) ? storageResult[key] : null;
}
catch (e) {}
return mResult;
};
/**
* @return {boolean}
*/
static supported() {
return !!(window.navigator && window.navigator.cookieEnabled);
}
}
export {CookieDriver, CookieDriver as default};

View file

@ -1,97 +0,0 @@
(function () {
'use strict';
var
window = require('window'),
JSON = require('JSON'),
Consts = require('Common/Consts'),
Utils = require('Common/Utils')
;
/**
* @constructor
*/
function LocalStorageDriver()
{
}
/**
* @static
* @return {boolean}
*/
LocalStorageDriver.supported = function ()
{
return !!window.localStorage;
};
/**
* @param {string} sKey
* @param {*} mData
* @return {boolean}
*/
LocalStorageDriver.prototype.set = function (sKey, mData)
{
var
mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
bResult = false,
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
}
catch (e) {}
if (!mResult)
{
mResult = {};
}
mResult[sKey] = mData;
try
{
window.localStorage[Consts.Values.ClientSideStorageIndexName] = JSON.stringify(mResult);
bResult = true;
}
catch (e) {}
return bResult;
};
/**
* @param {string} sKey
* @return {*}
*/
LocalStorageDriver.prototype.get = function (sKey)
{
var
mStorageValue = window.localStorage[Consts.Values.ClientSideStorageIndexName] || null,
mResult = null
;
try
{
mResult = null === mStorageValue ? null : JSON.parse(mStorageValue);
if (mResult && !Utils.isUnd(mResult[sKey]))
{
mResult = mResult[sKey];
}
else
{
mResult = null;
}
}
catch (e) {}
return mResult;
};
module.exports = LocalStorageDriver;
}());

View file

@ -0,0 +1,69 @@
import {window, JSON} from 'common';
import Utils from 'Common/Utils';
import {CLIENT_SIDE_STORAGE_INDEX_NAME} from 'Common/Consts';
class LocalStorageDriver
{
/**
* @param {string} key
* @param {*} data
* @return {boolean}
*/
set(key, data) {
let
result = false,
storageResult = null
;
try
{
const storageValue = window.localStorage[CLIENT_SIDE_STORAGE_INDEX_NAME] || null;
storageResult = null === storageValue ? null : JSON.parse(storageValue);
}
catch (e) {}
(storageResult || (storageResult = {}))[key] = data;
try
{
window.localStorage[CLIENT_SIDE_STORAGE_INDEX_NAME] = JSON.stringify(storageResult);
result = true;
}
catch (e) {}
return result;
}
/**
* @param {string} key
* @return {*}
*/
get(key) {
let result = null;
try
{
const
storageValue = window.localStorage[CLIENT_SIDE_STORAGE_INDEX_NAME] || null,
storageResult = null === storageValue ? null : JSON.parse(storageValue)
;
result = (storageResult && !Utils.isUnd(storageResult[key])) ? storageResult[key] : null
}
catch (e) {}
return result;
}
/**
* @return {boolean}
*/
static supported() {
return !!window.localStorage;
}
}
export {LocalStorageDriver, LocalStorageDriver as default};