mardi 20 mars 2018

Why does Ember 3.1 have trouble dealing with Ember Data proxied objects?

I have an ES6 class in Ember 3.1 which is being handed an ember data object called certifciate. I would like to be able to call .reload() on that certificate as follows:

  @action
  showCertificateInfo(this: DomainCard, certificate) {
    this.setProperties({
      isShowingCertificateModal: true,
      selectedCert: certificate,
    })
    certificate
      .reload()
      .then(() => {
        this.set('isShowingCertificateModal', true)
      })
      .catch(e => {
        // TODO: handle this
      })
    }

However, if I do this, then Ember gives the following error/warning:

Assertion Failed: You attempted to access the 'reload' property 
(of <DS.PRomiseObject:ember796>)... However in this case4 the object 
in quetstion is a special kind of Ember object (a proxy). Therefore,
it is still necessary to use` .get(‘reload’)` in this case.

If I do as the code suggests and call .get('reload') instead, then I get an internal Ember error that this is not defined when calling this._internalModel. I get the same error when doing:

const reload = certificate.get('reload').bind(certificate)
reload().then()
...

What do I need to do to be able to reload this ember data object properly?




Aucun commentaire:

Enregistrer un commentaire