Live data from Hacker News

Revesiting Backbone.js View Rendering

elving.me

1–9 of 9 posts

Re: Revesiting Backbone.js View Rendering

#4
post #2

I'm not familiar with Backbone but isn't `model.toJSON()` unnecessarily removing useful data types (like Date) that aren't available in JSON ?

You're probably thinking of `JSON.stringify()`. `model.toJSON()` just returns a clone of the models attributes object.

Re: Revesiting Backbone.js View Rendering

#5
post #2

I'm not familiar with Backbone but isn't `model.toJSON()` unnecessarily removing useful data types (like Date) that aren't available in JSON ?

You're probably thinking of `JSON.stringify()`. `model.toJSON()` just returns a clone of the models attributes object.

So `model.toJSON()` isn't supposed to return a JSON-compatible data structure ?

Re: Revesiting Backbone.js View Rendering

#7
post #5

Earlier quoted context omitted.

You're probably thinking of `JSON.stringify()`. `model.toJSON()` just returns a clone of the models attributes object.

So `model.toJSON()` isn't supposed to return a JSON-compatible data structure ?

It's supposed to return an object that is suitable for turning into JSON, but it won't convert any of items members. JSON.stringify relies on the toJSON functions of the members to serialize themselves.

Re: Revesiting Backbone.js View Rendering

#8
I agree that putting all that logic and template vars into a template is confusing. Hard to create mocks of what the HTML should actually be structured like. Im using Jade so I can be terse and pre-compiling the templates. While in my Backbone application, I apply DOM-like rendering with Plates.js.

Re: Revesiting Backbone.js View Rendering

#9
There are numerous benefits to using a presenter, or at least a "renderContext" object. Most conversion, formatting, predicates, and lazy attributes won't come through with toJSON(). The performance penalty is negligible compared to the benefit of testable presenter methods, logic out of the view, etc.

Performance isn't the only thing to consider.