Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-10-08 17:24:40 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2018-10-11 18:06:19 +0300
commit21940d1edf1604f192957691e99677d191380543 (patch)
treef9760a1263c9128aca629df81264ea98946055e7 /doc
parenta5ca102aa1440150717a470059f707d5e5842782 (diff)
Support pushing of feature flags to the frontend
This adds a method to Gitlab::GonHelper called `push_frontend_feature_flag`. This method can be used to easily expose the state of a feature flag to Javascript code. For example, using this method we may write the following controller code: before_action do push_frontend_feature_flag(:vim_bindings) end def index # ... end def edit # ... end In Javascript we can then check the state of the flag as follows: if ( gon.features.vimBindings ) { // ... } Fixes https://gitlab.com/gitlab-org/release/framework/issues/17
Diffstat (limited to 'doc')
-rw-r--r--doc/development/feature_flags.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/doc/development/feature_flags.md b/doc/development/feature_flags.md
index 417298205f5..0f1f079bdb4 100644
--- a/doc/development/feature_flags.md
+++ b/doc/development/feature_flags.md
@@ -69,6 +69,37 @@ For more information about rolling out changes using feature flags, refer to the
[Rolling out changes using feature flags](rolling_out_changes_using_feature_flags.md)
guide.
+### Frontend
+
+For frontend code you can use the method `push_frontend_feature_flag`, which is
+available to all controllers that inherit from `ApplicationController`. Using
+this method you can expose the state of a feature flag as follows:
+
+```ruby
+before_action do
+ push_frontend_feature_flag(:vim_bindings)
+end
+
+def index
+ # ...
+end
+
+def edit
+ # ...
+end
+```
+
+You can then check for the state of the feature flag in JavaScript as follows:
+
+```javascript
+if ( gon.features.vimBindings ) {
+ // ...
+}
+```
+
+The name of the feature flag in JavaScript will always be camelCased, meaning
+that checking for `gon.features.vim_bindings` would not work.
+
### Specs
In the test environment `Feature.enabled?` is stubbed to always respond to `true`,