Details
As part of work on plh a number of custom calc functions were required to simplify what would otherwise be very complex templating logic (#2127). These calculations are currently hardcoded in to the app, however we will want to come up with a better system for extending calc functions more generally.
A couple potential solutions
Config-based calculations
Could support a field in app config to provide custom calculations. The benefit of this would be ease of integration with the existing calc statements (just needs a line to import from app config) and using existing app compiler to support calcs written in typescript/esnext). Drawback would be harder to share functions across deployments
Flow-based calculations
Provide a custom flow type from which users can define calculations to be made globally available. The benefits of this would be more accessible to authors (?) and ability to share across deployments, drawbacks would be the calcs being one step further removed from runtime environment so would likely need custom parser/interpreter to ensure syntax is valid
Additional Considerations
How to support spec tests for deployment-based calcs (e.g. allow author to include test input/output in sheets, pass a spec.ts sheet etc.)
Confirm if possible for defined functions to have access to other functions (either defined, or potentially imported from a 3rd party lib? In the latter case would likely require bundling calc statements with all dependencies inlined)
How best to ensure functions written have valid syntax that works in target browsers (e.g. whether require additional linting and compilation, or if outside scope of the system)
How to handle sharing functions, e.g. prod issue from #2132
Details As part of work on plh a number of custom calc functions were required to simplify what would otherwise be very complex templating logic (#2127). These calculations are currently hardcoded in to the app, however we will want to come up with a better system for extending calc functions more generally.
A couple potential solutions Config-based calculations Could support a field in app config to provide custom calculations. The benefit of this would be ease of integration with the existing calc statements (just needs a line to import from app config) and using existing app compiler to support calcs written in typescript/esnext). Drawback would be harder to share functions across deployments
Flow-based calculations Provide a custom flow type from which users can define calculations to be made globally available. The benefits of this would be more accessible to authors (?) and ability to share across deployments, drawbacks would be the calcs being one step further removed from runtime environment so would likely need custom parser/interpreter to ensure syntax is valid
Additional Considerations