Created
April 14, 2014 18:07
-
-
Save bradstewart/10670247 to your computer and use it in GitHub Desktop.
Batman.js View from Model accessor
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
# This started as "why can't data-partial also take a keypath," but I actually | |
# like having a Batman.View which can attach jQuery plugins and stuff for each | |
# activity that's added. | |
class App.FeedActivity extends Batman.Model | |
# ... | |
@accessor 'show', -> | |
@layout('show') | |
@accessor 'create', -> | |
@layout('create') | |
layout: (viewType) -> | |
html = "feed_activities/#{@get('type')}/_#{viewType}" | |
new App.FeedActivityView( source: html, activity: this ) | |
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
<!-- Somewhere in HTML where you want to display the activity feed --> | |
<ul data-foreach-activity="currentUser.feedActivities"> | |
<li data-view="activity.show"></li> | |
</ul> |
Although one thing to consider would be that the same Batman.View
is getting rendered over and over, right? You haven't run into any weirdness with that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is very cool! I've never thought of using something like this. I can imagine implementing something like this on model:
Then you could do stuff like