Ember:断言失败:EmberObject.create不再支持定义计算属性 [英] Ember: Assertion Failed: EmberObject.create no longer supports defining computed properties

查看:84
本文介绍了Ember:断言失败:EmberObject.create不再支持定义计算属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Ember 2.16版本,我们升级到3.8。版本升级后,我看到此错误,但无法确定错误的出处。在什么情况下会出现此错误。我看到了其中一篇:



解决方案

我想您不是逐步升级,而是直接从2.18升级到3.8,是吗?在3.2中,已弃用,如果已创建对象,则必须使用 defineProperty 定义计算属性。该功能已在3.5中删除。不再支持使用 set 或传递给 EmberObject.create()的对象上的属性动态设置计算属性。



此功能已在3.2中弃用,并在3.5中删除:

 将对象导入为EmberObject,{从} @ ember / object'计算得出; 

EmberObject.create({
foo:计算('bar',function(){
// ...
})
}) ;



  EmberObject.extend({ 
init(){
this._super(... arguments);

this.set('foo',compute('bar',function(){
// ...
}));
}
});

您应迁移到:

 将Object导入为EmberObject,{通过} @ ember / object'计算得出; 

EmberObject.extend({
foo:计算('bar',function(){
// ...
})
}) 。创造();



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

EmberObject.extend({
init(){
this._super(... arguments);

defineProperty(this,'foo' ,compute('bar',function(){
// ...
}));
}
});

此旧语法不是公共API。尽管Ember并未对公共API进行重大更改,但私有API可能随时更改。如果核心团队认为它们被广泛使用,则在下一个LTS版本之后,将它们弃用并删除。



通常,从LTS升级到LTS的步骤通常更安全,更轻松。在这种情况下,您不会错过有用的弃用消息。



也请查看输入弃用指南,即使如此,它在技术上也有些不足,在我看来应该有更多真实的例子。 / p>

I was on Ember version 2.16 and we upgraded to 3.8. After version upgrade I am seeing this error but not able to figure out from where the error is coming. In what scenarios will I get this error. I saw one of the post:

Dynamic computed properties in Ember.JS deprecated?

But couldn't figure out the same in my code.

解决方案

I guess you didn't upgrade step by step but moved from 2.18 to 3.8 directly, did you? In 3.2 a deprecation was added that computed properties must be defined using defineProperty if object is already created. The functionality was removed in 3.5. Setting a computed property dynamically using set or a property on an object passed to EmberObject.create() is not supported anymore.

This has been deprecated in 3.2 and removed in 3.5:

import Object as EmberObject, { computed } from '@ember/object';

EmberObject.create({
  foo: computed('bar', function() {
    // ...
  })
});

EmberObject.extend({
  init() {
    this._super(...arguments);

    this.set('foo', computed('bar', function() {
      //  ...
    }));
  }
});

You should migrate to:

import Object as EmberObject, { computed } from '@ember/object';

EmberObject.extend({
  foo: computed('bar', function() {
    // ...
  })
}).create();

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

EmberObject.extend({
  init() {
    this._super(...arguments);

    defineProperty(this, 'foo', computed('bar', function() {
      //  ...
    }));
  }
});

This old syntax wasn't a public API. While Ember does not introduce breaking changes to public API, private APIs may be changed at any time. If core team considers them as widely used, they are deprecated and removed after next LTS release. This was the case here.

Normally it's safer and easier to do a step to step upgrade from LTS to LTS. In that case you don't miss helpful deprecation messages.

Please also have a look into the entry in deprecation guide even so it's a little bit to technical and should have had more real world examples in my opinion.

这篇关于Ember:断言失败:EmberObject.create不再支持定义计算属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆