Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4869

Model returns a proxy array

$
0
0

I’m following the Full Stack Ember with Rails tutorial from embercasts.com. I know it’s pretty old, but it’s also really well crafted as a class. So I follow the tutorial while using ember-cli 5.4 to build the app. This works pretty well overall and seems actually helpful because it also allows me to see previous and current approaches at the same time (which are likely to be mixed in an existing codebase).

I got stuck trying to use the store though. With the tutorial, the Rails backend provides an authors route with this data array:

On Ember, the author route model calls the route like this:

import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class Author extends Route {
  @service store;

  model() {
    // return fetch('http://localhost:3000/authors').then((response) =>
    //   response.json(),
    // );
    return this.store.findAll('author');
  }
}

That’s the point where I’m stuck. Using fetch (as commented out) works. Trying to use findAll from the store, I still get the response from the authors route, but when I log the model from the author template, it returns a proxy array:

image

I have the application adapter defined as such:

import JSONAPIAdapter from '@ember-data/adapter/json-api';

export default class ApplicationAdapter extends JSONAPIAdapter {
  host = 'http://localhost:3000';
}

I also added an application serializer:

import JSONAPISerializer from '@ember-data/serializer/json-api';

export default class ApplicationSerializer extends JSONAPISerializer {}

But I have no idea how to adjust those, so the model returns valid data. On the tutorial it apparently still worked by just adding the adapter.

I’m also posting this at length here in Learning Team because there’s a couple of things that seemed like dead-ends to me trying to get started with ember-data and using the store:

  • I get this warning in the console, but I couldn’t find anything in the docs to follow up

  • the latest documentation on customizing adapters gives JSONAPIAdapter as the default adapter: Customizing Adapters - EmberData - Ember Guides.

  • Looking up the adapter on the API docs, it states this is a legacy approach though: JSONAPIAdapter - 5.3 - Ember API Documentation and I should use a handler and requestmanager instead. However, I didn’t find this approach explained in the ember docs

Thanks a lot for any feedback on this :hugs: :pray:

4 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4869

Trending Articles