Reputation: 7362
Currently in my Meteor app, I have a boolean variable at the top of my layout file that keeps track of wether the user has closed the menu in desktop view.
var closedMenuInDesktopView = false
Also in another point in my app I use a boolean variable at top to keep track of wether the app is currently saving or not.
var saving = false
Everything in my app is working ok but I notice in the example Meteor apps, they use the Session to keep track of state variables within the app. Is it better to do it this way instead of putting javascript variables at the top of the file that can hold value?
Upvotes: 1
Views: 272
Reputation: 64312
For template code, I think you have three choices:
Session
Session
variable, but don't care if you lose state after the template is destroyed. In my case, that's most of the time.Upvotes: 3
Reputation: 2147
Variables that you declare with var
are only accessible from within that file. This is much more manageable as your application grows.
Session variables have the advantage of being reactive. They often appear in examples because they have clean syntax, and trigger DOM updates. It's best to limit using session variables for the same reasons you avoid globals.
If you don't need reactivity, stick with your locals. If you need a few reactive variables, use Session
. Otherwise, have a look at Deps.Dependency
to learn how to make your own reactive variables.
Upvotes: 1