forked from adopted-ember-addons/ember-cp-validations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: isDescriptor() logic & syntax
- Loading branch information
Nicolas Martinos
committed
Oct 11, 2023
1 parent
68adad4
commit d2fe360
Showing
3 changed files
with
19 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
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; | ||
} | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters