handsontable / handsontable/hyperformula

Call `runFunction` internally so it's easier to create custom functions

Open
#765 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

API Breaking Change Feature Impact: Medium Tech Debt To Be Discussed Verified
Dominant language
TypeScript
Stars
2.8k
Forks
171
Avg merge
1d 22h
Merged PRs (30d)
7

Description

Description

Currently each function calls runFunction with a callback. It does a lot of useful things and reduces the boilerplate (ie. argument validation) so it's natural that most implementations will want to use it. Also having meta properties for each functions kind of feels that validations is always done by the engine.

https://github.com/handsontable/hyperformula/blob/43071aa2a822ddcea04a7b1016fa3e8dda78e751/src/interpreter/plugin/ModuloPlugin.ts#L22-L30

Would become a simple

public mod(ast: ProcedureAst, formulaAddress: SimpleCellAddress, args: ModArgs): InternalScalarValue { 
  const { dividend, divisor } = args
 
  if (divisor === 0) { 
     return new CellError(ErrorType.DIV_BY_ZERO) 
  }

  return dividend % divisor 
} 

Interpreter already have access to AST, function meta and other properties, no need to create all this boilerplate code.

Other thoughts
  • We may have a flag to make the internal validation optional if someone want so implement everything on their own.
  • We should keep ast and formulaAddress, may be useful

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked src/interpreter/plugin/ModuloPlugin.ts example and trace how its callback reaches runFunction, including the current argument validation and function metadata handling. Compare that flow with the proposed mod implementation; done should leave a defined internal invocation model that preserves the useful context and supports custom functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.