function load(name, doNotParse, opt) {
var cookies = _isNode2.default ? _rawCookie : _cookie2.default.parse(document.cookie, opt);
var cookieVal = cookies && cookies[name];
if (typeof doNotParse === 'undefined') {
doNotParse = !cookieVal || cookieVal[0] !== '{' && cookieVal[0] !== '[';
}
if (!doNotParse) {
try {
cookieVal = JSON.parse(cookieVal);
} catch (e) {
// Not serialized object
}
}
return cookieVal;
}...
import cookie from 'react-cookie';
import LoginPanel from './LoginPanel';
import Dashboard from './Dashboard';
export default class MyApp extends Component {
componentWillMount() {
this.state = { userId: cookie.load('userId') };
}
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
...function plugToRequest(req, res) {
if (req.cookie) {
_rawCookie = req.cookie;
} else if (req.cookies) {
_rawCookie = req.cookies;
} else if (req.headers && req.headers.cookie) {
setRawCookie(req.headers.cookie);
} else {
_rawCookie = {};
}
_res = res;
return function unplug() {
_res = null;
_rawCookie = {};
};
}n/a
function remove(name, opt) {
delete _rawCookie[name];
if (typeof opt === 'undefined') {
opt = {};
} else if (typeof opt === 'string') {
// Will be deprecated in future versions
opt = { path: opt };
} else {
// Prevent mutation of opt below
opt = (0, _objectAssign2.default)({}, opt);
}
if (typeof document !== 'undefined') {
opt.expires = new Date(1970, 1, 1, 0, 0, 1);
opt.maxAge = 0;
document.cookie = _cookie2.default.serialize(name, '', opt);
}
if (_isResWritable() && _res.clearCookie) {
_res.clearCookie(name, opt);
}
}...
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
onLogout() {
cookie.remove('userId', { path: '/' });
}
render() {
if (!this.state.userId) {
return <LoginPanel onSuccess={this.onLogin.bind(this)} />;
}
...function save(name, val, opt) {
_rawCookie[name] = val;
// allow you to work with cookies as objects.
if ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') {
_rawCookie[name] = JSON.stringify(val);
}
// Cookies only work in the browser
if (!_isNode2.default) {
document.cookie = _cookie2.default.serialize(name, _rawCookie[name], opt);
}
if (_isResWritable() && _res.cookie) {
var expressOpt = _extends({}, opt);
if (expressOpt.maxAge) {
// the standard for maxAge is seconds but express uses milliseconds
expressOpt.maxAge = opt.maxAge * 1000;
}
_res.cookie(name, val, opt);
}
}...
export default class MyApp extends Component {
componentWillMount() {
this.state = { userId: cookie.load('userId') };
}
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
onLogout() {
cookie.remove('userId', { path: '/' });
}
render() {
...function select(regex) {
var cookies = _isNode2.default ? _rawCookie : _cookie2.default.parse(document.cookie);
if (!cookies) {
return {};
}
if (!regex) {
return cookies;
}
return Object.keys(cookies).reduce(function (accumulator, name) {
if (!regex.test(name)) {
return accumulator;
}
var newCookie = {};
newCookie[name] = cookies[name];
return (0, _objectAssign2.default)({}, accumulator, newCookie);
}, {});
}n/a
function setRawCookie(rawCookie) {
if (rawCookie) {
_rawCookie = _cookie2.default.parse(rawCookie);
} else {
_rawCookie = {};
}
}n/a
function load(name, doNotParse, opt) {
var cookies = _isNode2.default ? _rawCookie : _cookie2.default.parse(document.cookie, opt);
var cookieVal = cookies && cookies[name];
if (typeof doNotParse === 'undefined') {
doNotParse = !cookieVal || cookieVal[0] !== '{' && cookieVal[0] !== '[';
}
if (!doNotParse) {
try {
cookieVal = JSON.parse(cookieVal);
} catch (e) {
// Not serialized object
}
}
return cookieVal;
}...
import cookie from 'react-cookie';
import LoginPanel from './LoginPanel';
import Dashboard from './Dashboard';
export default class MyApp extends Component {
componentWillMount() {
this.state = { userId: cookie.load('userId') };
}
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
...function plugToRequest(req, res) {
if (req.cookie) {
_rawCookie = req.cookie;
} else if (req.cookies) {
_rawCookie = req.cookies;
} else if (req.headers && req.headers.cookie) {
setRawCookie(req.headers.cookie);
} else {
_rawCookie = {};
}
_res = res;
return function unplug() {
_res = null;
_rawCookie = {};
};
}n/a
function remove(name, opt) {
delete _rawCookie[name];
if (typeof opt === 'undefined') {
opt = {};
} else if (typeof opt === 'string') {
// Will be deprecated in future versions
opt = { path: opt };
} else {
// Prevent mutation of opt below
opt = (0, _objectAssign2.default)({}, opt);
}
if (typeof document !== 'undefined') {
opt.expires = new Date(1970, 1, 1, 0, 0, 1);
opt.maxAge = 0;
document.cookie = _cookie2.default.serialize(name, '', opt);
}
if (_isResWritable() && _res.clearCookie) {
_res.clearCookie(name, opt);
}
}...
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
onLogout() {
cookie.remove('userId', { path: '/' });
}
render() {
if (!this.state.userId) {
return <LoginPanel onSuccess={this.onLogin.bind(this)} />;
}
...function save(name, val, opt) {
_rawCookie[name] = val;
// allow you to work with cookies as objects.
if ((typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object') {
_rawCookie[name] = JSON.stringify(val);
}
// Cookies only work in the browser
if (!_isNode2.default) {
document.cookie = _cookie2.default.serialize(name, _rawCookie[name], opt);
}
if (_isResWritable() && _res.cookie) {
var expressOpt = _extends({}, opt);
if (expressOpt.maxAge) {
// the standard for maxAge is seconds but express uses milliseconds
expressOpt.maxAge = opt.maxAge * 1000;
}
_res.cookie(name, val, opt);
}
}...
export default class MyApp extends Component {
componentWillMount() {
this.state = { userId: cookie.load('userId') };
}
onLogin(userId) {
this.setState({ userId });
cookie.save('userId', userId, { path: '/' });
}
onLogout() {
cookie.remove('userId', { path: '/' });
}
render() {
...function select(regex) {
var cookies = _isNode2.default ? _rawCookie : _cookie2.default.parse(document.cookie);
if (!cookies) {
return {};
}
if (!regex) {
return cookies;
}
return Object.keys(cookies).reduce(function (accumulator, name) {
if (!regex.test(name)) {
return accumulator;
}
var newCookie = {};
newCookie[name] = cookies[name];
return (0, _objectAssign2.default)({}, accumulator, newCookie);
}, {});
}n/a
function setRawCookie(rawCookie) {
if (rawCookie) {
_rawCookie = _cookie2.default.parse(rawCookie);
} else {
_rawCookie = {};
}
}n/a