npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-feature-manager

v0.0.12

Published

React toolset to start using feature-flags in your application

Downloads

7

Readme

Build Status Coverage Status

react-feature-manager

React high-order components kit to make feature management simple

react-feature-manager is a library which provide high order components to manange your application features, run dark launches or A/B tests.

This library is back-end agnostick and will work with any feature-flag implemenemtation as long as you provide the client to it.

Installation

npm install --save react-feature-manager

or yarn add react-feature-manager

How to use

Dependencies

For bundle size optimisation purposes this library does not include following dependencies and expect them to be provided as peer dependencies:

  • React
  • React Dom
  • PropTypes

Library API

This library provides 3 HOCs:

  • Provider - provides client to Feature HOCs
  • Feature - defines a feature to manage. Requires name: string property, which should be a featureFlag name
  • Option - defines a feature implemenatation. Requires a value property. If value is equal to featureFlag value - childern of Option will be rendered.

At the top level of your app add client provider:

   import { Provider as FeatureClientProvider } from 'react-feature-manager';
   ...

   ReactDOM.render(
     <FeatureClientProvider client={yourClientImplementation}>
       <MyAppliaction />
     </FeatureClientProvider>,
     document.getElementById('application-container')
   );
NOTE: if your build system does not support "module builds" or you decided to use UMD version of this package for some reason, your imports have to look like:
  import featureManager from 'react-feature-manager'

  const { Provider } = featureManager;
  ...
  const { Feature, Option } = featureManager;

This example is just simple on/off switch:

import React from 'react';
import { Feature, Option } from 'react-feature-manager';

<Feature name="one">
  <Option value>
      <span>
        Feature <span className="bold">one</span> is enabled
      </span>
  </Option>
</Feature>

Or if you have multiple implementations and want to display specific implementation based on some db or config value (like when you run an A/B test):

import React from 'react';
import { Feature, Option } from 'react-feature-manager';

const SomeComponent = () => (
  <section className="column">
    <h3>My A/B test:</h3>
      <Feature name="myABTestFlagName">
        <Option value="RecipieA">
          <span>
            <span className="bold">RecipieA</span> enabled
          </span>
        </Option>
        <Option value="RecipieB">
          <span>
           <span className="bold">RecipieB</span> enabled
          </span>
        </Option>
        <Option value="RecipieC">
          <span>
            <span className="bold">RecipieC</span> enabled
          </span>
        </Option>
      </Feature>
  </section>
);

Client

The client is a simple JavaScript object which provides the following methods:

{
  subscribe: function(flagName, callback),
  getFeatureFlagValue: function(flagName)
}
  • subscribe - takes a flagName: String and supposed to call a callback when flagName value is changed. Optionaly subscribe may return an unSubscribe function which will be called on Feature component unmount.
  • getFeatureFlagValue - takes a flagName and returns either flag value or Promise which resolves with a flag value.

Since I can not know your specific implementation for a flag storage - the client is not provided with this library. However there is an example of a mock client in the example folder

How to run an example

  1. git clone https://github.com/AndrewKovalenko/react-feature-manager.git
  2. cd react-feature-manager
  3. npm install
  4. npm start Browser should open automatically, but if it doesn't - visit http://localhost:10001/ once build is finished.