You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
The current API uses a component and callback which essentially forces the use of a class component. This is fine for smaller changes, but it doesn't compose well with other React HOC-based libraries.
An example with code splitting and conditional data fetching:
This can allow the A/B test to be completely transparent to the wrapped component, and it can be easily added or removed without adding custom wrapper components.
This should be possible to do while sharing code with the existing component, possibly as a simple wrapper.
The text was updated successfully, but these errors were encountered:
This is quite limited because it only allows for a single flag to be passed in, but it reuses the current FeatureFlag component to accomplish an HOC:
exportdefaultflagKey=>WrappedComponent=>{const_renderFeature=function(props,featureFlagValue=true){constflags={};flags[flagKey]=featureFlagValue;return<WrappedComponent{...props}featureFlags={flags}/>;};returnfunction(props){return(<FeatureFlagflagKey={flagKey}// null flag value means LaunchDarkly is not initialized yetinitialRenderCallback={_renderFeature.bind(this,props,null)}renderDefaultCallback={_renderFeature.bind(this,props,false)}renderFeatureCallback={_renderFeature.bind(this,props)}/>);};};
^- this tactic means that the wrapped component must comprehend a prop called featureFlags. That's undesirable because it means we can't take an existing feature, wrap it in the HOC (with no other changes), and see a different flagged outcome. Looking at @threehams's proposal via recompose, we do get that quality. The challenger component and the challengee(?) can be completely decoupled:
start with existing feature
invent challenger feature
wrap existing feature usage with HOC that references challenger
decide winner and delete the HOC
Although now that I'm looking twice at your code, it seems maybe that prop is superfluous anyway? We already know which callback was exercised by the featureFlagValue argument, so no need to pass the flag along to WrappedComponent. Right? We could still get an unmolested challengee in there.
Forgive me for making the same comment on both your posts, but please do submit a PR. It will make the code commenting a lot easier. 🙂
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The current API uses a component and callback which essentially forces the use of a class component. This is fine for smaller changes, but it doesn't compose well with other React HOC-based libraries.
An example with code splitting and conditional data fetching:
This can allow the A/B test to be completely transparent to the wrapped component, and it can be easily added or removed without adding custom wrapper components.
This should be possible to do while sharing code with the existing component, possibly as a simple wrapper.
The text was updated successfully, but these errors were encountered: