Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convenient way to inspect or introspect Ember Data source with DS.RESTAdapter

Is there a convenient way to inspect the raw model data being passed from external API to Ember js and Ember Data models?

Something like the Ruby .inspect method. Is there any debug tool like this in for Ember Data?

I want to make sure that I am properly mapping to the JSON when the data gets to my Ember models. But it would be handy to see the data structures before having to explicitly define the attributes in the model class on the Ember side.

I am wondering if there something roughly analogous to this pattern:

App.Somedata = DS.Model.extend({
  raw: this.inspect
});

and then in my template I could just dump it to the view as a property that conveys the whole structure.

  {{#each item in controller}}
    {{item.raw}}
  {{/each}}

This is not for production, but just for discovery purposes when trying to explore the implementation of an API and how it is served over the adapter.

like image 794
Gordon Potter Avatar asked Feb 16 '23 10:02

Gordon Potter


1 Answers

There are two parts to debugging this, the first would be to inspect the JSON payload in your browser console. (In Chrome, check the Network tab).

To check the internal data being stored in an EmberData object there are actually two places that are used for internal housekeeping object.get('_data') and object.get('_reference'). In your case I think the data is what you are hoping for.

Your other options are to call object.toJSON() or object.serialize() to see what the representation that would be returned to the server in the current state.

like image 125
Bradley Priest Avatar answered May 07 '23 08:05

Bradley Priest