Hi there, I just started learning Meteor. I’m a quit experienced developer with PHP and Rails but this is my first JavaScript adventure.
I finished the leaderboard tutorial (Meteor Tips Tutorial) and it worked like a charm. Now I am trying to expand the app to improve my understanding and came across the following question:
In the tutorial you can select only one player at a time but I want to be able to select multiple players. (< li > elements) So that when I click on a player it gets selected and when I click on the next player both become highlighted.
I thought it might be a good idea to edit this function from the tutorial:
My approach was to store the players in an array within the “selectedPlayer” session variable but I see quite a lot of people bashing stuff like this as “misusing sessions” as they were intended to be a simple key, value pair and I can’t really argue with that opinion.
Nothing wrong with what you’re suggesting (using an array in a Session variable), in my opinion. If it’s abusing Session you’re worried about, read this excellent post from @robfallows about the alternatives.
The approach above by @robsw is sound, in terms of keeping the scope limited and the global keyspace in Session unpolluted, and is a pattern that lots of Meteor devs (including myself) would use.