Skip to content

Commit

Permalink
refactor: widens check for decorators
Browse files Browse the repository at this point in the history
- otherwise embroider test scenarios fail with Error:
- "EmberObject.create no longer supports defining computed properties"
  • Loading branch information
Pixelik committed Oct 7, 2023
1 parent 8969d78 commit 68adad4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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
11 changes: 10 additions & 1 deletion addon/utils/deep-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { isDescriptor } from './utils';
import { isNone } from '@ember/utils';
import EmberObject, { defineProperty, set, get } from '@ember/object';

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

function isCP(value) {
return (
isDescriptor(value) ||
POSSIBLE_DECORATORS.includes(value?.constructor?.name)
);
}

export default function deepSet(
obj,
path,
Expand All @@ -29,7 +38,7 @@ export default function deepSet(
currObj = get(currObj, key);
}

if (isDescriptor(value)) {
if (isCP(value)) {
defineProperty(currObj, keyPath[lastKeyIndex], value);
} else {
set(currObj, keyPath[lastKeyIndex], value);
Expand Down

0 comments on commit 68adad4

Please sign in to comment.