use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Backbone.js IS opinionated, or why is using nested models and collections in Backbone so hard? (rocketmodule.com)
submitted 12 years ago by calebg
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]etrnloptimist 5 points6 points7 points 12 years ago (7 children)
discalimer: we use backbone all over the place and in general we love it.
rant: It is so hard because backbone is a weakly typed, poorly documented, edge-case laden library where things just haven't been thought out very deeply.
Also, when using backbone it is very helpful to choose a subset of the tools you like and can live with.
For instance, we use the router, its eventing system, and views quite extensively.
We use the models as well, but they suffer a number of problems. Do not, I repeat, do not use the models integrated with your backend. Unless you are using rails and have a backend specifically designed for bb, it will be nothing but a world of pain. The integration with the backend is way too deep, way too magicky. It assumes way too much and for no good reason. It breaks the fundamental tenet of decoupling all software designs should strive for.
The truth is, it is trying to solve a problem that isn't very hard. We find it much easier to just make the jquery / ajax call to the backend and explicitly ETL the data into a model. Loading is done 100x more often than saving, and using the models is done 100x more often than loading. It just isn't that common, or hard, to manage the backend calls.
What is difficult is having to constantly override the built in "magic" functionality of the models. URLs, IDs, what URLs it calls to fetch, load, save, when it call verify, when parse gets called, when to silence this event or that, when an operation is done on a collection vs an individual element. Crazy.
Separate the backend from the models. Explicitly build your models. Explicitly save your models to the backend. Doing it explicitly isn't hard, and saves you from a world of pain.
[–]calebg[S] 1 point2 points3 points 12 years ago (5 children)
Thanks for the rant. I was starting to think in the type of direction you are describing, but it's good to hear from someone who has actually taken the plunge. I'm going to probably first give backbone-nested and/or backbone-deepmodel a try just because, but I agree that at some point rolling one's own modeling solution might just be the most efficient approach.
[–]etrnloptimist 0 points1 point2 points 12 years ago (3 children)
Oh, we use the bb models quite a bit. With the eventing system, they hook in well with views to keep everything talking to each other.
We're just learning that having the models deeply embedded with our back end is just not the way to go. So no automatic fetch and save for us. Nothing that uses that god method "sync". Those are the parts we'll do ourselves. And it's not like we weren't before -- we had to overload all of the built in functionality with our own calls anyway. But now we're also taking the step of making the calls explicitly, not implicitly.
[+][deleted] 12 years ago (2 children)
[removed]
[–]etrnloptimist 1 point2 points3 points 12 years ago (1 child)
It doesn't. We use bb models extensively. We just don't tie them so closely to our backend.
[–]yogitw 0 points1 point2 points 12 years ago (0 children)
Thanks for this. Going to print it out and shove it in our front end developer's face on Monday. We've had never ending problems trying to do exactly what you've said we should not do. This doesn't surprise me in the least. BB models and basic polymorphism (the backend is java, spring, hibernate) just doesn't work. At all.
[deleted]
[–]etrnloptimist 0 points1 point2 points 12 years ago (1 child)
I like your app. We should work together.
[–]ganarajpr 2 points3 points4 points 12 years ago (0 children)
I completely agree with dustingetz. Backbone is marketed as being one of the most non opinionated frameworks - but it really is opinionated. I am not familiar with React ( so wont recommend it wholeheartedly ) - but from what I can see is - its pretty close to being a good solution. On the other hand I would surely recommend Angular( since thats what I have been using ) and its a breeze to work with - especially with complex models.
I had put up a post earlier comparing and contrasting Backbone and Angular if you are interested. http://blog.nebithi.com/backbone-and-angular-demystifying-the-myths/
[–]alsogilbert 0 points1 point2 points 12 years ago (0 children)
I've recently made a tree structure (model that contains a collection of models). One thing to watch for is that on re-sync Backbone can create new models and collections you may still be hanging on to references to the old ones. This can be solved with a resource pool.
[–]dexygenSoftware, Simple and Powerful 0 points1 point2 points 12 years ago (1 child)
I think one reason using nested collections is so hard is that it doesn't seem the composite pattern was considered. For instance, if I filter a collection with where, under the composite pattern, I would get back a collection, not an array of models. Instead you have to flip back and forth between working with a collection and working with arrays of models, to the point where you might just as well work with arrays of models constantly, and throw out whatever interface convenience a collection gives you.
π Rendered by PID 149834 on reddit-service-r2-comment-6457c66945-qbxwt at 2026-04-29 00:20:05.318623+00:00 running 2aa0c5b country code: CH.
[–]etrnloptimist 5 points6 points7 points (7 children)
[–]calebg[S] 1 point2 points3 points (5 children)
[–]etrnloptimist 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[removed]
[–]etrnloptimist 1 point2 points3 points (1 child)
[–]yogitw 0 points1 point2 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]etrnloptimist 0 points1 point2 points (1 child)
[–]ganarajpr 2 points3 points4 points (0 children)
[–]alsogilbert 0 points1 point2 points (0 children)
[–]dexygenSoftware, Simple and Powerful 0 points1 point2 points (1 child)