Skip to content

Instantly share code, notes, and snippets.

@leepfrog
Created January 10, 2013 07:31
Show Gist options
  • Select an option

  • Save leepfrog/4500204 to your computer and use it in GitHub Desktop.

Select an option

Save leepfrog/4500204 to your computer and use it in GitHub Desktop.
App.BookIndexController = Ember.ArrayController.extend
content: [] # array of books
proxies: {} # proxy cache for books
# Creates and caches a proxy that will wrap around our book
createProxy: (book, id) ->
@proxies[id] = BookProxy.create
content: book
controller: this
# This wraps each book in our book array w/ a proxy
objectAtContent: (index) ->
book = @get('arrangedContent').objectAt(index)
if book?
book_id = book.get('id')
if @proxies[book_id] then @proxies[book_id] else @createProxy(book,book_id)
BookProxy = Em.ObjectProxy.extend
isSelected: (->
@get('controller.selectedBook') == @get('content')
).property('controller.selectedBook')
# Other stuff goes here for augmenting the book model / behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment