Skip to content

Commit

Permalink
fix: handles computed decorators & prevents EmberObject.create Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelik committed Sep 18, 2023
1 parent 24b9998 commit b6fba28
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion addon/-private/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { isDescriptor } from '../utils/utils';
const { keys } = Object;
const OPTION_KEYS = '__option_keys__';

const POSSIBLE_DECORATORS = ['AliasDecoratorImpl', 'ComputedDecoratorImpl'];

const OptionsObject = EmberObject.extend({
toObject() {
return this[OPTION_KEYS].reduce((obj, key) => {
Expand All @@ -17,9 +19,15 @@ export default class Options {
constructor({ model, attribute, options = {} }) {
const optionKeys = keys(options);
const createParams = { [OPTION_KEYS]: optionKeys, model, attribute };
const someOptionsAreCPs = optionKeys.some((key) => {
return (
isDescriptor(options[key]) ||
POSSIBLE_DECORATORS.includes(options[key]?.constructor?.name)
);
});

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

Expand Down

0 comments on commit b6fba28

Please sign in to comment.