Repository navigation
feat(vue): add @tryabby/vue integration package (closes #68) #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gostmkr24
wants to merge
6
commits into
tryabby:main
Choose a base branch
from
gostmkr24:feat/vue-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,380
−317
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88c46b0
feat(vue): add @tryabby/vue integration package
gostmkr24 5aecbec
fix(vue): isolate scopes and defer variant assignment
gostmkr24 a7a66cb
fix(vue): recover from a failed data request and scope user properties
gostmkr24 6d3bbe7
fix(vue): expose a scoped user-property updater and cover node SSR
gostmkr24 f922347
fix(core): never freeze a rule result or pick a variant before init
gostmkr24 518dedb
fix(vue): do not assign a variant while the data is still loading
gostmkr24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@tryabby/vue": minor | ||
| --- | ||
|
|
||
| Add the `@tryabby/vue` package: a Vue 3 integration with `createAbby`, `AbbyPlugin`, `AbbyProvider`, `provideAbby`, the `useAbby`, `useFeatureFlag`, `useRemoteConfig`, `useFeatureFlags` and `useRemoteConfigVariables` composables, the non-reactive helpers and full type tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| --- | ||
| title: Vue | ||
| description: The official Vue 3 integration for Abby | ||
| --- | ||
|
|
||
| # Vue | ||
|
|
||
| The `@tryabby/vue` package is the official [Vue 3](https://vuejs.org) integration for Abby. | ||
| It consumes [`@tryabby/core`](/reference/core) internally and has the same feature set as the | ||
| [React integration](/reference/react). | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @tryabby/vue | ||
| ``` | ||
|
|
||
| ## Setup | ||
|
|
||
| ```ts | ||
| // lib/abby.ts | ||
| import { createAbby } from "@tryabby/vue"; | ||
|
|
||
| export const { | ||
| AbbyPlugin, | ||
| AbbyProvider, | ||
| provideAbby, | ||
| useAbby, | ||
| useFeatureFlag, | ||
| useRemoteConfig, | ||
| getFeatureFlagValue, | ||
| getRemoteConfig, | ||
| getABTestValue, | ||
| getABResetFunction, | ||
| getVariants, | ||
| updateUserProperties, | ||
| withDevtools, | ||
| } = createAbby({ | ||
| projectId: "YOUR_PROJECT_ID", | ||
| currentEnvironment: "production", | ||
| environments: ["development", "preview", "production"], | ||
| tests: { | ||
| "my-ab-test": { | ||
| variants: ["control", "variant-a"], | ||
| }, | ||
| }, | ||
| flags: ["my-feature-flag"], | ||
| remoteConfig: { | ||
| "my-string-variable": "String", | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| Install the plugin on your app: | ||
|
|
||
| ```ts | ||
| // main.ts | ||
| import { createApp } from "vue"; | ||
| import App from "./App.vue"; | ||
| import { AbbyPlugin } from "./lib/abby"; | ||
|
|
||
| createApp(App).use(AbbyPlugin).mount("#app"); | ||
| ``` | ||
|
|
||
| If you already fetched the Abby data on the server, pass it to the plugin so no | ||
| request is made on the client: | ||
|
|
||
| ```ts | ||
| app.use(AbbyPlugin, { initialData: dataFromTheServer }); | ||
| ``` | ||
|
|
||
| You can also call `provideAbby({ initialData })` inside a `setup` function, or | ||
| render the `<AbbyProvider :initial-data="...">` component to scope the Abby | ||
| context to a subtree. | ||
|
|
||
| ## `useAbby` | ||
|
|
||
| Returns the currently selected variant of an A/B test and the `onAct` function. | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useAbby } from "~/lib/abby"; | ||
|
|
||
| const { variant, onAct } = useAbby("my-ab-test"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <button @click="onAct">{{ variant }}</button> | ||
| </template> | ||
| ``` | ||
|
|
||
| `variant` is a `ComputedRef` and is unwrapped automatically inside of templates. | ||
| It is an empty string until the component is mounted so that server side | ||
| rendering and hydration cannot mismatch. | ||
|
|
||
| You can pass a lookup object as the second argument. The returned variant is then | ||
| the value of the selected variant and fully typed: | ||
|
|
||
| ```ts | ||
| const { variant } = useAbby("my-ab-test", { | ||
| control: "Hello", | ||
| "variant-a": "Bonjour", | ||
| }); | ||
| ``` | ||
|
|
||
| ## `useFeatureFlag` | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useFeatureFlag } from "~/lib/abby"; | ||
|
|
||
| const showNewFooter = useFeatureFlag("my-feature-flag"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <NewFooter v-if="showNewFooter" /> | ||
| <OldFooter v-else /> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## `useRemoteConfig` | ||
|
|
||
| ```vue | ||
| <script setup lang="ts"> | ||
| import { useRemoteConfig } from "~/lib/abby"; | ||
|
|
||
| const headline = useRemoteConfig("my-string-variable"); | ||
| </script> | ||
|
|
||
| <template> | ||
| <h1>{{ headline }}</h1> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## `useFeatureFlags` and `useRemoteConfigVariables` | ||
|
|
||
| Both return a `ComputedRef` with an array of `{ name, value }` objects for all | ||
| configured flags / remote config variables. | ||
|
|
||
| ## Non-reactive helpers | ||
|
|
||
| The following helpers can be used outside of a component (for example in a | ||
| router guard or a store): | ||
|
|
||
| - `getFeatureFlagValue(name)` – value of a feature flag | ||
| - `getRemoteConfig(name)` – value of a remote config variable | ||
| - `getABTestValue(name, lookup?)` – variant of an A/B test | ||
| - `getVariants(name)` – all variants of a test | ||
| - `getABResetFunction(name)` – returns a function which resets the stored variant | ||
| - `updateUserProperties(user)` – updates the user properties used by flag rules | ||
|
|
||
| ## Nuxt | ||
|
|
||
| ```ts | ||
| // plugins/abby.ts | ||
| import { AbbyPlugin } from "~/lib/abby"; | ||
|
|
||
| export default defineNuxtPlugin((nuxtApp) => { | ||
| nuxtApp.vueApp.use(AbbyPlugin, { | ||
| initialData: nuxtApp.payload.data.abby, | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Devtools | ||
|
|
||
| ```ts | ||
| import DevtoolsFactory from "@tryabby/devtools"; | ||
| import { withDevtools } from "~/lib/abby"; | ||
|
|
||
| export const AbbyDevtools = withDevtools(DevtoolsFactory); | ||
| ``` | ||
|
|
||
| Render `<AbbyDevtools />` once in your app. It is only rendered in development | ||
| mode unless `dangerouslyForceShow` is set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dist |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep scoped overrides reactive after a failed load.
If project-data loading returns
null, Vue callsmarkInitialized()without calling coreinit(). This leaveshasServerDatafalse. A later devtoolsupdateFlag("flag1", true)changes the core value, but this guard suppresses the subscription callback.useFeatureFlag()therefore retains its fallback value indefinitely.Allow notifications after fallback initialization. Keep variant selection deferred while the request is pending.