flipper-rb

1.0.0 • Public • Published

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!

Readme

Keywords

Package Sidebar

Install

npm i flipper-rb

Weekly Downloads

891

Version

1.0.0

License

MIT

Last publish

Collaborators

  • joegaudet