Thanks.
Could you please confirm or clarify the below regarding child templates and components. I'm really starting to like the new concept, but I need to be sure of the below before taking design decisions.
I need to know if I have grasped the below correctly and if I missed anything important.
Child templates called with new syntax {{childTemplate.. }}
In the child html I get access to this, i.e. the current data context from parent
Example usage in child {{this.someItemData}} or simply {{someItemData}}
child templates does NOT have access to data from outer scopes in the parent
Example: {{../this.name}} will not work in the child
Helpers in child templates can access the complete report data structure via this
Example:
function() {
console.log(this.someDataFromTheRoot)
}
child templates can run scripts (i.e. beforeRender..)
Global helpers are accessible from child templates
In order to call a template which is not html recipe, I need to inject a recipe change into the childTemplate call.
Helpers in child templates gets an options object prepended as last argument in calls. The data.root in the options object is the root of the report dataset.
Components
In the component html I get access to this, i.e. the current data context from parent, i.e. same as child templates
Components does NOT have access to data from outer scopes in the parent. Same as child templates.
Helpers in components can NOT access the complete report data structure via this
But if I need data from elsewhere in the report data structure I can prepare a special data package to deliver to the component via a wrapper as in your examples.
Child components can NOT run scripts (i.e. beforeRender..)
Global helpers are accessible from components
Components are forced to html recipe, i.e. no need to inject recipe change as for child templates
Helpers in components gets an options object prepended as last argument in calls. The data.root in the options object is the current context from the parent, i.e. NOT the root from the report dataset.
Edit:
I just realized that I can use global helpers to get hold of the report data root even from a component which operates in another context. This could make components usable in every case where I used to have child templates. Does this make sense?
const jsreport = require('jsreport-proxy');
function getUserName() {
return jsreport.req.data.user.name;
}