File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
packages-exp/auth-exp/src/core/util Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
+ import { debugAssert } from './assert' ;
19
+
18
20
/**
19
21
* Our API has a lot of one-off constants that are used to do things.
20
22
* Unfortunately we can't export these as classes instantiated directly since
@@ -26,14 +28,18 @@ export interface SingletonInstantiator<T> {
26
28
new ( ) : T ;
27
29
}
28
30
29
- const persistenceCache : Map < unknown , unknown > = new Map ( ) ;
31
+ const instanceCache : Map < unknown , unknown > = new Map ( ) ;
30
32
31
33
export function _getInstance < T > ( cls : unknown ) : T {
32
- if ( persistenceCache . has ( cls ) ) {
33
- return persistenceCache . get ( cls ) ! as T ;
34
+ debugAssert ( cls instanceof Function , 'Expected a class definition' ) ;
35
+ let instance = instanceCache . get ( cls ) as T | undefined ;
36
+
37
+ if ( instance ) {
38
+ debugAssert ( instance instanceof cls , 'Instance stored in cache mismatched with class' ) ;
39
+ return instance ;
34
40
}
35
41
36
- const persistence = new ( cls as SingletonInstantiator < T > ) ( ) ;
37
- persistenceCache . set ( cls , persistence ) ;
38
- return persistence ;
42
+ instance = new ( cls as SingletonInstantiator < T > ) ( ) ;
43
+ instanceCache . set ( cls , instance ) ;
44
+ return instance ;
39
45
}
You can’t perform that action at this time.
0 commit comments