Commit 840f3cce authored by Amy Qualls's avatar Amy Qualls

Merge branch 'dreedy-follow-up-from-56911-experiment-vue-component-docs-fixes' into 'master'

Spruce up the docs for new experiment Vue component a bit

See merge request gitlab-org/gitlab!57176
parents 70564f1e 33035a70
...@@ -504,18 +504,20 @@ so you can use it when resolving some concepts around experimentation in the cli ...@@ -504,18 +504,20 @@ so you can use it when resolving some concepts around experimentation in the cli
### Use experiments in Vue ### Use experiments in Vue
With the `experiment` component, you can define slots that match the name of the With the `experiment` component, you can define slots that match the name of the
variants pushed to `window.gon.experiment`. For example, an experiment with the variants pushed to `window.gon.experiment`. For example, if we alter the `pill_color`
default variants `control` and `candidate` could be implemented like this: experiment to just use the default variants of `control` and `candidate` like so:
```ruby ```ruby
def show def show
experiment(:button_color) do |e| experiment(:pill_color) do |e|
e.use { } # control e.use { } # control
e.try { } # candidate e.try { } # candidate
end.run end.run
end end
``` ```
We can make use of the named slots `control` and `candidate` in the Vue component:
```vue ```vue
<script> <script>
import Experiment from '~/experimentation/components/experiment.vue'; import Experiment from '~/experimentation/components/experiment.vue';
...@@ -526,20 +528,20 @@ export default { ...@@ -526,20 +528,20 @@ export default {
</script> </script>
<template> <template>
<experiment name="button_name"> <experiment name="pill_color">
<template #control> <template #control>
<button>Click me</button> <button class="bg-default">Click default button</button>
</template> </template>
<template #candidate> <template #candidate>
<button>You will not believe what happens when you click this button</button> <button class="bg-red">Click red button</button>
</template> </template>
</experiment> </experiment>
</template> </template>
``` ```
When you use a multivariate experiment, you can use the variant names. For example, When you're coding for an experiment with multiple variants, you can use the variant names.
the Vue component for the `pill_color` experiment would look like this: For example, the Vue component for the previously-defined `pill_color` experiment with `red` and `blue` variants would look like this:
```vue ```vue
<template> <template>
...@@ -560,7 +562,7 @@ the Vue component for the `pill_color` experiment would look like this: ...@@ -560,7 +562,7 @@ the Vue component for the `pill_color` experiment would look like this:
``` ```
NOTE: NOTE:
When there is no experiment defined in the frontend via `experiment(:experiment_name)`, then `control` will be rendered if it exists. When there is no experiment data in the `window.gon.experiment` object for the given experiment name, the `control` slot will be used, if it exists.
## Notes on feature flags ## Notes on feature flags
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment