Skip to content

Instantly share code, notes, and snippets.

@drogus
Created August 30, 2012 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drogus/3529680 to your computer and use it in GitHub Desktop.
Save drogus/3529680 to your computer and use it in GitHub Desktop.
Array for ember data that allows extending with findQuery results
DS.ExpandableRecordArray = DS.RecordArray.extend
isLoading: false
load: (array) ->
@set 'isLoading', true
self = this
observer = ->
if @get 'isLoaded'
content = self.get 'content'
array.removeObserver 'isLoaded', observer
array.forEach (record) ->
clientId = record.get 'clientId'
unless content.contains clientId
content.pushObject clientId
@set 'isLoading', false
array.addObserver 'isLoaded', observer
array = DS.ExpandableRecordArray.create
type: App.Todo
content: Ember.A([])
store: App.store
array.load App.store.find(App.Todo, {})
array.load App.store.find(App.Todo, {some_param: true})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment