meteor/meteor — pull request #272 by joshrtay (2012-08-12 23:14:36+00:00)
Title: add ReactiveDict, ReactiveDict on template, and firstRender

Implemented some of the features mention in the landmark-demo-comments. If you like the changes, I'm happy to clean up the code and test better. Right now the landmark demo works exactly as it did before, but I have not done any testing beyond that.

Implemented a ReactiveDict that Session utilizes.

// XXX make Session be a ReactiveDict (ReactiveMap?)

Added a ReactiveDict to each template.

// XXX actually want to create a ReactiveVar on the template!
// (but how will it be preserved across migration?)
// (maybe template.get, template.set?? rather than form??)

Handled the migration by storing each template store by the dom path of the firstNode of the template. When the template is rendered after a migration it checks the migration data to see if any stores match the dom path of the firstNode.

Migration Setup
```javascript
var templateStoresByPath = {};
if (Meteor._reload) {
Meteor._reload.on_migrate('templateStores',function() {
var stores = {}
_.each(templateInstanceData,function(template) {
stores[template.path()] = template.store;
});
return [true,stores];
});
(function() {
var migration_data = Meteor._reload.migration_data('templateStores');
if (migration_data) {
templateStoresByPath = migration_data;
}
})();
}
```

path
```javascript
return "/" + $(this.firstNode).parents().andSelf().map(function() {
var $this = $(this);
var tagName = this.nodeName;
if ($this.siblings(tagName).length > 0) {
tagName += "[" + $this.prevAll(tagName).length + "]";
}
return tagName;
}).get().join("/");
```

restore
```javascript
var path = template.path();
if (template.firstRender && path in templateStoresByPath) {
template.store.setMany(templateStoresByPath[path]);
}
```
Also added template.firstRender.

// XXX template.firstRender would be handy here