Created
January 3, 2012 06:29
-
-
Save shawn42/1553782 to your computer and use it in GitHub Desktop.
Presenter First in Backbone.js
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
namespace "MyWidget.Expander", (exports) -> | |
template = JST["thingers/widget"] | |
exports.expand = (model) -> | |
template({ | |
'$.name': "#{model.get('first_name')} #{model.get('last_name')}" | |
}) |
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
namespace "MyWidget", (exports) -> | |
class exports.Model extends Backbone.Model | |
reload: => | |
@fetch | |
success: => | |
@trigger "reloaded" |
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
namespace "MyWidget", (exports) -> | |
class exports.Presenter | |
constructor: (@view, @model) -> | |
@view.bind "openClicked", => | |
@view.showLoading() | |
@model.reload() | |
@model.bind "reloaded", => | |
@view.render @model |
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
namespace "MyWidget", (exports) -> | |
class exports.View extends Backbone.View | |
events: | |
"click .open": "openClicked" | |
"click .save": "saveClicked" | |
openClicked: => | |
@trigger "openClicked" | |
saveClicked: => | |
@trigger "saveClicked" | |
render: (model) => | |
$(@el).html(MyWidget.Expander.expand(model)) | |
showLoading: => | |
# code for loading, turn on spinner, hide other stuff etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment