Skip to content
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

Additional params to experiment hooks methods. Enable hooks in getAssignment #8

Merged
merged 5 commits into from
Aug 30, 2023

Conversation

petzel
Copy link
Contributor

@petzel petzel commented Aug 29, 2023

Description

  • Adds additional parameters to the hook methods so users can reuse a single definition of IAssignmentHooks
  • We originally created a separate method for retrieving an assignment with hooks so it could be made async in order to potentially perform I/O during a hook invocation. We also got feedback that this isn't necessary/desired, so added the hooks as an optional param to the synchronous getAssignment method, and removed the getAssignmentWithHooks method.
  • Moves the call to onPreAssignment after the enabled check so overrides only take place if the flag is enabled

@petzel petzel force-pushed the assignment-hooks-sync-with-more-params branch from d4c2ae7 to 7adbe91 Compare August 29, 2023 13:46
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good! 🎉

expect(td.explain(mockHooks.onPreAssignment).callCount).toEqual(1);
expect(td.explain(mockHooks.onPreAssignment).calls[0].args[0]).toEqual('subject-identifer');
expect(td.explain(mockHooks.onPreAssignment).calls[0].args[0]).toEqual(experimentName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assignment = this.getAssignment(subjectKey, experimentKey, subjectAttributes);
// check for overridden assignment via hook
const overriddenAssignment = assignmentHooks?.onPreAssignment(experimentKey, subjectKey);
if (overriddenAssignment != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but we can strict inequality check here (!==)

@petzel petzel merged commit e43426a into main Aug 30, 2023
2 checks passed
@petzel petzel deleted the assignment-hooks-sync-with-more-params branch August 30, 2023 15:51
leoromanovsky pushed a commit that referenced this pull request Aug 30, 2023
…signment` (#8)

* additional params to experiment hooks methods. enable hooks in getAssignment

* only check assignment override after enabled check

* ensure logging callback is invoked when overriding via hook

* create internal method to avoid multiple calls to log assignment/post assignment callback

* add undefined check
leoromanovsky pushed a commit that referenced this pull request Aug 31, 2023
…signment` (#8)

* additional params to experiment hooks methods. enable hooks in getAssignment

* only check assignment override after enabled check

* ensure logging callback is invoked when overriding via hook

* create internal method to avoid multiple calls to log assignment/post assignment callback

* add undefined check
leoromanovsky pushed a commit that referenced this pull request Aug 31, 2023
…signment` (#8)

* additional params to experiment hooks methods. enable hooks in getAssignment

* only check assignment override after enabled check

* ensure logging callback is invoked when overriding via hook

* create internal method to avoid multiple calls to log assignment/post assignment callback

* add undefined check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants