File tree 2 files changed +13
-10
lines changed
2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ class Template {
10
10
this . props . templatesConfig . compileOptions :
11
11
{ } ,
12
12
helpers : this . props . templatesConfig . helpers ,
13
- data : this . props . transformData ?
14
- getTransformData ( this . props . transformData , this . props . templateKey ) ( this . props . data ) :
15
- this . props . data
13
+ data : transformData ( this . props . transformData , this . props . templateKey , this . props . data )
16
14
} ) ;
17
15
18
16
if ( content === null ) {
@@ -56,14 +54,19 @@ Template.defaultProps = {
56
54
data : { }
57
55
} ;
58
56
59
- function getTransformData ( transformData , templateKey ) {
60
- if ( typeof transformData === 'function' ) {
61
- return transformData ;
62
- } else if ( typeof transformData [ templateKey ] === 'function' ) {
63
- return transformData [ templateKey ] ;
57
+ function transformData ( fn , templateKey , originalData ) {
58
+ if ( ! fn ) {
59
+ return originalData ;
64
60
}
65
61
66
- throw new Error ( 'transformData should be a function or an object' ) ;
62
+ if ( typeof fn === 'function' ) {
63
+ return fn ( originalData ) ;
64
+ } else if ( typeof fn === 'object' ) {
65
+ // ex: transformData: {hit, empty}
66
+ return fn [ templateKey ] && fn [ templateKey ] ( originalData ) || originalData ;
67
+ }
68
+
69
+ throw new Error ( '`transformData` must be a function or an object' ) ;
67
70
}
68
71
69
72
module . exports = Template ;
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ function menu({
43
43
item : null
44
44
} ,
45
45
templates = defaultTemplates ,
46
- transformData = null ,
46
+ transformData,
47
47
hideWhenNoResults = true
48
48
} ) {
49
49
hierarchicalCounter ++ ;
You can’t perform that action at this time.
0 commit comments