-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work around not having the default empty object value from TS constru…
…ctor anymore
- Loading branch information
Showing
3 changed files
with
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const get = (type: any) => Reflect.getMetadata(key, type) ?? {}; | ||
|
||
const set = | ||
(value: any): PropertyDecorator => | ||
({ constructor: type }, propertyKey) => | ||
Reflect.defineMetadata(key, { ...get(type), [propertyKey]: value }, type); | ||
|
||
/** | ||
* A helper to get/set default values for classes. | ||
* Usage of this is discouraged in favor or more common practices. | ||
* This is mostly useful with abstractions. | ||
* Note that the defaults aren't automatically applied, this just holds | ||
* a container for them - They need to be fetched explicitly. | ||
*/ | ||
export const DefaultValue = { Get: get, Set: set }; | ||
|
||
const key = 'DefaultValue'; |
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