Created
February 27, 2012 04:49
-
-
Save wycats/1921480 to your computer and use it in GitHub Desktop.
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
Viz.WidgetsController = Ember.ArrayController.extend | |
init: -> | |
@refresh() | |
setInterval (=> @refresh), 5000 | |
refresh: -> | |
$.ajax | |
url: @get('src'), | |
type: "GET", | |
context: this, | |
success: this.loadData | |
loadData: (visualizer) -> | |
@set 'template', Ember.Handlebars.compile(visualizer.template) | |
@set 'content', visualizer.widgets | |
Viz.Widgets = Ember.CollectionView.extend | |
init: -> | |
@_super() | |
@set 'content', Viz.WidgetsController.create(src: @get('src')) | |
createChildView: (viewClass, attributes) -> | |
attributes.template = @getPath('content.template') | |
attributes.templateContext = attributes.content | |
@_super(viewClass, attributes) | |
# <h1>Surrounding HTML</h1> | |
# <div>{{view Viz.Widgets src="/visualizers/hosts"}}</div> |
This example was for a very specific case where dynamically loaded templates based on a view attribute were required. You could probably have a separate state manager for the data loading per view, but it seems like overkill here. I'm not sure if dynamic controllers generated by views is a perfect pattern, but on occasion I use it and it works nicely.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@wycats, did you recommend to include the logic of managing data (as store fetching) on the Controllers, or this logic is recommended to be included in the StateManagers, acting the Controllers only as view data objects.