Skip to content

Instantly share code, notes, and snippets.

@pward123
Last active August 29, 2015 13:57
Show Gist options
  • Save pward123/9573687 to your computer and use it in GitHub Desktop.
Save pward123/9573687 to your computer and use it in GitHub Desktop.
Session Trick
SessionProperty = function _sessionProperty(key, defaultValue) {
if (!_.isString(key)) throw new Meteor.Error('key must be a string');
return function(value) {
if (_.isUndefined(value)) {
value = Session.get(key);
return _.isUndefined(value) ? defaultValue : value;
} else {
return Session.set(key, value);
}
}
}
var templateName = 'myTemplate'
,searchKeywords = SessionProperty(templateName + '_searchKeywords', '')
;
// Getting the searchKeywords value
var currentValue = searchKeywords();
// Setting the searchKeywords value
searchKeywords('new value');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment