flimflam57
flimflam57

Reputation: 1334

Should I initiate a Session with Session.set('key', undefined)?

I new to Meteor and I've found myself initiating a Session with:

Session.set('key', undefined);

Then somewhere inside a helper, say, I'd set it:

...
Session.set('key, some value);
...

I'm not sure why I've started doing this; I may have seen it done somewhere and have just copied it. Can I just set the Session when I need it to hold the unique value and forget the initial 'undefined' value?

Upvotes: 1

Views: 52

Answers (1)

dr.dimitru
dr.dimitru

Reputation: 2702

If you're 100% sure this Session should be initialized, Meteor has special method for this:

Session.setDefault(key, value);

Reference for Session.setDefault

Upvotes: 1

Related Questions