Last active
August 29, 2015 14:18
-
-
Save alexhidalgo/60c4eac3dab36b9aa360 to your computer and use it in GitHub Desktop.
Backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myToDoModel = Backbone.Model.extend({ | |
urlRoot: 'http://tiny-pizza-server.herokuapp.com/collections/alex-todo-items', | |
defaults: { | |
todo: null, | |
completed: true | |
}, | |
idAttribute: '_id' | |
}); | |
I am very proud of the Backbone model I created above for two reasons. Firstly, this model | |
represents the start of my exploration into backbone.js many months ago and reminds me of | |
how far I have come in such a short amount of time. Secondly, after learning several other | |
MVC frameworks like Angular.js I've grown to appreciate Backbone's less opinionated framework. | |
For example, when I create a model the Model.extend component allows me to get back to writing | |
good javascript instead of writing framework specific code. | |
I can create a default object and add a 'completed' key that I can toggle when a ToDo item is | |
clicked as well as a listener on the model change. | |
this.model.on('change:completed', this.onModelChanged); | |
The onModelChanged function and toggles a strike-text class on the clicked item. | |
onModelChanged: function() { | |
this.$el.toggleClass('strike-text'); | |
} | |
The above example may seem very trivial but for me it represents the start of a newly minted | |
developer's first steps into the world of MVC frameworks. Through these first steps I've been | |
able to understand the advantages and disadvantages of selecting one technology over another | |
and ultimately picking the right tool for the right job. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment