Skip to content

Instantly share code, notes, and snippets.

@wycats
Created February 27, 2012 04:49
Show Gist options
  • Save wycats/1921480 to your computer and use it in GitHub Desktop.
Save wycats/1921480 to your computer and use it in GitHub Desktop.
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>
@wycats
Copy link
Author

wycats commented Feb 27, 2012

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