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

feat(ForcedDecisions): Add forced-decisions APIs to ReactSDKClient and update useDecision hook to reflect changes #133

Merged
merged 5 commits into from
Jan 19, 2022

Conversation

cristianparcu-epi
Copy link
Contributor

@cristianparcu-epi cristianparcu-epi commented Nov 12, 2021

Summary

Add a set of new APIs for forced-decisions to ReactSDKClient.

  • setForcedDecision
  • getForcedDecision
  • removeForcedDecision
  • removeAllForcedDecisions

Also updated useDecision hook to autoupdate and reflect changes when forced decisions are set and removed.

Test Plan

  • Added unit tests.
  • Manually tested thoroughly.

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

Great work overall!
This is a partial review. I have suggested a few changes and will suggest a few more later today. Overall, this is looking great and heading in the right direction.

src/client.ts Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved
src/client.ts Show resolved Hide resolved
Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

The Implementation looks great so far! Can you add unit tests for all the changes you made and all the new functionality you added.

Comment on lines +354 to +356
const getCurrentDecision: () => { decision: OptimizelyDecision } = () => ({
decision: optimizely.decide(flagKey, options.decideOptions, overrides.overrideUserId, overrideAttrs),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This was probably done to make sure decide is only called if any of the inputs that it depends on, change. Removing this from a useCallback hook might result in it being called multiple times on same inputs

src/store.ts Outdated Show resolved Hide resolved
src/hooks.ts Outdated
Comment on lines 431 to 438
useEffect(() => {
if (lastUserUpdate) {
setState(prevState => ({
...prevState,
...getCurrentDecision(),
}));
}
}, [lastUserUpdate]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole implementation for forced decision looks great. Can you add unit tests to cover all the scenarios

* @param {optimizely.OptimizelyForcedDecision} forcedDecision
* @memberof OptimizelyReactSDKClient
*/
public setForcedDecision(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add unit tests for this?

zashraf1985 and others added 3 commits January 6, 2022 15:13
Sherry was working from his fork due to access issues. Now merging it back to the same branch in base repo.
@zashraf1985 zashraf1985 changed the title [WIP][OASIS-7957] Implementing forced decisions from the JS SDK Implementing forced decisions from the JS SDK Jan 17, 2022
@zashraf1985 zashraf1985 changed the title Implementing forced decisions from the JS SDK Implemented Forced Decision APIs Jan 19, 2022
@zashraf1985 zashraf1985 changed the title Implemented Forced Decision APIs feat(ForcedDecisions): Add forced-decisions APIs to ReactSDKClient and update useDecision hook to reflect changes Jan 19, 2022
@zashraf1985 zashraf1985 merged commit a67ad8b into master Jan 19, 2022
@zashraf1985 zashraf1985 deleted the cris/forced-decisions branch January 19, 2022 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants