Understanding client data binding with ReactiveVar/Dict


#1

I’m still fairly new to Meteor so I’m trying to understand some of the core principals; I understand that there may not yet be canonical ways of doing everything.

I’ve got a calendar composed of Day objects, each with a number of properties. The client interaction is somewhat involved, needing to repeatedly access and modify these properties. Is the ‘correct’ or best way to do this via a ReactiveDict plus a Template.autorun to manage the db updates?

For example, a Day might look like:

"2014-11-20":{
    	"JLKGZnfFkGvX9DHgz":{
    		"state":1,
    		"notes":"Only available after 9",
    		"timestamp":"Thu Mar 05 2015 13:46:50 GMT-0500 (EST)"
    	},
    	"Rkhs4cu7LzyejcTYa":{
    		"state":1,
    		"notes":"",
    		"timestamp":"Thu Mar 05 2015 13:46:50 GMT-0500 (EST)"
    	},
    	"selected":true
}

Each hash key is a user id. I need to do things like calculate how many users have what states for that day, change the state of the current user, etc…

I would imagine that a ReactiveDict would be good for this (as opposed to a bunch of individual ReactiveVars) and an autorun block that interfaces with the collection?

Or am I missing something basic?


#2

Are you sure you need anything between you and your collection? Can you not display and modify your data by accessing your collection directly ? (with template helpers for read access and Meteor methods for write access)


#3

@t3db0t What you’re suggesting sounds perfectly fine. Using ReactiveDict to store your “cached” values will allow you to prevent redundant computations. However in 99% situations an inline solution in the form of template helper that acts directly on your collection as suggested by @Steve will be more then enough. Please note that when you are accessing collection on client it’s actually a local copy of a subset from your database, so there’s practically no overhead if you’re querying multiple times for the same data.