adopted-ember-addons / adopted-ember-addons/ember-cp-validations

Error when using computed values with ember-decorators-polyfill installed or Ember 3.10.0

未关闭
#635 29 条评论 4 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
439
派生
172
PR 合并指标
30 天内没有已合并 PR

描述

### Environment

- Ember Version: 3.6 with ember-decorators-polyfill or current 3.10.0-beta.2
- Ember CLI Version: 3.6
- Ember CP Validations Version: 3.5.5 and 4.0.0-beta.7

### Steps to Reproduce
I tested this with my work app at 3.8 and used the dummy app at 3.6 and installed ember-decorators-polyfill

Having validations that use a form of `computed` for their value.
models/user-detail.js - dob validator
```
after: computed(function() {
return moment()
.subtract(120, 'years')
.format('M/D/YYYY');
}).volatile(),
```
Results in the error:
Error: Assertion Failed: EmberObject.create no longer supports defining computed properties. Define computed properties using extend() or reopen() before calling create().

I tracked it in the debugger to
-private/options.js in the constructor for the Options class
```
constructor({ model, attribute, options = {} }) {
const optionKeys = keys(options);
const createParams = { [OPTION_KEYS]: optionKeys, model, attribute };

// If any of the options is a CP, we need to create a custom class for it
if (optionKeys.some(key => isDescriptor(options[key]))) {
return OptionsObject.extend(options).create(createParams);
}

return OptionsObject.create(createParams, options);
}
```

I chatted with Chris Garrett in e-decorators on the Ember discord. He suggested that the computed properties were not being detected and that you would always need to extend. He said the same error would apply with Ember 3.10 and I have been able to reproduce it with the dummy app and ember-source upgraded to 3.10.0-beta.2

I attempted update the code to always return `OptionsObject.extend(options).create(createParams);`

Which got rid of the error but then some of the tests were not passing.

Please let me know if there is more detail that I can provide.

贡献指南

打开贡献指南

调研方向

Start by reproducing the computed-value validation in the dummy app with the listed Ember versions, then inspect private/options.js and the Options constructor. Review the existing tests that failed after always extending OptionsObject; done means the assertion no longer occurs and the full existing test suite passes.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
frontend, web-dev
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。