-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache module info getters before output generation (#5438)
* Cache module info getters before output generation * Update ExternalModule.ts * Update Module.ts * Update src/utils/getter.ts Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com> * Remove safeguards as we are converting a hand-picked list --------- Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com> Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
fffaede
commit 41ba566
Showing
4 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function cacheObjectGetters<T, K extends PropertyKey = keyof T>( | ||
object: T, | ||
getterProperties: K[] | ||
) { | ||
for (const property of getterProperties) { | ||
const propertyGetter = Object.getOwnPropertyDescriptor(object, property)!.get!; | ||
Object.defineProperty(object, property, { | ||
get() { | ||
const value = propertyGetter.call(object); | ||
// This replaces the getter with a fixed value for subsequent calls | ||
Object.defineProperty(object, property, { value }); | ||
return value; | ||
} | ||
}); | ||
} | ||
} |