Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the Ember Data Store from the console?

In Ember 2+, does anyone know how to get a reference to the Ember Store in order to troubleshoot Model mapping in the javascript console?

It was possible through App.__container__.lookup in Ember 1, but this doesn't exist anymore, and it's bloody hard to find documentation on this.

Thanks

like image 950
Fabien Benoit-Koch Avatar asked Oct 06 '15 13:10

Fabien Benoit-Koch


People also ask

How do I use Ember data?

Ember comes with a data management library called Ember Data to help deal with persistent application data. Ember Data requires you to define the structure of the data you wish to provide to your application by extending DS. Model . import DS from 'ember-data'; export default DS.

What is store in Ember JS?

The store contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates.

How do I open Ember app?

Create a New Application Once you've installed Ember CLI via npm, you will have access to a new ember command in your terminal. You can use the ember new command to create a new application. This one command will create a new directory called ember-quickstart and set up a new Ember application inside of it.


1 Answers

If you don't want to install a separate package to access your app in the console, you can do it through window.Ember.Namespace.NAMESPACES. For example, something you can run in the console to find your app instance is:

var app = Ember.A(Ember.Namespace.NAMESPACES).filter(n => {return n.name === 'your-app-name'})[0];

From here, you can access the store on the app's container as explained by @GJK

var store = app.__container__.lookup('service:store');

I used this for debugging an Ember app in production which didn't have its container registered on the window. I found it out by looking through the ember-inspector source code, since it always has access to the container.

https://github.com/emberjs/ember-inspector/blob/2237dc1b4818e31a856f3348f35305b10f42f60a/ember_debug/vendor/startup-wrapper.js#L201

like image 106
kevinyuliawan Avatar answered Sep 17 '22 19:09

kevinyuliawan