so a couple of thoughts:
(link: https://github.com/emberjs/data/issues/190 )
how to listen to new records in the data warehouse
normal Model.find () / findQuery () will return AdapterPopulatedModelArray, but this array will stand by itself ... it does not know that something new has been loaded into the database
a Model.find () without parameters (or store.findAll ()) will return ALL FilteredModelArray records to you, and ember data will "register" it in the list, and any new records loaded into the database will be added to this array.
calling Model.filter (func) will provide you with a FilteredModelArray, which is also registered in the store ... and any new records in the store will call ember-data for "updateModelArrays", that is, it will call your filter function with a new record, and if you return true , then it will be attached to your existing array.
SO WHAT I FINISHED: did right after creating the store, I call store.findAll (), which returns me an array of all the models for the type ... and I attach it to the repository ... then somewhere else in the code, I can add ArrayObservers to these lists .. something like:
App.MyModel = DS.Model.extend() App.store = DS.Store.create() App.store.allMyModels = App.store.findAll(App.MyModel) //some other place in the app... a list controller perhaps App.store.allMyModels.addArrayObserver({ arrayWillChange: function(arr, start, removeCount, addCount) {} arrayDidChange: function(arr, start, removeCount, addCount) {} })
how to push the model to one of these "immutable" arrays:
First of all, pay attention: all Ember-Data Model instances (records) have the clientId property ... which is a unique integer that identifies the model in the data warehouse cache, does it have a real server-id yet (example: immediately after creating the Model .createRecord).
therefore, AdapterPopulatedModelArray itself has the "content" property ... which is an array of these clientId identifiers ... and when you iterate through AdapterPopulatedModelArray, the iterator iterates over these clientId and passes you all the model instances (records) that are mapped to each client.
SO WHAT I DID (this does not mean that it is βrightβ!) To watch these findAll arrays and insert a new clientId into the content AdapterPopulatedModelArray ... SOMETHING LIKE property:
arrayDidChange:function(arr, start, removeCount, addCount){ if (addCount == 0) {return;} //only care about adds right now... not removes... arr.slice(start, start+addCount).forEach(function(item) { //push clientId of this item into AdapterPopulatedModelArray content list self.getPath('list.content').pushObject(item.get('clientId')); }); }
what can I say: βits work for meβ :) will it be split into the next update of the ember data? completely possible