A convenient way to validate or introspect an Ember data source using DS.RESTAdapter

Is there a convenient way to verify the source model data passed from external APIs to the Ember js and Ember Data models?

Something like a Ruby .inspect method. Is there any debugging tool for Ember data?

I want to make sure that I match JSON correctly when data hits my Ember models. But it would be convenient to see data structures before you need to explicitly define attributes in the model class on the Ember side.

I am wondering if something roughly looks like this pattern:

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

and then in my template, I can just upload it to the view as a property that passes the whole structure.

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

This is not for production, but only for detection purposes when trying to learn the implementation of the API and how it is served through the adapter.

+4
source share
1 answer

Two parts are being debugged, the first is checking the JSON payload in your browser console. (In Chrome, check the "Network" tab).

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

Your other options are to call object.toJSON() or object.serialize() to find out which view will be returned to the server in its current state.

+8
source

Source: https://habr.com/ru/post/1482655/


All Articles