Goal
I have a top-level Collection named Players and a Session variable called ‘n’. In addition to my top-level Collection, I’d like to have a Collection of the top-‘n’ Players based on player.points, which updates in reaction to Session.set('n', n) (and, of course, any changing of the underlying Players data).
Rationale
The reason I would like a TopNPlayers is because within each player template (call it Template.player_item) I want to provide a couple of variables:
Template.player_item.isInTopN, which sets a CSS class to highlight a player if it’s in the top-‘n’ in pointsTemplate.player_item.PointsVsBaseline, which gives the difference between that player’s points and the ‘n’th player inTopNPlayers.
Since I don’t want to manually manage a global variable containing Players filtered by the value of Session.get('n'), and I certainly don’t want to calculate the top-‘n’ every time I render another player_item, I’d like to set up an additional subscription to the Players Collection.
I’m not sure you need a separate collection, wouldn’t a cursor do the trick?
Something like: