Javier Cadiz
Javier Cadiz

Reputation: 12536

DEPRECATION: The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one

At the moment of this question i'm running the latest Ember and Ember Data versions.

enter image description here

I'm working with the DS.RESTAdapter calling for a /places this way:

this.store.findAll('place');

The model only have a name attribute name: DS.attr('string') The JSON is the following:

{
  places: [
    {
      id: 1,
      name: "San Francisco"
    },
    {
      id: 2,
      name: "Havana"
    }
  ]
}

I made the template and with the corresponding each and everything shows up and works so far but i get a deprecation warnings that tells the following:

DEPRECATION: The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "destination" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.

I don't know exactly what's the best approach to solve this warning. I'm new to ember so any further explanation will be fine. Thanks in advance.

Upvotes: 13

Views: 2342

Answers (3)

Daniel
Daniel

Reputation: 18680

To answer @Eric Wilson question:

I will award the bounty to an answer that contains the necessary details to override the shouldReloadAll function. In other words, I can't figure out what to do with these snippets of code.

First use:

ember g adapter application

Then go to newly-generated app/adapters/application.js and replace code with:

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  shouldReloadAll() {
    return true;
  }
});

You're done. Demo on Ember Twiddle.

Returning true from shouldReloadAll function basically instructs Ember to re-fetch models each time you call findAll method and fire request to your backend.

If you know that this data won't change, for example, for next 2 minutes then you can implement some logic in shouldReloadAll which would prevent Ember from firing unnecessary request (like check if 2 minutes passed, if not then prevent request - return false).

See DS.Adapter.shouldReloadAll method documentation for more context.

Upvotes: 5

Knucklehead
Knucklehead

Reputation: 97

To comply with the new default behavior, override shouldReloadAll like this:

function shouldReloadAll( store, snapshot ) {
    return !store.peekAll( snapshot.type.modelName ).length
}

Upvotes: 5

Timmie Sarjanen
Timmie Sarjanen

Reputation: 411

Set shouldReloadAll() { return true; } in your application adapter and the warning goes away and the current default behavior is the same.

Upvotes: 8

Related Questions