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

Hooks refactor #10

Merged
merged 9 commits into from
Sep 17, 2019
Merged

Hooks refactor #10

merged 9 commits into from
Sep 17, 2019

Conversation

tbrannam
Copy link

@tbrannam tbrannam commented Sep 8, 2019

Table of Contents

Description

Introduce hooks support
Refactor CoreExperiment to use hooks
Update tests.
Fix slow tests

Motivation and Context

Ready support for react 17.x
Add hooks support for React Functional Components

How Has This Been Tested?

Updated tests related to params changes for core experiment.
Added specific tests for hook, useExperiment

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Todd Brannam added 2 commits September 5, 2019 08:35
Breaking Change

** CoreExperiment now has same Props as Experiment **
- (value becomes defaultVariantName)

the call `calculateActiveVariant` has moved from Experiment down to the hook called in CoreExperiment.  The public interfaces of `Variant` and `Experiment` remain the same

- add hooks implementation
- reimplement CoreExperiment as functional component with using hook for implemenation.
@tbrannam tbrannam changed the title Hooks refactor Draft: Hooks refactor Sep 8, 2019
BREAKING CHANGE

propTypes of CoreExperiment are different than before this branch
@moretti
Copy link
Member

moretti commented Sep 11, 2019

Hey @tbrannam, looks like an amazing work, I'll have deep look tomorrow.
Having support for hooks is great, I think we'll have to create a major release, since we're no longer supporting [email protected] and react@15, but it should be fine, we can potentially add it to README.

I'm sorry about the late reply (currently drowning in reviews 😅), thank you for submitting this pull request! 🎉

added new test for testing the hook base functionality
@tbrannam tbrannam changed the title Draft: Hooks refactor Hooks refactor Sep 11, 2019
@tbrannam
Copy link
Author

It's all good - I think I did everything I wanted to do - just added tests for hooks.

BREAKING CHANGE

Due to modern React requirement
Copy link
Member

@moretti moretti left a comment

Choose a reason for hiding this comment

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

This is really great work! 🎉
I left a couple of suggestions

README.md Outdated Show resolved Hide resolved
src/CoreExperiment.jsx Show resolved Hide resolved
src/hooks.jsx Outdated Show resolved Hide resolved
test/browser/emitter.test.jsx Outdated Show resolved Hide resolved
test/browser/weighted.test.jsx Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Todd Brannam added 4 commits September 12, 2019 09:06
renamed hooks.jsx -> hook.jsx to match singular form of other files
Require React 16.8
changed to singular form
@tbrannam
Copy link
Author

Think I've addressed all the outstanding issues.

One thing that I wonder about revisiting is the need to preregister variants. This is due to the Hook not having any reference to the possible list of variants like the Components would have. I like the hook interface now, but it might work if somehow the variants were passed to the hook as well as an alternative calling pattern.

Or maybe it isn't too bad the way it is?

@tbrannam
Copy link
Author

friendly bump

@moretti
Copy link
Member

moretti commented Sep 17, 2019

I had another deep look at source code and I think it looks really good.

One way to solve the last problem that you mentioned would be to extend the useExperiment hook, eg. use an object for advance configuration:

useExperiment('experiment_name', { 
  variants: ['A', 'B'],
  defaultVariant: 'A',
  userIdentifier: 'pk_123', 
});

I think we could potentially merge this PR as it is, release a beta version of v3, test it for a few days and see how it goes, what do you think?

@tbrannam
Copy link
Author

tbrannam commented Sep 17, 2019 via email

@moretti moretti merged commit ab7d3de into marvelapp:master Sep 17, 2019
@moretti
Copy link
Member

moretti commented Sep 17, 2019

Released in 3.0.0-beta.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants