ember-cp-validations: Error when using computed values with ember-decorators-polyfill installed or Ember 3.10.0
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.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 4
- Comments: 29 (9 by maintainers)
@offirgolan what they’re saying is correct, the goal in the near future is to eliminate all of the the intimate/private APIs for computed properties. There are a few that have to remain around for the time being, but where there are alternatives we’re trying to push people towards them. I think extending is a reasonable alternative, and it will be the only alternative in the future with native classes, so I would recommend moving to something like this now, or not using computed properties.
Any additional thoughts on how to update this addon?
Decorators have shipped in 3.10 which will cause a couple of issues if you are using a computed property in a validator, to disable it for example.
EmberObject.create no longer supports defining computed properties.
issuemodel.<someAttr>
will need to be explicitly added todependentKeys
@jderr-mx Did you ever find a solution to this? @offirgolan Any ideas how to fix?
This is very expensive to do and I would prefer to fix the underlying isDescriptor utility method instead if at all possible.
For 3.10 I had to update
addon/-private/options.js
to make the constructor always extend the object.