-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Adds support for parenless attr, belongsTo, and hasMany
- Loading branch information
Chris Garrett
committed
Aug 20, 2019
1 parent
2dff029
commit f53f953
Showing
8 changed files
with
114 additions
and
3 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { gte } from 'ember-compatibility-helpers'; | ||
|
||
export type DecoratorPropertyDescriptor = PropertyDescriptor & { initializer?: any } | undefined; | ||
|
||
export function isElementDescriptor(args: any[]): args is [object, string, DecoratorPropertyDescriptor] { | ||
let [maybeTarget, maybeKey, maybeDesc] = args; | ||
|
||
return ( | ||
// Ensure we have the right number of args | ||
args.length === 3 && | ||
// Make sure the target is a class or object (prototype) | ||
(typeof maybeTarget === 'function' || (typeof maybeTarget === 'object' && maybeTarget !== null)) && | ||
// Make sure the key is a string | ||
typeof maybeKey === 'string' && | ||
// Make sure the descriptor is the right shape | ||
((typeof maybeDesc === 'object' && | ||
maybeDesc !== null && | ||
'enumerable' in maybeDesc && | ||
'configurable' in maybeDesc) || | ||
// TS compatibility | ||
maybeDesc === undefined) | ||
); | ||
} | ||
|
||
export function computedMacroWithOptionalParams(fn) { | ||
if (gte('3.10.0')) { | ||
return (...maybeDesc: any[]) => (isElementDescriptor(maybeDesc) ? fn()(...maybeDesc) : fn(...maybeDesc)); | ||
} else { | ||
return fn; | ||
} | ||
} |
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