Last active
August 29, 2015 14:16
-
-
Save sapslaj/8306750ff9d71e8a59ff to your computer and use it in GitHub Desktop.
my take on MVC on the client
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
| class ArticleViewController extends ViewController | |
| initialize: (@params) -> | |
| @event.on('button.new-comment', 'click', @new_comment) | |
| @event.on('button.like', 'click', @like) | |
| new_comment: (event) -> | |
| comment_body = $('input.new-comment').val() | |
| comment = new Comment({body: comment_body}) | |
| if comment.save() | |
| flash_notice("Comment posted!") | |
| else | |
| flash_alert("There was an error posting your comment") | |
| like: (event) -> | |
| $like_container = $(".article-likes"). | |
| old_likes = parseInt($like_container.html()) | |
| article = Article.find(@params.id) | |
| article.like() | |
| likes = ++old_likes | |
| $like_container.html(likes) |
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
| class Article extends Model | |
| url: articles_path() | |
| like: () -> | |
| endpoint.vote({type: 'up'}) | |
| class Comment extends Model | |
| url: article_comments_path(window.active_controller.id) |
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
| Router.draw -> | |
| route articles_path(':id'), ArticleViewContoller |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment