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

Expose LDProvider as a standalone component #28

Closed
wants to merge 4 commits into from

Conversation

nimi
Copy link
Contributor

@nimi nimi commented Feb 23, 2020

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

#27

Describe the solution you've provided

I've lifted the LDProvider class component used inside the withLDProvider HOC into a standalone class component export. I've done my best to ensure that that there no new behavior changes were made and only on the task of moving the Provider code into a place where it can be exported in the public API of this SDK.

I've also moved around the unit tests and shifted coverage to the standalone LDProvider.

Describe alternatives you've considered

  • Feature flagging libraries that aren't a part of the official SDK

Copy link
Contributor

@yusinto yusinto left a comment

Choose a reason for hiding this comment

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

@nimi thank you for submitting this PR! Exposing the Provider component definitely makes sense and it is something that we agree should be included in the react sdk.

I have left some feedback here which are hopefully useful. In addition to the in-line comments, is it also possible to add an example app to the examples folder please? There are currently an example app each for asyncWithLDProvider and withLDProvider. It will be tremendously helpful to other users to have another example app demonstrating this new Provider component.

Also for completeness, is it also possible to add documentation for this new Provider component to the react sdk docs please? You can submit a PR via the Edit on github button on that page.

Thank you again.

@@ -1,16 +1,12 @@
import * as React from 'react';
import camelCase from 'lodash.camelcase';
import { LDClient, LDFlagSet, LDFlagChangeset } from 'launchdarkly-js-client-sdk';
import { defaultReactOptions, ProviderConfig, EnhancedComponent } from './types';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's safe to remove EnhancedComponent now that it is no longer used here.

if (options) {
const { bootstrap } = options;
if (bootstrap && bootstrap !== 'localStorage') {
const { useCamelCaseFlagKeys = defaultReactOptions.useCamelCaseFlagKeys } = reactOptions || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems the logic to generate react options based on the default and user values is being used multiple times in this component. Perhaps we can optimize this to a single function which can be re-used, thus removing duplication:

// new function to generate react options which can be re-used
getReactOptions = () => ({ ...defaultReactOptions, ...this.props.reactOptions });

// then on lines 42, 58 and 68, the usage becomes
const { useCamelCaseFlagKeys } = this.getReactOptions();

You can also safely remove the destructured prop reactOptions on line 32 above if you do this since it is no longer used.

@nimi
Copy link
Contributor Author

nimi commented Mar 13, 2020

Hi @yusinto! Thanks so much for the review and follow up! My apologies for the delay in my response

I can definitely take care of the feedback mentioned with both docs and code cleanup. I'll address those concerns and request review when I've updated.

Cheers,
Nicholas

@Morton
Copy link
Contributor

Morton commented May 7, 2020

Hi guys,
I could need that change, so I quickly fixed the comments and opened a new PR: #31

Thanks guys,
Morton

@bwoskow-ld
Copy link
Member

We merged #31 just now -- I'm closing this PR in favor of that one.

@bwoskow-ld bwoskow-ld closed this Jun 12, 2020
LaunchDarklyCI pushed a commit that referenced this pull request Sep 14, 2020
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.

4 participants