2
votes

With ember data, where is the best place to create the store.

Should I create it before I create the application object?

Should I create it as a property of the application object, e.g.

app = Ember.Application.create()
app.set('Store', App.Store.create())

I've been working with Ember for a while but this has often been a point of confusion for me.

What is the recommended approach?

The main problems I have is when it comes to tests. Destroying the store is problematic.

1

1 Answers

4
votes

Create a Store (capital s) property on your application namespace before the app initializes. Ember Data registers an injection that will automatically instantiate the store as well as give both the router and controllers access to it. For example.

App = Ember.Application.create();
App.Store = DS.Store.extend({
  adapter: DS.RESTAdapter.extend()
});

And later on you can do things like this.

router.get('store');
router.get('userController.store');