@@ -3,41 +3,27 @@ import matchDiscourseNode from "./matchDiscourseNode";
33
44const discourseNodeTypeCache : Record < string , DiscourseNode | false > = { } ;
55
6- const findDiscourseNode = (
7- uid = "" ,
8- nodes = getDiscourseNodes ( ) ,
9- ) : DiscourseNode | false => {
10- if ( typeof discourseNodeTypeCache [ uid ] !== "undefined" ) {
11- return discourseNodeTypeCache [ uid ] ;
12- }
13-
14- const matchingNode = nodes . find ( ( node ) =>
15- matchDiscourseNode ( { ...node , uid } ) ,
16- ) ;
17-
18- discourseNodeTypeCache [ uid ] = matchingNode || false ;
19- return discourseNodeTypeCache [ uid ] ;
20- } ;
21- export default findDiscourseNode ;
22-
23- export const findDiscourseNodeByTitleAndUid = ( {
6+ const findDiscourseNode = ( {
247 uid,
258 title,
26- nodes,
9+ nodes = getDiscourseNodes ( ) ,
2710} : {
28- uid : string ;
29- title : string ;
11+ uid ? : string ;
12+ title ? : string ;
3013 nodes ?: DiscourseNode [ ] ;
3114} ) : DiscourseNode | false => {
32- nodes = nodes || getDiscourseNodes ( ) ;
15+ if ( uid === undefined ) return false ;
3316 if ( typeof discourseNodeTypeCache [ uid ] !== "undefined" ) {
3417 return discourseNodeTypeCache [ uid ] ;
3518 }
3619
37- const matchingNode = nodes . find ( ( node ) =>
38- matchDiscourseNode ( { ...node , title } ) ,
39- ) ;
40-
41- discourseNodeTypeCache [ uid ] = matchingNode || false ;
42- return discourseNodeTypeCache [ uid ] ;
20+ const matchingNode =
21+ nodes . find ( ( node ) =>
22+ title === undefined
23+ ? matchDiscourseNode ( { ...node , uid : uid } )
24+ : matchDiscourseNode ( { ...node , title } ) ,
25+ ) || false ;
26+ discourseNodeTypeCache [ uid ] = matchingNode ;
27+ return matchingNode ;
4328} ;
29+ export default findDiscourseNode ;
0 commit comments