-
Notifications
You must be signed in to change notification settings - Fork 51
refactor: simplify evaluation context updates for before hooks #1257
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
base: main
Are you sure you want to change the base?
refactor: simplify evaluation context updates for before hooks #1257
Conversation
- Remove redundant loop for updating the hook contexts - Add simple test case to make sure the same object reference is being updated Signed-off-by: Marko Mlakar <markomlakar2@gmail.com>
aepfli
left a comment
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.
thank you this looks good to me - but i am by far not a js expert, maybe somebody else can have a look at this
| const hookContext = hookContexts[hookContextIndex]; | ||
|
|
||
| // Update the context on the stable hook context object | ||
| Object.assign(hookContext.context, accumulatedContext); |
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.
If we remove this line, the accumulatedContext is not available in the beforeHook on the next line.
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 @guidobrei you are correct. I have updated the PR
Signed-off-by: markomlakar <marko.mlakar@dynatrace.com>
* Reverted the purposed changes to ensure the before hook gets the accumulated hook context * Replaced the for loop with a single shared object update Signed-off-by: MarkoMlakar <marko.mlakar@dynatrace.com>
| Object.assign(accumulatedContext, hookResult); | ||
|
|
||
| for (let i = 0; i < hooks.length; i++) { | ||
| Object.assign(hookContexts[hookContextIndex].context, accumulatedContext); |
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.
hookContext.context is a shared object. All the hooks recieve and operate on the same context object, making this for loop redundant
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.
Is it? from the method signature it could be different contexts.
This PR
Related Issues
#1236
Notes
The accumulated evaluation context object is shared with all the hooks (same object reference). This makes the inner for loop for updating the contexts redundant
How to test
npm run test