Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Enabling a GK manager for the plaground
Browse files Browse the repository at this point in the history
Summary:
This enables on the playground for us to pass `gk_enable=foo,bar,foobar` or `gk_disable=foo,bar,foobar`, on the URI,

Example:

```
http://localhost:3000/?gk_enable=foo&gk_disable=bar,foobar
```

***

TLDR:

- Updating our Gkx stub to treat undefined gks on the stub object as falsy
- This will allow us to update GK flags while interacting with the playground.
Closes #1677

Differential Revision: D7155154

fbshipit-source-id: 99836da46aafcf0cd30d4fe613633e897f59a079
  • Loading branch information
mitermayer authored and facebook-github-bot committed Mar 5, 2018
1 parent 7495adf commit 8eea2c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions examples/draft-0-10-0/playground/src/GkManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import querystring from 'querystring';

const QUERY_STRINGS = querystring.parse(window.location.search.substring(1));

// overwrite the feature flag stub object
const GKManager = (window.__DRAFT_GKX = {});

// enable or disable feature flags
const flagControls = {
gk_disable: flags =>
flags.forEach(flag => (window.__DRAFT_GKX[flag] = false)),
gk_enable: flags => flags.forEach(flag => (window.__DRAFT_GKX[flag] = true)),
};

Object.keys(flagControls)
.filter(flag => QUERY_STRINGS[flag])
.forEach(flag => flagControls[flag](QUERY_STRINGS[flag].split(',')));

export default GKManager;
3 changes: 3 additions & 0 deletions examples/draft-0-10-0/playground/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import GkManager from './GkManager';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

console.log("Applying feature flag overwrites: ", GkManager);

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
2 changes: 1 addition & 1 deletion src/stubs/gkx.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

module.exports = function(name: string) {
if (typeof window !== 'undefined' && window.__DRAFT_GKX) {
return window.__DRAFT_GKX[name];
return !!window.__DRAFT_GKX[name];
}
return false;
};

0 comments on commit 8eea2c2

Please sign in to comment.