2
votes

I received an error of Don't use Ember's function prototype extensions ember/no-function-prototype-extensions

and my line of code is this

import JSONAPIAdapter from 'ember-data/adapters/json-api';
import $ from 'jquery';
import config from 'appName/config/environment';

export default JSONAPIAdapter.extend({
  shouldReloadAll: function() {
    return false;
  },

  shouldBackgroundReloadRecord: function() {
    return true;
  },

  namespace: 'api/v1',
  host: window.location.origin,
  coalesceFindRequests: true,
  headers: function() {
    // Reference https://github.com/DavyJonesLocker/ember-appkit-rails/issues/220
    // Only set the X-CSRF-TOKEN in staging or production, since API will only look for a CSRF token on those environments
    let csrfToken;

    if (config.environment === 'staging' || config.environment === 'production') {
      csrfToken = $('meta[name="csrf-token"]').attr('content');
    }

    let authorizationToken = 'Token ' + this.currentSession.get('token');

    return {
      'X-CSRF-TOKEN':  csrfToken,
      'Authorization': authorizationToken
    };
  }.property().volatile(),

  handleResponse(status, headers, payload, requestData) {
    if (this.isInvalid(status, headers, payload)) {
      if (payload && typeof payload === 'object' && payload.errors &&
      typeof payload.errors === 'object') {
        return payload.errors = [payload.errors];
      }
    }

    return this._super(status, headers, payload, requestData);
  }
});

this was the line of code that my terminal is referring to .property().volatile(), I have looked on the google but I couldn’t find a similar examples to my work. Btw, I have updated my ember version from 1.13.13 to 3.1.0 and that is the reason why I received the error.

Please help me

1

1 Answers

4
votes

Ember's .property() is deprecated.

Instead of:

headers: function() {
  // ...
}.property().volatile(),

...do:

headers: computed(function () {
  // ...  
}).volatile(),

Also add the computed import at the top:

import { computed } from '@ember/object';

When you see these eslint errors, do a google search for the name of the rule, in this case ember/no-function-prototype-extensions. You'll find the description of the error and how to fix:

https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-function-prototype-extensions.md