5 ms·
Show HN: I rewrote the Backbone.js Todo example
- siong1987 14y agoFor those who wonder how to build a Todo app in different javascript frameworks, you should definitely check out TodoMVC: http://addyosmani.github.com/todomvc/ http://addyosmani.github.com/todomvc/
- tosh 14y agoIt is a great site to check out different frameworks/approaches/philosophies. There is also an example for the todo app written in Dart using Web Components (similar to AngularJS) https://github.com/dart-lang/web-ui/tree/master/example/todomvc https://github.com/dart-lang/web-ui/tree/master/example/todo...
- mtrimpe 14y agoI'd suggest keeping in mind that TodoMVC hides how well the different frameworks perform with more complex (nested / inter-dependent) models though.
- nirvanatikku 14y agoNice documentation! Hadn't seen docco before; pretty neat doc generator. http://jashkenas.github.com/docco/ http://jashkenas.github.com/docco/
- philipwalton 14y agoAn example of the TODOs app with AMD is great! Now if only Backbone and Underscore would support AMD natively so you wouldn't need to Shim them.
- pneftali 14y agothere's always the amd-version of those here -> https://github.com/amdjs https://github.com/amdjs
- peter_l_downs 14y agoMaybe I'm misreading it, but it looks like you might have a typo in todos-router.js. See http://ahamlett.com/Backbone.localStorage/docs/todos-router.html http://ahamlett.com/Backbone.localStorage/docs/todos-router...., in the call to define() -- your dependencies are 'jquery' and 'backbone', but you take in '_' and 'Backbone'. Then, you later use '$'.
- welder 14y agoGood catch! It's fixed now. Keep the feedback coming! I'm particularly interested in design pattern suggestions.
- minikomi 14y agoVery nice idea. Good stuff! Should todolist.js be in a folder called Collections?
- welder 14y agoMaybe, I like to pretend it's a flask app and lump anything that models an api resource in the same folder. After all, a Collection is just an array of Models. What do you think? Probably should be named TodoCollection.js either way.
- minikomi 14y agoYeah, I've been keeping them separate, if only to make it easier to decide what kinds of functions go where.
- polychrome 14y agoYeah, I have to agree with keeping them separate and renaming it to TodoCollection.js. As someone looking at this for the first time, even after breezing over the code that was my immediate question: wait, where was the collection again?
- dimadima 14y agoThanks for posting this!
- sneak 14y agoI don't know how to say this without sounding like a dick, so apologies in advance. For fuck's sake, people - it's 2013. Get with the CoffeeScript program already.
- gkoberger 14y agoCoffeeScript isn't for everyone. I've used it, and I really prefer JavaScript. While there's some nice things about it, I personally find it to be incredibly unreadable. (Sure, you can write a mix of JS and CS, but that just seems wrong.) (That being said, I love LESS and can't imagine writing pure CSS, so I do understand how you feel.)
- andrewingram 14y agoSame here, I've used CoffeeScript on a biggish project and found myself longing to return to JavaScript.
- welder 14y agoMaybe my mind is too low-level for CoffeeScript... I prefer seeing var and being verbose.
- camus 14y agoand fix javascript by hand ... i prefer working on my business logic.
- pilgrim689 14y ago"working on my business logic" and "preferring explicit languages" are not mutually exclusive -_-
- polychrome 14y ago"I don't know how to say this without sounding like a dick, so apologies in advance." I'm curious why you did not use CoffeeScript when you updated this example?
- camus 14y agoI think the todo app is not good enough to compare different frameworks maybe we should come up with another app , that has a least some ajax and a more complex business logic to handle.
- welder 14y agoI totally agree. The only problem is hosting the api for a new example app. I could write an example app using the github api requiring OAuth. Does anyone know of a public api that allows modifying resources without login?
- paduc 14y agoThis comment has nothing to do with Backbone but we tend to use the sugar syntax for defines: define(function(require){ var whatever = require('dependency'); }); instead of define([ 'dependency', ], function(whatever) { }); We do this because it's way more readable for files with numerous dependencies. Also, we make Backbone, $ and _ globals so we don't have to inject them in every single module.
- Cthulhu_ 14y ago> Also, we make Backbone, $ and _ globals so we don't have to inject them in every single module. We don't; we explicitly define every dependency, always, so that it does not make any assumptions about the environment it runs in (a webpage with jquery / underscore included via script tags, for example). Second, our end-product is a single .js with Backbone and some other dependencies all combined into it. (we're not allowed to use a CDN)
- paduc 14y agoThat sounds like a pretty good reason not to make those globals. We did it when we realized 100% of our modules had those three dependencies. Haven't found a drawback yet.
- twalling 14y agoI like the fresh take on organizing the example but I disagree with the 2nd bullet point. Jérôme Gravel-Niquet's example encapsulates everything inside of an anonymous function and I don't see any var leakage into the global namespace.