1

I am upgrading my ember app from 3.9 to 3.10.

I started getting an error.

Assertion Failed: EmberObject.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().

I am not 100% sure, but after some tracking down, this piece of code seems to be causing this error (the computed property inside this mixin).

import Mixin from '@ember/object/mixin';
import { get, set, computed } from '@ember/object';
import { inject as service } from '@ember/service';
import DS from 'ember-data';

const { PromiseArray } = DS;

export default Mixin.create({
  ajax: service(),
  intl: service(),

  patientAnalysis: computed(function() {
    return this.getPatientAnalysis();
  }),

  getPatientAnalysis() {
    let _this = this;

    let patient = this.patientModel || this.patient;
    let intl = this.intl;

    if (get(patient, 'id')) {
      return PromiseArray.create({
        promise: new Promise(function(resolve, reject) {
          let url = `/analyses/patient/${patient.id}`;
          _this
            .get('ajax')
            .request(url)
            .then(json => {
              json.map(a => {
                set(a, 'statusIntlName', intl.t(`status.${a.statusId}`));
              });
              resolve(json);
            }, reject);
        })
      });
    }
  }

This mixin is being imported and used in another component, like so

import Analyses from 'ui/mixins/components/patient/analyses';
[...]
export default Component.extend(Analyses, {

I have read a few thread about this specific error, such as this one, but I can't figure out exactly how to make this work. I am not even sure why I am getting this error from upgrading to version 3.10 as this does not seems to have been deprecated or removed in that version.

I tried rewritting my mixin as the example from the ember doc, but without success.

If anyone could help me out figure out what exactly is going on and how to fix it, that would be appreciated.

oehaut
  • 129
  • 2
  • 9
  • I just tried replicating this on a mixin but I'm not seeing that error. Are you sure there's no other piece of code that's defining a computed property in a call to `create()`? – stevenelberger Nov 26 '19 at 20:04
  • Thanks for your feedback. The error message disappears when I remove the part that use this specific computed property in the .hbs file, so I am incline to believe this is what is causing it, yet I am not 100% sure. It's a rather big app and lots of component are call within the component that uses the mixin. It's hard to track down because the error message in the console with the stack trace refers only to ember internal files so I have no way of knowing which file is causing this. – oehaut Nov 26 '19 at 20:29
  • Does it even need to be a computed property? It's not watching any specific properties. Why not do `this.set('patientAnalysis, this.getPatientAnalysis());` in the `init()` hook? – stevenelberger Nov 26 '19 at 20:40
  • what is `getPatientAnalysis` doing? – Lux Nov 26 '19 at 22:44
  • @stevenelberger I am not exactly sure why that is. The developer that worked on that code is no longer with the company. I am new to ember so I am still learning. I was thinking that a computed property that is not watching any property is watching itself. Is that incorrect? I'll try to see if setting the `patientAnalysis` in the `init()` hook might be a fix for now. – oehaut Nov 27 '19 at 00:31
  • @Lux I've added the `getPatientAnalysis` method to my original post. – oehaut Nov 27 '19 at 00:32
  • @oehaut it's more like caching the result of the function, not so much watching itself. – stevenelberger Nov 27 '19 at 00:39

1 Answers1

1

If anyone ever find this thread with a common question, it turned out this error was caused by an npm package ember-cp-validations, that was used in a model.js file.

The error had been reported here for ember 3.10.

I could not make the proposed fix work, but upgrading to 3.11 fixed that issue.

oehaut
  • 129
  • 2
  • 9