Last active
August 29, 2015 13:57
-
-
Save pward123/9573687 to your computer and use it in GitHub Desktop.
Session Trick
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
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); | |
} | |
} | |
} |
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
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