Skip to content

Commit 1dfb24b

Browse files
author
Balwant Singh 🚀
committed
Added v1.1 changes
Added registerMyFeatureFlags support Updated usage documentation Added package script
1 parent e987b24 commit 1dfb24b

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

DEVELOPER.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Developing Chrome Plugin
2+
3+
Main code for plugin is located inside `plugin` folder.
4+
5+
## Packaging
6+
7+
run package command in terminal:
8+
9+
```shell
10+
> ./package
11+
```

README.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,53 @@ Example:
2424
// Declare Flags
2525
const flags = [
2626
{
27-
key: 'flag.one'
27+
key: 'flag.one',
2828
value: true, // current / initial state of feature flags in you app.
2929
description: 'First feature description', // Optional
3030
title: 'First feature', // Optional - If not passed, key will be used.
3131
},
3232
{
33-
key: 'flag.two'
33+
key: 'flag.two',
3434
value: true, // current / initial state of feature flags in you app.
3535
description: 'Second feature description', // Optional
3636
title: 'Second feature', // Optional - If not passed, key will be used.
37-
}
37+
},
3838
];
3939

4040
// This function will be called whenever a change happens in Chrome extension
4141
function listener(key, value) {
42-
// Feature flag with key change and update value is in value.
42+
// Feature flag with key change and update value is in value.
4343

44-
// Make your changes in your app
45-
toggleFeatureFlag(key, value);
46-
updateApp();
44+
// Make your changes in your app
45+
toggleFeatureFlag(key, value);
46+
updateApp();
4747
}
4848

49-
5049
// Register Feature Flags with plugin
5150
if (window.featureFlagsPluginRegister) {
5251
window.featureFlagsPluginRegister(flags, listener);
5352
}
5453
```
5554

55+
### Avoiding race conditions
56+
57+
Sometimes your registration code runs before plugin registers `featureFlagsPluginRegister`. In this case you can expose a setup function `registerMyFeatureFlags` on `window` object so that the plugin loads, it will automatically call this function which will register your flags.
58+
59+
`featureFlagsPluginRegister` function is also passed to your `registerMyFeatureFlags` which can be used to register the feature flags.
60+
61+
> Note: This will only run once the plugin registers with the web page. later on you can still call `window.featureFlagsPluginRegister`.
62+
63+
### Example
64+
65+
```javascript
66+
window.registerMyFeatureFlags = (register) => {
67+
register(toggles, (key, value) => {
68+
console.info(`Toggling ${key} => ${value}`);
69+
toggleFeatureFlag(key, value);
70+
});
71+
};
72+
```
73+
5674
---
5775

5876
### Testing Snippet

package

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f plugin.zip
4+
5+
zip plugin.zip -r plugin

plugin/content-script.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
}
3232
window.featureFlagsPluginRegister = featureFlagsPluginRegister;
3333
window.addEventListener('message', event => {
34-
3534
});
3635
console.info('featureFlagsPluginRegister Registered :)');
36+
37+
if(window.registerMyFeatureFlags) {
38+
window.registerMyFeatureFlags(featureFlagsPluginRegister);
39+
}
3740
}
3841

3942
function inject(fn) {

plugin/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Feature Flags",
3-
"version": "1.0",
3+
"version": "1.1",
44
"description": "Chrome Extension to manage Feature Flags in supported web apps",
55
"permissions": [
66
"tabs",

0 commit comments

Comments
 (0)