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
# backbone | |
class PostView extends Backbone.View | |
className: 'post' | |
initialize: -> | |
@model.on('change:rating', @ratingChanged) | |
teardown: -> | |
@model.off('change:rating') | |
# custom plugin cleanup here | |
@remove() | |
render: -> |
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
# backbone | |
class PostView extends Backbone.View | |
className: 'post' | |
initialize: -> | |
@model.on('change:rating', @ratingChanged) | |
teardown: -> | |
@model.off('change:rating') | |
# custom plugin cleanup here | |
@remove() | |
render: -> |
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
$('#region').html((new PostView(model: model)).render()) # => will render blank in marionette | |
$('#region').html((new PostView(model: model)).render().$el) # => OK |
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
# backbone | |
class PostsView extends Backbone.View | |
initialize: -> | |
@collection.on('reset add remove', @render) | |
@collection.on('request', @startFetch) | |
teardown: -> | |
@collection.off('reset add remove', @render) | |
@collection.off('request' @startFetch) | |
render: -> | |
[email protected]() |
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 PostsWithPaginationView extends Marionette.CompositeView | |
itemView: PostView | |
emptyView: NoPostsView | |
itemViewContainer: '.items' | |
template: -> "<div class='items'></div><div class='pagination'>" | |
onRender: -> | |
# initialize pagination plugin |
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 PostDashboardView extends Marionette.Layout | |
template: -> "<div id='posts-region'></div><div id='new-post-region'></div>" | |
regions: | |
postsRegion: '#posts-region' | |
newPostRegion: '#new-post-region' | |
layout = new PostDashboardView | |
postsView = new PostsView(collection: new Posts) | |
newPostView = new NewPostView |
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 MainLayout extends Marionette.Layout | |
template: -> "<div id='main-region'></div>" | |
regions: | |
mainRegion: '#main-region' | |
# application startup | |
App.mainLayout = new MainLayout | |
$("body").html(@mainLayout.render().$el) | |
# somewhere in a router |
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
Application = new Marionette.Application | |
# this will replace your mainLayout | |
Application.addRegions | |
mainRegion: 'body' | |
Application.on 'initialize:after', -> | |
Backbone.history.start() | |
# OtherView definition |
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
Application.module 'Posts', (Posts, Application, Backbone, Marionete, $, _) -> | |
Posts.Router = Marionette.AppRouter.extend | |
appRoutes: | |
'post/:id': 'show' | |
class Posts.Controller | |
show: (id)-> | |
post = new Post(id: id) | |
view = new Posts.Views.Post(model: post) | |
Application.mainRegion.show(view) |
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
# define responses | |
Application.reqres.setHandler "post:new", -> | |
new Post | |
Application.reqres.setHandler "post:get", (id) -> | |
post = new Post(id: id) | |
post.fetch() | |
post | |