File tree 1 file changed +16
-17
lines changed
xp-archive/client/versionSelector
1 file changed +16
-17
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { VersionReference } from 'shared/types' ;
3
3
4
- const contentCache : Record <
5
- string ,
6
- {
7
- component : React . ReactNode | null ;
8
- versions : VersionReference [ ] ;
9
- isOpen : boolean ;
10
- }
11
- > = { } ;
4
+ type VersionSelectorCacheItem = {
5
+ component : React . ReactNode | null ;
6
+ versions : VersionReference [ ] ;
7
+ isOpen : boolean ;
8
+ } ;
9
+
10
+ const DEFAULT_CACHE : VersionSelectorCacheItem = {
11
+ component : null ,
12
+ versions : [ ] ,
13
+ isOpen : false ,
14
+ } ;
15
+
16
+ const contentCache : Record < string , VersionSelectorCacheItem > = { } ;
12
17
13
18
export const setCachedVersionSelector = (
14
19
contentId : string ,
@@ -29,17 +34,11 @@ export const setCachedVersionSelector = (
29
34
} ;
30
35
} ;
31
36
32
- export const getCachedVersionSelector = ( contentId : string ) => {
33
- return (
34
- contentCache [ contentId ] || {
35
- component : null ,
36
- versions : [ ] ,
37
- isOpen : false ,
38
- }
39
- ) ;
37
+ export const getCachedVersionSelector = ( contentId : string ) : VersionSelectorCacheItem => {
38
+ return contentCache [ contentId ] || DEFAULT_CACHE ;
40
39
} ;
41
40
42
- export const clearCachedVersionSelector = ( contentId : string ) => {
41
+ export const clearCachedVersionSelector = ( contentId : string ) : void => {
43
42
if ( contentId in contentCache ) {
44
43
delete contentCache [ contentId ] ;
45
44
}
You can’t perform that action at this time.
0 commit comments