File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ class Template {
1010 this . props . templatesConfig . compileOptions :
1111 { } ,
1212 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 )
1614 } ) ;
1715
1816 if ( content === null ) {
@@ -56,14 +54,19 @@ Template.defaultProps = {
5654 data : { }
5755} ;
5856
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 ;
6460 }
6561
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' ) ;
6770}
6871
6972module . exports = Template ;
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ function menu({
4343 item : null
4444 } ,
4545 templates = defaultTemplates ,
46- transformData = null ,
46+ transformData,
4747 hideWhenNoResults = true
4848 } ) {
4949 hierarchicalCounter ++ ;
You can’t perform that action at this time.
0 commit comments