Created
March 20, 2014 22:26
-
-
Save allouis/9675312 to your computer and use it in GitHub Desktop.
Model View Controller Psuedoshite
This file contains 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 BookModel = Model.extend({ | |
length: function () { | |
// take two for contents and index | |
return this.pages.length - 2; | |
} | |
}); | |
var BookController = Controller.extend({ | |
events: { | |
"click .save": "saveBook", | |
"change:saved": "render" | |
}, | |
saveBook: function () { | |
this.model.saved = true; | |
}, | |
render: function () { | |
this.view.render(this.model); | |
} | |
}); | |
var BookView = View.extend({ | |
template: "./views/book.hbs", | |
render: function (data) { | |
return mustache.render(this.template, data) | |
} | |
}); | |
function createBook (data) { | |
var model = BookModel.create(data); | |
var view = BookModel.create(); | |
var controller = BookController.create(model, view); | |
} | |
getBookViaAjax(function (data){ | |
createBook(data); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment