TweetKnock JavaScriptMVC's Back Out
I’ve read a lot of articles and tweets comparing JavaScriptMVC, BackboneJS, and KnockoutJS. A lot of good things can be said about these frameworks. Backbone is largely similar to JavaScriptMVC’s MVC components, and Knockout has a really amazing observable system.
But it gets under my skin when people compare how easy it is to ‘get up to speed on’ these frameworks. JavaScriptMVC’s API is, in my opinion, just as simple as any other framework. Here’s how you setup a model to talk to your server:
$.Model('Todo',{
findAll : '/todos',
findOne : '/todos/{id}',
create: 'POST /todos',
update: 'PUT /todos/{id}',
destroy : 'DELETE /todos/{id}'
},{})
Here’s how you can findAll those todos and render them in a list using an ejs template:
Todo.findAll(function(todos){
$('#todos').html('todoList.ejs',todos);
});
Here’s a jQuery widget that listens for clicks on those todos and delete them from the server:
$.Controller('Todos',{
'a.destroy click' : function(el){
var todoEl = el.closest('.todo')
todoEl.model().destroy(function(){
todoEl.remove();
})
}
});
$('#todos').todos();
It’s simple. But, JavaScriptMVC does have a much longer ‘ramp’ up speed than these frameworks simply because it’s got almost everything. Take a look at its core features. It’s getting started guide alone takes you through:
- creating files and folders for your app
- writing code for it
- documenting it
- testing it
- building a production build
Many apps might not need all this. But I promise that if yours does, you and your team’s total ramp-up speed will be far faster with JavaScriptMVC than some piecewise collection.
I wouldn’t try to dissuade anyone from trying out any other library or framework. Just make sure you are comparing apples to apples. Not an apple to an orchard. Of course, if you just want a few apples, you can download just JMVC’s core MVC parts.