How to pass object into HyperFormula that I can then get access to in Custom Functions

Tags: #<Tag:0x00007f8b1cea5de0> #<Tag:0x00007f8b1cea5c50>

I am in the process of upgrading from Handsontable 8 to 9 and am attempting to refactor our code so that it works with HyperFormula.

I have managed to get a basic custom formula to work, however I need access to an external object from within the custom formulas.

How can I pass my object into the instance of hyperformula so that I can access it from my custom formula?

Hi @srichardson,
Unfortunately, I don’t grasp your idea.
Could you fork that demo at https://jsfiddle.net/5gs0uhef/ and put there your customization?

What I am trying to do is.

Create many different instances of Hyperformula.
this.hfInstance = HyperFormula.buildEmpty();

When I create these instances I want to somehow attach some data (that I want to be different for different instances) that will be accessible in the custom functions.

So far I have tried:
let plugin = this.hfInstance.getFunctionPlugin(‘HYPER’);
this.hfInstance.getConfig().ctrl = this;
plugin.ctrl = this;

In the custom function:
hyper(ast, state) {
let ctrl = Object.getPrototypeOf(this).constructor.ctrl;
console.log(ctrl.key);
return ‘Hyperformula’.length;
}

Unfortunately this will not work for me as there is only one instance of the custom formula so each instance of HyperFormula shares the same instance of the custom formula.

I hope that makes more sense?

Alright, so this issue is not related to the Handsontable but only Hyperformula. Support for HyperFormula and its integration is a separate service. Please reach out to our sales team at sales@handsontable.com to ask about available consulting services.
You can also ask HyperFormula’s community on GitHub Discussions: https://github.com/handsontable/hyperformula/discussions. I think it would be helpful for anyone who would like to investigate the problem if you could prepare the demo. You can use the following example to share your custom function: https://codesandbox.io/s/github/handsontable/hyperformula-demos/tree/1.1.x/basic-usage?from-embed=&file=/src/hyperformulaConfig.js