All Projects → yusinto → ld-redux

yusinto / ld-redux

Licence: MIT license
A library to integrate launch darkly with react redux

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ld-redux

ld-scheduler
Schedule Launch Darkly flags on or off
Stars: ✭ 14 (-57.58%)
Mutual labels:  launch, feature-flags, feature-toggles, flags, feature, launchdarkly, feature-toggle, feature-flag, ldclient, launch-darkly, darkly, ld-redux
jest-launchdarkly-mock
Easily unit test LaunchDarkly feature flagged components with jest
Stars: ✭ 14 (-57.58%)
Mutual labels:  feature-flags, feature-toggles, flags, feature, launchdarkly
Flipper
🐬 Beautiful, performant feature flags for Ruby.
Stars: ✭ 2,732 (+8178.79%)
Mutual labels:  feature-flags, feature-toggles, feature, feature-toggle, feature-flag
flagsmith-js-client
Javascript Client for Flagsmith. Ship features with confidence using feature flags and remote config. Host yourself or use our hosted version at https://www.flagsmith.com/
Stars: ✭ 42 (+27.27%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle, feature-flag
featurehub
FeatureHub - cloud native feature flags, A/B testing and remote configuration service. Real-time streaming feature updates. Provided with Java, JavaScript, Go, .Net, Android and Flutter SDKs.
Stars: ✭ 136 (+312.12%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle, feature-flag
Unleash
Unleash is the open source feature toggle service.
Stars: ✭ 4,679 (+14078.79%)
Mutual labels:  feature-flags, feature-toggles, feature, feature-toggle
js-sdk
JavaScript frontend SDK for ConfigCat. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
Stars: ✭ 21 (-36.36%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle, feature-flag
flipper
Feature Flipper, Feature Flags, Rollout Flags, Feature Toggles for Crystal
Stars: ✭ 21 (-36.36%)
Mutual labels:  feature-flags, feature-toggles, feature-flag
java-server-sdk
LaunchDarkly Server-Side SDK for Java
Stars: ✭ 71 (+115.15%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
ruby-client
Ruby SDK client for Split Software
Stars: ✭ 22 (-33.33%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle
js-client-sdk
LaunchDarkly Client-side SDK for Browser JavaScript
Stars: ✭ 93 (+181.82%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
toggler
toggler is a feature flag service to decouple deployment, feature enrollment and experiments
Stars: ✭ 27 (-18.18%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle
php-server-sdk
LaunchDarkly Server-side SDK for PHP
Stars: ✭ 31 (-6.06%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
flagsmith
Open Source Feature Flagging and Remote Config Service. Host on-prem or use our hosted version at https://flagsmith.com/
Stars: ✭ 2,309 (+6896.97%)
Mutual labels:  feature-flags, feature-toggles, feature-flag
php-client
PHP SDK client for Split Software
Stars: ✭ 14 (-57.58%)
Mutual labels:  feature-flags, feature-toggles, feature-toggle
ruby-server-sdk
LaunchDarkly Server-side SDK for Ruby
Stars: ✭ 25 (-24.24%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
ios-client-sdk
LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
Stars: ✭ 45 (+36.36%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
erlang-server-sdk
LaunchDarkly Server-Side SDK for Erlang/Elixir
Stars: ✭ 16 (-51.52%)
Mutual labels:  feature-flags, feature-toggles, launchdarkly
Flagception Bundle
Feature flags on steroids!
Stars: ✭ 162 (+390.91%)
Mutual labels:  feature-flags, feature-toggles, feature
Unleash Client Go
Unleash Client for Go
Stars: ✭ 78 (+136.36%)
Mutual labels:  feature-flags, feature-toggles, feature

ld-redux

npm version npm downloads npm npm

A library to integrate launch darkly with react redux 👏

Launch Darkly is a great tool for feature flagging and a/b testing. It has a fully capable client-side javascript sdk, so why this package?

If you use react redux and you want to store your feature flags as part of your redux state, this package will do that for you. It does the heavy lifting of:

  • Fetching your flags from launch darkly.
  • Storing it in your redux state.
  • Camel casing your keys so you can use them in code with the dot operator. The keys by default are dash separated so you can't do this out of the box with the official sdk.
  • Server Sent Event works as well so your app will respond live to feature flag changes without the users having to refresh the browser!

Breaking changes in v3.1

ld-redux v3.1.* is NOT backwards compatible! The init method now accepts dispatch instead of store. Follow the quickstart example below to see this.

Installation

yarn add ld-redux

Quickstart

  1. In your client bootstrap, initialise the launch darkly client by invoking the init method:

    import createStore from '<your-project>/store';
    import ldRedux from 'ld-redux';
    
    // standard redux createStore
    const store = createStore();
    
    // do this once
    ldRedux.init({
      clientSideId: 'your-client-side-id',
      dispatch: store.dispatch,
    });
    
    render(
      <Provider store={store}>
        <Router routes={routes} history={browserHistory}/>
      </Provider>,
      document.getElementById('reactDiv')
    );
  2. Include ldReducer as one of the reducers in your app:

    import { combineReducers } from 'redux';
    import ldRedux from 'ld-redux';
    import reducers from '<your-project>/reducers';
    
    export default combineReducers({
      ...reducers,
      LD: ldRedux.reducer(), // Note: the LD key can be anything you want
    });
  3. Use the flag:

    import React, {Component} from 'react';
    import {connect} from 'react-redux';
    
    const mapStateToProps = (state) => {
      const {featureFlagKey} = state.LD; // Note: the key LD must be the same as step 2.
    
      return {
        featureFlagKey,
      };
    };
    
    @connect(mapStateToProps)
    export default class Home extends Component {
      render() {
        return (
          <div>
            {
              /* look ma, feature flag! */
              this.props.featureFlagKey ?
                <div>
                  <p>Welcome to feature toggling!</p>
                </div>
                :
                'nothing'
            }
          </div>
        );
      }
    }

API

init({clientSideId, dispatch, flags, useCamelCaseFlagKeys, user, subscribe, options})

The init method accepts an object with the above properties. clientSideId, dispatch are mandatory.

The flags property is optional. This is an object containing all the flags you want to use and subscribe to in your app. If you don't specify this, ld-redux will subscribe to all flags in your ld environment.

// standard redux createStore
const store = createStore();
const flags = { 'feature-flag-key': false }; // only subscribe to  this one flag

// do this once
ldRedux.init({
  clientSideId: 'your-client-side-id',
  dispatch: store.dispatch,
  flags,
});

The subscribe property is optional. This defaults to true which means by default you'll get automatic live updates of flag changes from the server. You can turn this off and manually subscribe to flag changes through the ldClient object if for some reason you don't want to get live updates.

The user property is optional. You can initialise the sdk with a custom user by specifying one. This must be an object containing at least a "key" property. If you don't specify a user object, ldRedux will create a default one that looks like this:

const defaultUser = {
  key: uuid.v4(), // random guid
  ip: ip.address(),
  custom: {
    browser: userAgentParser.getResult().browser.name,
    device
  }
};

For more info on the user object, see here.

The useCamelCaseFlagKeys property is optional. This defaults to true which means by default the flags that are stored in redux will be camel cased. If this property is false, no transformation on the flag name will be done.

The options property is optional. It can be used to pass in extra options such as Bootstrapping. For example:

ldRedux.init({
    clientSideId,
    dispatch,
    flags,
    options: {
      bootstrap: 'localStorage',
    }
});

reducer()

This is ld-redux's reducer. You must include this reducer in your app as per step 2 above with any key of your choice. You then use this key to retrieve your flags from redux's state.

window.ldClient

Internally the ldRedux.init method above initialises the js sdk and stores the resultant ldClient object in window.ldClient. You can use this object to access the official sdk methods directly. For example, you can do things like:

// track goals
window.ldClient.track('add to cart');

// change user context
window.ldClient.identify({key: 'someUserId'});

For more info on changing user context, see the official documentation.

isLDReady

You no longer need to deal with isLDReady. However if you need to, it is still available in the store. You can access it via the LD state like so:

const mapStateToProps = (state) => {
  const {isLDReady} = state.LD; // Note: the key LD must be the same as step 2.

  return {
    isLDReady,
  };
};

This is useful to solve "flickering" issues above the fold on your front page caused by a flag transitioning from a default false value to true.

Example

Check the example for a fully working spa with react, redux and react-router. Remember to enter your client side sdk in the client bootstrap file before running the example!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].