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

Commit 8eea2c2

Browse files
mitermayerfacebook-github-bot
authored andcommitted
Enabling a GK manager for the plaground
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
1 parent 7495adf commit 8eea2c2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import querystring from 'querystring';
2+
3+
const QUERY_STRINGS = querystring.parse(window.location.search.substring(1));
4+
5+
// overwrite the feature flag stub object
6+
const GKManager = (window.__DRAFT_GKX = {});
7+
8+
// enable or disable feature flags
9+
const flagControls = {
10+
gk_disable: flags =>
11+
flags.forEach(flag => (window.__DRAFT_GKX[flag] = false)),
12+
gk_enable: flags => flags.forEach(flag => (window.__DRAFT_GKX[flag] = true)),
13+
};
14+
15+
Object.keys(flagControls)
16+
.filter(flag => QUERY_STRINGS[flag])
17+
.forEach(flag => flagControls[flag](QUERY_STRINGS[flag].split(',')));
18+
19+
export default GKManager;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import GkManager from './GkManager';
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34
import './index.css';
45
import App from './App';
56
import registerServiceWorker from './registerServiceWorker';
67

8+
console.log("Applying feature flag overwrites: ", GkManager);
9+
710
ReactDOM.render(<App />, document.getElementById('root'));
811
registerServiceWorker();

src/stubs/gkx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
module.exports = function(name: string) {
1717
if (typeof window !== 'undefined' && window.__DRAFT_GKX) {
18-
return window.__DRAFT_GKX[name];
18+
return !!window.__DRAFT_GKX[name];
1919
}
2020
return false;
2121
};

0 commit comments

Comments
 (0)