UselessPickles / ts-enum-util

Strictly typed utilities for working with TypeScript enums
MIT License
231 stars 6 forks source link

Use WeakMap to cache EnumWrapper instances #2

Closed UselessPickles closed 6 years ago

UselessPickles commented 6 years ago

Use a WeakMap instead of a Map to cache EnumWrapper instances. This ensures that EnumWrapper instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks), and should also improve cache lookup performance.

Because WeakMap solves the concern about memory leaks when ts-enum-util is used on temporary enum-like objects, there's really no need to opt out of caching any more. So the following API changes were made:

The $enum function was also slightly optimized by making it a direct reference to EnumWrapper.getCachedInstance.

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 112


Totals Coverage Status
Change from base Build 108: 0.0%
Covered Lines: 111
Relevant Lines: 111

💛 - Coveralls