-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!: template-calc service #2793
Conversation
const { thisCtxt, globalFunctions, globalConstants } = calcContext; | ||
const mergedContext = { ...thisCtxt, ...evalContext }; | ||
return evaluateJSExpression(calcExpression, mergedContext, globalFunctions, globalConstants); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note - this method has been adapted from the template-variable service which currently handles evaluation. It will be used as part of the refactor in #2772
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted about the breaking changes. I normally use the examples in the debug
deployment as a starting point for writing @calc()
statements, so it's plausible I never realised @calc(window.calc. ...)
even existed as a valid syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @chrismclarke, looks good and can confirm the tests are passing
PR Checklist
Breaking Changes
The
window.calc
accessor has been marked as deprecated, e.g.@calc(window.calc.pick_random([1,2,3]))
Any methods available via
window.calc.xxxx
are already available directly, e.g.@calc(pick_random)
, so use that way instead.I can't see any examples of this being used in example_calc, so assume this is mostly a legacy behaviour anyways
The only method that should still be accessed via the window is the
date_fns
utility library, e.g.@calc(window.date_fns.add_days(...))
Description
Changes merged from #2772 for easier review, a handful of updates to the
template-calc.service
which handles authored@calc(...)
statements, specificallyAuthor Notes
Beyond the marked deprecation, there shouldn't be any breaking changes or functional testing required.
Review Notes
The code doesn't introduce changes to how calc statements are evaluated (for follow-up), so more just to confirm test cases behave as expected
Dev Notes
The changes introduced here should be mostly non-functional (testing, mock and type-safety improvements). The additional method included is designed for future integration in #2772, so in itself shouldn't be breaking.
Whilst diving into the service I did notice a handful of inconsistencies and clunky areas within the code, however have avoided larger refactor as would be best done through RFC procedures first (beyond marking
window.calc
as deprecated. Goals of a larger refactor would include:Git Issues
Closes #
Screenshots/Videos
If useful, provide screenshot or capture to highlight main changes