(re)load data from "outsite" with ember-data 1.0 beta


#1

Hi,

we have an application where we use Ember-data with the DS.RESTAdapter. We have a “widget” controller where we load data in the init() function.

First we had: this.content = App.ModelName.find() to load al the data.

Now for 1.0 beta we changed this to

var that = this; 
this.get('store').find('modelName').then(function(content) {
  that.set('content', content);
});

This all works fine. But we have a socket connection where we push the identifiers of all objects that changed server site. In 0.13 we then could do this to (re)load the data for these objects and through the normal data binding all is updated.

var _object = App.ModelName.find(id);
if(_object._data) _object.reload(); # when data present force a reload from the server

But the find() functions on a object isn’t there anymore. So we are searching for a way to access the store and trigger a reload of the object. But I can not find a way to access the store from the outsite scope.

What is the best way to solve this?


#2

If i’m understanding you correctly, your websockets code is running outside of the context of the Ember application where you don’t have a way to get a hold of the store. As you’ve inferred, you need to initialize that code somewhere that does. An application initializer may be a good place for this.

Ember.Application.initializer
  name: 'websocketsInitializer' #call it whatever makes sense
  after: 'store' #we want this to initialize after the store initializer has run
  initialize: (container) ->
    store = container.lookup('store:main')
    #initialize websockets stuff here now that you have the store available

You could also kick this off from you application controller.

I hope i’ve understood this correctly and that it helps.


#3

tnx. That worked.

Yet another functionality of Ember to explore :smile: