summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Florian <mflorian@gitlab.com>2019-07-10 12:24:57 +0800
committerMark Florian <mflorian@gitlab.com>2019-07-10 13:24:45 +0800
commitf80c75cf7e652460b0a1958407a2524fb57bdee0 (patch)
tree2f8f7d833f5fa35313e5d64f41d9a4cc4b083c5c
parent8a33f51d2f5ce67e167deb21ffe7768c3d638dcf (diff)
downloadgitlab-ce-docs-feature-flags-in-vue.tar.gz
Document how to access feature flags in Vuedocs-feature-flags-in-vue
Originated from this [discussion][1]. [1]: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14531#note_188376382
-rw-r--r--doc/development/fe_guide/vue.md43
-rw-r--r--doc/development/feature_flags/development.md3
2 files changed, 46 insertions, 0 deletions
diff --git a/doc/development/fe_guide/vue.md b/doc/development/fe_guide/vue.md
index 6c7572352ec..ab1309d05ad 100644
--- a/doc/development/fe_guide/vue.md
+++ b/doc/development/fe_guide/vue.md
@@ -103,6 +103,49 @@ document.addEventListener('DOMContentLoaded', () => new Vue({
}));
```
+#### Accessing feature flags
+
+Use Vue's [provide/inject](https://vuejs.org/v2/api/#provide-inject) mechanism
+to make feature flags available to any descendant components in a Vue
+application:
+
+```javascript
+// application entry point
+document.addEventListener('DOMContentLoaded', () => new Vue({
+ el: '.js-vue-app',
+ provide: {
+ aFeatureFlag: gon.features.aFeatureFlag,
+ },
+ render(createElement) {
+ return createElement('my-component');
+ },
+}));
+
+// An arbitrary descendant component
+export default {
+ ...
+ inject: {
+ aFeatureFlag: {
+ from: 'aFeatureFlag',
+ default: false,
+ },
+ },
+ ...
+}
+```
+
+This approach has several benefits:
+
+- Arbitrarily deeply nested components can opt-in and access the flag without
+ intermediate components being aware of it (c.f. passing the flag down via
+ props).
+- Components can use a different local name for the flag if necessary.
+- A default value can be declared in case the flag is not provided.
+- Good testability, since the flag can be provided to `mount`/`shallowMount`
+ from `vue-test-utils` as easily as a prop.
+- No need to access a global variable, except in the application's
+ [entry point](#accessing-the-gl-object).
+
### A folder for Components
This folder holds all components that are specific of this new feature.
diff --git a/doc/development/feature_flags/development.md b/doc/development/feature_flags/development.md
index 98773026122..dceacc2f407 100644
--- a/doc/development/feature_flags/development.md
+++ b/doc/development/feature_flags/development.md
@@ -109,6 +109,9 @@ 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.
+See the [Vue guide](../fe_guide/vue.md#accessing-feature-flags) for details about
+how to access feature flags in a Vue application.
+
### Specs
In the test environment `Feature.enabled?` is stubbed to always respond to `true`,