hyperformula icon indicating copy to clipboard operation
hyperformula copied to clipboard

Named Expressions doesn't have static methods

Open wojciechczerniak opened this issue 4 years ago • 0 comments

Description

From working on Custom Functions #317 looks like it's useful to have functions and languages registered globally (static) and locally (instance) so we can have both, shared registry and customized for each instance.

For Named Expression the use case may even be more common. We want to have expressions that are part of our application, i.e. TRUE / FALSE #5, and initialize an instance with the expressions that are part of the particular workbook.

Note:

It is possible to have a global variable with named expressions and registering them for each instance

const SharedNamedExpressions = [A, B, C, D]

const engine_1 = HyperFormula.buildEmpty({ 
  namedExpressions: [...SharedNamedExpressions, F, G, H] 
})
SharedNamedExpressions.forEach((expression) => {
  engine_1.addNamedExpression(expression)
})

const engine_2 = HyperFormula.buildEmpty({ 
  namedExpressions: [...SharedNamedExpressions, X, Y, Z] 
})
SharedNamedExpressions.forEach((expression) => {
  engine_2.addNamedExpression(expression)
})

Or, with #319:

const SharedNamedExpressions = [A, B, C, D]

const engine_1 = HyperFormula.buildEmpty({ 
  namedExpressions: [...SharedNamedExpressions, F, G, H] 
})

const engine_2 = HyperFormula.buildEmpty({ 
  namedExpressions: [...SharedNamedExpressions, X, Y, Z] 
})

But it would be a lot more elegant way to do it once

HyperFormula.addNamedExpression( [A, B, C, D] )

const engine_1 = HyperFormula.buildEmpty()

const engine_2 = HyperFormula.buildEmpty()

wojciechczerniak avatar Apr 25 '20 22:04 wojciechczerniak