News for hackers. Stuff that matters.
Re:Rendr - Use Backbone on both the server and client by bryanlarsen on Tuesday April 02, 2013 @05:27AM (#5478360)
My brother released a very similar project about 8 months ago.[1] He never did properly announce or document it so it's no surprise that nobody else is using it.

Of course, it's not like rendr has any real documentation, either.

However it has been working very well for us, so it is validation of the rendr approach.

A quick glance at their documentation indicates a very similar design, comparing the two projects should be instructive.

1: https://github.com/wvl/highbrow

Re:Rendr - Use Backbone on both the server and client by bryanlarsen on Tuesday April 02, 2013 @06:13AM (#5478461)
I looked a little bit more at the rendr source, and one thing that immediately jumps out at me is the code BaseView#getTemplateData[1] which very tightly couples the model & views together. You should totally steal highbrow's ViewModel code, which is very sweet. (But you might want to come up with a better name). Rather than passing @model.toJSON() as template data, highbrow creates a ViewModel from the model or collection or out of thin air, and passes that in as template data.

Here's a typical ViewModel definition (in JS):

    foo.vm.Resource = highbrow.ViewModel.extend({
      lastUpdated: function() {
        return moment(this.model.get('modifiedAt')).fromNow();
      }
    });
    foo.vm.Resource.attrs(['name', 'content']);
This shows the main two features of ViewModel's: a whitelist of attrs that the template can access directly, and a set of functions that would otherwise end up polluting your model with view side code.

This decoupling dramatically improves the structure of our applications, without introducing Rails style controllers which are also totally misnamed in my opinion. Rails controllers are essentially two things: routers and MV-shims. Splitting the two makes for much improved program structure.

1: https://github.com/airbnb/rendr/blob/master/shared/base/view...

2: https://github.com/wvl/highbrow/blob/master/src/view-model.c...

Re:Rendr - Use Backbone on both the server and client by frontendbeauty on Tuesday April 02, 2013 @03:13PM (#5481499)
Cool, I like that ViewModel pattern. You could certainly use that with Rendr.
Re:Rendr - Use Backbone on both the server and client by bryanlarsen on Tuesday April 02, 2013 @06:23AM (#5478485)
I think this design goal:

    * Minimize if (server) {...} else {…}
was unfortunate. A grep of the highbrow source code indicates about 10 instances of that pattern, so I don't think there's a need for a separate base/server/client directory structure like rendr has, I think that creates artificial distinctions. It may be because I'm used to reading the highbrow source (because that's the only documentation :), but I find those if/else blocks to be very illuminating.
Re:Rendr - Use Backbone on both the server and client by napoleond on Tuesday April 02, 2013 @11:37AM (#5479930)
This is really nice, thanks for sharing. When this thread hit the front page last night I was very surprised that no one had done this before with Backbone--as it turns out, a few people have!
Re:Rendr - Use Backbone on both the server and client by bryanlarsen on Tuesday April 02, 2013 @06:15AM (#5478468)