diff --git a/addon/-private/ember-internals.js b/addon/-private/ember-internals.js index 3e7292ef..727966bd 100644 --- a/addon/-private/ember-internals.js +++ b/addon/-private/ember-internals.js @@ -1,10 +1,10 @@ -import __EMBER_METAL__ from '@ember/-internals/metal/index'; +import * as EMBER_METAL from '@ember/-internals/metal/index'; + +const POSSIBLE_DECORATORS = ['AliasDecoratorImpl', 'ComputedDecoratorImpl']; export function getDependentKeys(descriptorOrDecorator) { - if (__EMBER_METAL__ && __EMBER_METAL__.descriptorForDecorator) { - let descriptor = __EMBER_METAL__.descriptorForDecorator( - descriptorOrDecorator, - ); + if (EMBER_METAL && EMBER_METAL.descriptorForDecorator) { + let descriptor = EMBER_METAL.descriptorForDecorator(descriptorOrDecorator); return descriptor._dependentKeys || [descriptor.altKey]; } else { return descriptorOrDecorator._dependentKeys; @@ -12,11 +12,14 @@ export function getDependentKeys(descriptorOrDecorator) { } export function isDescriptor(o) { - if (__EMBER_METAL__ && __EMBER_METAL__.isClassicDecorator) { - return __EMBER_METAL__.isClassicDecorator(o); - } else { - return ( - o && (typeof o === 'object' || typeof o === 'function') && o.isDescriptor - ); - } + const isClassicDecorator = + EMBER_METAL && + EMBER_METAL.isClassicDecorator && + EMBER_METAL.isClassicDecorator(o); + const _isDescriptor = + o && (typeof o === 'object' || typeof o === 'function') && o.isDescriptor; + const isOtherDecoratorImpl = POSSIBLE_DECORATORS.includes( + o?.constructor?.name, + ); + return isClassicDecorator || _isDescriptor || isOtherDecoratorImpl; } diff --git a/addon/-private/options.js b/addon/-private/options.js index d517ddb6..7b11f26b 100644 --- a/addon/-private/options.js +++ b/addon/-private/options.js @@ -4,8 +4,6 @@ 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) => { @@ -19,15 +17,12 @@ 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) - ); + const someOptionsAreDescriptors = optionKeys.some((key) => { + return isDescriptor(options[key]); }); // If any of the options is a CP, we need to create a custom class for it - if (someOptionsAreCPs) { + if (someOptionsAreDescriptors) { return OptionsObject.extend(options).create(createParams); } diff --git a/addon/utils/deep-set.js b/addon/utils/deep-set.js index 5424a512..8b251dd9 100644 --- a/addon/utils/deep-set.js +++ b/addon/utils/deep-set.js @@ -7,15 +7,6 @@ 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, @@ -38,7 +29,7 @@ export default function deepSet( currObj = get(currObj, key); } - if (isCP(value)) { + if (isDescriptor(value)) { defineProperty(currObj, keyPath[lastKeyIndex], value); } else { set(currObj, keyPath[lastKeyIndex], value);