https://github.com/foodee/flipper-rb-js
Simple lib for letting JS talk to Flipper.rb
https://github.com/foodee/flipper-rb-js
Last synced: 11 months ago
JSON representation
Simple lib for letting JS talk to Flipper.rb
- Host: GitHub
- URL: https://github.com/foodee/flipper-rb-js
- Owner: Foodee
- License: mit
- Created: 2016-06-01T22:49:27.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-03T02:51:49.000Z (about 10 years ago)
- Last Synced: 2024-11-17T05:36:32.247Z (over 1 year ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 5
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flipper-rb-js
[](https://travis-ci.org/Foodee/flipper-rb-js) [](https://codeclimate.com/github/Foodee/flipper-rb-js) [](https://codeclimate.com/github/Foodee/flipper-rb-js) [](https://codeclimate.com/github/Foodee/flipper-rb-js/coverage)
Simple lib for letting your JavaScript talk to Flipper.rb
## Motivation
If you use the flipper library [https://github.com/jnunemaker/flipper](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:
```JavaScript
{
feature: true,
false: false
}
```
## Usage - JavaScript
Use the static initializer, which is promise aware.
```JavaScript
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
```JavaScript
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.
```JavaScript
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](https://github.com/jnunemaker) for Flipper!