So the notation of const {DataHelper} = customJS
is really just a shortcut for storing the customJS.DataHelper
into a variable of its own. Knowing that, we can redefine to not use this extraction at all and simply do:
Coffee:: `$= customJS.DataHelper.sumFunction('coffee') `
Some other variants which also should work, but personally I don’t think looks as nice:
`$= const DH = customJS.DataHelper; DH.sumFunction('coffee') `
`$= const {DataHelper} = customJs; DataHelper.sumFunction('coffee') `
`$= const {DataHelper:DH} = customJS; DH.sumFunction('coffee') `
For more information on how to destructure objects, see Destructuring assignment - JavaScript | MDN
Also note that as long as you can use semicolon to indicate the line shift, you can have as many “lines” of code within the inline dataviewjs query as you feel like.
One final note: When you do coffee:: `$= … `
, you don’t set the inline field to the value of that inline query, you set the field to the query itself, so if you use this in another context it can cause issues if that’s not a place where that query can be evaluated.
For example, if you use the first variant above, and then do `$= console.log(dv.current().coffee) `
, the output you’ll get in the console is `$= customJS.DataHelper.sumFunction(‘coffee’) `
.