Skip to content

Foodee/flipper-rb-js

Repository files navigation

flipper-rb-js

Build Status Code Climate Issue Count Test Coverage

Simple lib for letting your JavaScript talk to Flipper.rb

Motivation

If you use the flipper library https://github.com/jnunemaker/flipper for your rails app, but you also run an SPA, you may also want those feature flags to be visible in the JavaScript side of things. This library aims to make that easy for you.

Usage - Rails side

You'll need to build an endpoint that exposes your feature flags for a particular user, the implementation currently assumes a simple json object:

{
  feature: true,
  false: false
}

Usage - JavaScript

Use the static initializer, which is promise aware.

import Flipper from 'flipper-rb';

let eventuallyFlipper = Flipper.load('/api/users/features');

eventuallyFlipper
  .then(flipper => {
  
    if(flipper.isEnabled('featureName')){
      // do some things 
    }
    else {
      // do some other things 
    }
  });

The library assumes native promises, but if you want to be backwards compatible you can pass a promise class into the load function like so

let eventuallyFlipper = Flipper.load('/api/users/features', {PromiseClass: Ember.RSVP.Promise});

You might need some custom authentication (since you're likely flipping per user) so you can pass along some headers as well.

let eventuallyFlipper = Flipper.load('/api/users/features', {
                                                              PromiseClass: Ember.RSVP.Promise,
                                                              headers: {
                                                                Authentication: token="myToken"
                                                              }
                                                            });

Happy Flipping !

Shout outs

Thanks to https://github.com/jnunemaker for Flipper!

About

Simple lib for letting JS talk to Flipper.rb

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published