Pass multiple collections to a template · Issue #53 · rendrjs/rendr (original) (raw)

That's one place. There are a few other important parts. Let's walk through the process:

What I'd like is that any JSON-serializable data could be bootstrapped and attached to a view during hydration, rather than just models or collections. This could be accomplished by assigning a unique identifier to views on the server, and then using that id as a key in order to store the data for that view in a dictionary.

It may be possible to reuse the View.prototype.cid unique ID that Backbone adds to views, however the issue is that it gets regenerated on the client-side, and gets out of sync with the server. We could either override the constructor in View to use a cid that was passed into this.options (coming from a data-cid attribute in the HTML), or just use our own identifier.

The reason I didn't go down this road in the first place is because of duplicate data being bootstrapped for subviews. Take m.airbnb.com as an example; if you view the source, you'll notice there's a search_view which has a reference to a listings collection (identified by the JSON params {"location":"","number_of_guests":1,"offset":0,"items_per_page":20}). That is the outer view, but it has a number of child views which share a reference to the same collection. What I wouldn't want to happen is to duplicate that bootstrapped JSON onto the page once for each view; that can add up!

Maybe there's a library that can de-dupe JSON into some other, more compact format? If not, this would be a pretty juicy problem to tackle!

Another approach could be to keep bootstrapping data as models or collections, but allow multiple models or collections. Then it's really just BaseView that needs to change, rather than all the bootstrapping code.