-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add vue integration #167
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dist |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| # @tryabby/vue | ||
|
|
||
| ## createAbby | ||
|
|
||
| ### Parameters | ||
|
|
||
| The `createAbby` function takes an object as a parameter. The object can contain the following properties: | ||
|
|
||
| | Name | Type | Required | Description | details | | ||
| | ------------------ | -------- | :------: | ------------------------------------------------------- | --------------------- | | ||
| | projectId | `string` | ✅ | The ID of your project in Abby | - | | ||
| | apiUrl | `string` | | The URL of the Abby API. Defaults to the hosted version | - | | ||
| | currentEnvironment | `string` | ✅ | The current environment of your application | [link](/environments) | | ||
| | tests | `object` | | An object containing your defined A/B Tests | - | | ||
| | flags | `object` | | An array containing your defined Feature Flags | - | | ||
| | settings | `object` | | An object with additional settings for Abby | - | | ||
|
|
||
| #### tests | ||
|
|
||
| The tests property is an object containing your defined A/B Tests. You probably want to use the Copy Button in your dashboard to copy the tests object. | ||
| They keys of the object represent the names of your predefined A/B tests. The values are objects containing the following properties: | ||
|
|
||
| | Name | Type | Required | Description | | ||
| | -------- | --------------- | :------: | ------------------------------------------------------- | | ||
| | variants | `Array<string>` | ✅ | An array of strings containing the variants of the test | | ||
|
|
||
| ##### Example | ||
|
|
||
| ```ts | ||
| const abby = createAbby({ | ||
| // ... your config | ||
| tests: { | ||
| "test-abtest": { | ||
| variants: ["control", "variant-a", "variant-b"], | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| #### flags | ||
|
|
||
| The flags property is an array containing your defined Feature Flags. You probably want to use the Copy Button in your dashboard to copy the flags array. | ||
|
|
||
| ##### Example | ||
|
|
||
| ```ts | ||
| const abby = createAbby({ | ||
| // ... your config | ||
| flags: { "test-flag": "Boolean" }, | ||
| }); | ||
| ``` | ||
|
|
||
| #### settings | ||
|
|
||
| The settings property is an object containing additional settings for Abby. The following properties are available: | ||
|
|
||
| - `flags.defaultValues`: Allows you to set a general default value for each flag type. The keys of the object represent the types of the flags. | ||
| The default value is the following: | ||
|
|
||
| ```json | ||
| { | ||
| "Boolean": false, | ||
| "String": "", | ||
| "Number": 0, | ||
| "JSON": {} | ||
| } | ||
| ``` | ||
|
|
||
| - `flags.devOverrides`: An object containing the values of feature flags in development mode. The keys of the object represent the names of the flags. | ||
| The values need to be of the type of the flag. This means if your flag is a `String` flag, this needs to be a `string`. | ||
|
|
||
| ### Return Values | ||
|
|
||
| #### useAbby | ||
|
|
||
| `useAbby` is a react hook that used to access the value of an A/B Test. | ||
| Recurring users will always get the same value for a test. | ||
| New users will get a random value for a test depending on the defined weights | ||
|
|
||
| ##### Parameters | ||
|
|
||
| - `string`: The name of the test or flag, needs to be one of the defined tests. | ||
|
|
||
| ##### Return Values | ||
|
|
||
| - `variant` : The variant of the test | ||
|
|
||
| - `onAct`: A function to call when the user performs an action associated with the test _Type: `function`_ | ||
|
|
||
| #### useFeatureFlag | ||
|
|
||
| `useFeatureFlag` is a react hook that used to access the value of a Feature Flag. | ||
|
|
||
| ##### Parameters | ||
|
|
||
| The name of the test or flag, needs to be one of the defined flags. | ||
|
|
||
| ##### Return Value | ||
|
|
||
| The value of the flag _Type: `boolean`_ | ||
|
|
||
| #### AbbyProvider | ||
|
|
||
| A react component to wrap your application. | ||
|
|
||
| ##### Props | ||
|
|
||
| - `children`: The children of the component | ||
| - `initialData (optional)`: The data (weights, tests, etc). If not provided, the data will be fetched on the client. | ||
|
|
||
| #### getFeatureFlagValue | ||
|
|
||
| `getFeatureFlagValue` is a function to access the value of a feature flag. This can be called in a non-react scope | ||
|
|
||
| ##### Parameters | ||
|
|
||
| The name of the test or flag, needs to be one of the defined flags. | ||
|
|
||
| #### getABTestValue | ||
|
|
||
| `getABTestValue` is a function to access the users variant of an A/B Test. This can be called in a non-react scope. | ||
| If the user is new, a random variant will be generated based on the weights, persisted in a cookie and returned. | ||
| Otherwise the variant will be read from the cookie and returned. | ||
|
|
||
| ##### Parameters | ||
|
|
||
| The name of the test, needs to be one of the defined tests. | ||
|
|
||
| ##### Return Values | ||
|
|
||
| The variant of the test. | ||
|
|
||
| #### withDevtools | ||
|
|
||
| `withDevtools` is a higher order function to wrap the Devtools from [`@tryabby/devtools`](/devtools) for usage within Reacts. | ||
|
|
||
| ##### Parameters | ||
|
|
||
| The Devtools component from `@tryabby/devtools` | ||
|
|
||
| ##### Example | ||
|
|
||
| ```jsx | ||
| import { AbbyDevTools } from "@tryabby/devtools"; | ||
| export const AbbyDevtools = withDevtools(AbbyDevTools); | ||
| ``` | ||
|
|
||
| #### getABResetFunction | ||
|
|
||
| This is a function which returns a function that can be used to reset the stored variant for the current user. | ||
| This means the cookie will be deleted and the user will get a new variant on the next page load. | ||
|
|
||
| #### Parameters | ||
|
|
||
| The name of the test, needs to be one of the defined tests. | ||
|
|
||
| #### Example | ||
|
|
||
| ```tsx | ||
| import { getABResetFunction } from "lib/abby"; | ||
|
|
||
| export default function SomePage() { | ||
| const onReset = () => { | ||
| const resetCookie = getABResetFunction("SignupButton"); | ||
| resetCookie(); | ||
| window.reload(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1>Hello World</h1> | ||
| <button onClick={onReset}>Reset Cookie</button> | ||
| </div> | ||
| ); | ||
| } | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,47 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "@tryabby/vue", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "version": "0.1.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "description": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "main": "dist/index.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "files": ["dist"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "module": "dist/index.mjs", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "types": "dist/index.d.ts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ".": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "types": "./dist/index.d.ts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "import": "./dist/index.mjs", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "require": "./dist/index.js" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "scripts": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "build": "tsup src/", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dev": "pnpm run build --watch", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "test": "vitest" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "homepage": "https://docs.tryabby.com", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "keywords": [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "author": "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "license": "ISC", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@testing-library/jest-dom": "^5.16.5", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@testing-library/react": "^13.4.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@testing-library/vue": "^8.1.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@vue/test-utils": "^2.4.6", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@tryabby/devtools": "workspace:*", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/js-cookie": "^3.0.3", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@vitejs/plugin-vue": "5.1.4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "jsdom": "^20.0.3", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "msw": "^0.49.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "node-fetch": "^3.3.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "tsconfig": "workspace:*", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "tsup": "^6.5.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "typescript": "5.5.4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vite": "5.4.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vitest": "2.0.5" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clean up development dependencies. There are several issues with the devDependencies:
Apply these changes: "devDependencies": {
- "@testing-library/jest-dom": "^5.16.5",
- "@testing-library/react": "^13.4.0",
"@testing-library/vue": "^8.1.0",
"@vue/test-utils": "^2.4.6",
"@tryabby/devtools": "workspace:*",
"@types/js-cookie": "^3.0.3",
"@vitejs/plugin-vue": "5.1.4",
"jsdom": "^20.0.3",
"msw": "^0.49.1",
"node-fetch": "^3.3.0",
"tsconfig": "workspace:*",
"tsup": "^6.5.0",
"typescript": "5.5.4",
"vite": "5.4.0",
- "vitest": "2.0.5"
+ "vitest": "2.0.5",
+ "vue": "^3.5.12"
},📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "peerDependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vue": "^3.5.12" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@tryabby/core": "workspace:*", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "js-cookie": "^3.0.1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type IStorageService, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getABStorageKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getFFStorageKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| getRCStorageKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "@tryabby/core"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { StorageServiceOptions } from "@tryabby/core/dist/shared/interfaces"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Cookie from "js-cookie"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const DEFAULT_COOKIE_AGE = 365; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class ABStorageService implements IStorageService { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get(projectId: string, testName: string): string | null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const retrievedValue = Cookie.get(getABStorageKey(projectId, testName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!retrievedValue) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return retrievedValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| projectId: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testName: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options?: StorageServiceOptions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.set(getABStorageKey(projectId, testName), value, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expires: options?.expiresInDays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? options.expiresInDays | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : DEFAULT_COOKIE_AGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remove(projectId: string, testName: string): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.remove(getABStorageKey(projectId, testName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and type validation The ABStorageService implementation should handle potential cookie-related errors and validate input types: class ABStorageService implements IStorageService {
get(projectId: string, testName: string): string | null {
+ try {
const retrievedValue = Cookie.get(getABStorageKey(projectId, testName));
if (!retrievedValue) return null;
return retrievedValue;
+ } catch (error) {
+ console.error(`Failed to retrieve A/B test value: ${error}`);
+ return null;
+ }
}
set(
projectId: string,
testName: string,
value: string,
options?: StorageServiceOptions
): void {
+ if (!projectId || !testName) {
+ throw new Error('Project ID and test name are required');
+ }
+ try {
Cookie.set(getABStorageKey(projectId, testName), value, {
expires: options?.expiresInDays
? options.expiresInDays
: DEFAULT_COOKIE_AGE,
});
+ } catch (error) {
+ console.error(`Failed to set A/B test value: ${error}`);
+ throw error;
+ }
}
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class FFStorageService implements IStorageService { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get(projectId: string, flagName: string): string | null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const retrievedValue = Cookie.get(getFFStorageKey(projectId, flagName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!retrievedValue) return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return retrievedValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set(projectId: string, flagName: string, value: string): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.set(getFFStorageKey(projectId, flagName), value, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expires: DEFAULT_COOKIE_AGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remove(projectId: string, flagName: string): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.remove(getFFStorageKey(projectId, flagName)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Reduce code duplication and standardize API Consider creating a base storage service class to reduce duplication and maintain consistency: +abstract class BaseStorageService implements IStorageService {
+ constructor(protected getStorageKey: (projectId: string, key: string) => string) {}
+
+ get(projectId: string, key: string): string | null {
+ try {
+ const retrievedValue = Cookie.get(this.getStorageKey(projectId, key));
+ return retrievedValue ?? null;
+ } catch (error) {
+ console.error(`Failed to retrieve value: ${error}`);
+ return null;
+ }
+ }
+
+ set(projectId: string, key: string, value: string, options?: StorageServiceOptions): void {
+ if (!projectId || !key) {
+ throw new Error('Project ID and key are required');
+ }
+ try {
+ Cookie.set(this.getStorageKey(projectId, key), value, {
+ expires: options?.expiresInDays ?? DEFAULT_COOKIE_AGE,
+ });
+ } catch (error) {
+ console.error(`Failed to set value: ${error}`);
+ throw error;
+ }
+ }
+
+ remove(projectId: string, key: string): void {
+ Cookie.remove(this.getStorageKey(projectId, key));
+ }
+}
-class FFStorageService implements IStorageService {
+class FFStorageService extends BaseStorageService {
+ constructor() {
+ super(getFFStorageKey);
+ }
- // Remove duplicated methods
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class RCStorageService implements IStorageService { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| get(projectId: string, key: string): string | null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const retrievedValue = Cookie.get(getRCStorageKey(projectId, key)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return retrievedValue ?? null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set(projectId: string, key: string, value: string): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.set(getRCStorageKey(projectId, key), value, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expires: DEFAULT_COOKIE_AGE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remove(projectId: string, key: string): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Cookie.remove(getRCStorageKey(projectId, key)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const TestStorageService = new ABStorageService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const FlagStorageService = new FFStorageService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const RemoteConfigStorageService = new RCStorageService(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Critical: Documentation contains React-specific content instead of Vue integration details
The documentation appears to be copied from the React package without proper adaptation for Vue. This needs to be completely reworked to use Vue-specific terminology and concepts:
Replace React hooks with Vue composables:
useAbbyshould be documented as a Vue composableuseFeatureFlagshould be documented as a Vue composableReplace React components with Vue components:
AbbyProvidershould be documented as a Vue component or pluginUpdate implementation examples to use Vue's composition API style
Would you like assistance in generating Vue-specific documentation templates for these sections?
🧰 Tools
🪛 LanguageTool
[grammar] ~21-~21: The pronoun ‘They’ must be used with a non-third-person form of a verb.
Context: ...ashboard to copy the tests object. They keys of the object represent the names of yo...
(NON3PRS_VERB)
[uncategorized] ~57-~57: Loose punctuation mark.
Context: ... are available: -
flags.defaultValues: Allows you to set a general default val...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~69-~69: Loose punctuation mark.
Context: ...N": {} } ``` -
flags.devOverrides: An object containing the values of feat...(UNLIKELY_OPENING_PUNCTUATION)
[grammar] ~76-~76: “React” is a proper noun and needs to be capitalized.
Context: ...rn Values #### useAbby
useAbbyis a react hook that used to access the value of a...(A_GOOGLE)
[uncategorized] ~82-~82: Loose punctuation mark.
Context: ...ed weights ##### Parameters -
string: The name of the test or flag, needs to ...(UNLIKELY_OPENING_PUNCTUATION)
[style] ~82-~82: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...
string: The name of the test or flag, needs to be one of the defined tests. ##### Ret...(REP_NEED_TO_VB)
[uncategorized] ~86-~86: Loose punctuation mark.
Context: ...ests. ##### Return Values -
variant: The variant of the test -onAct: A f...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~88-~88: Loose punctuation mark.
Context: ...nt
: The variant of the test -onAct`: A function to call when the user perfor...(UNLIKELY_OPENING_PUNCTUATION)
[grammar] ~92-~92: “React” is a proper noun and needs to be capitalized.
Context: ...# useFeatureFlag
useFeatureFlagis a react hook that used to access the value of a...(A_GOOGLE)
[grammar] ~104-~104: “React” is a proper noun and needs to be capitalized.
Context: ...Type:
boolean#### AbbyProvider A react component to wrap your application. ##...(A_GOOGLE)
[uncategorized] ~108-~108: Loose punctuation mark.
Context: ... application. ##### Props -
children: The children of the component - `initia...(UNLIKELY_OPENING_PUNCTUATION)
[style] ~109-~109: In American English, abbreviations like “etc.” require a period.
Context: ... (optional)`: The data (weights, tests, etc). If not provided, the data will be fet...
(ETC_PERIOD)
[uncategorized] ~122-~122: A comma may be missing after the conjunctive/linking adverb ‘Otherwise’.
Context: ...ts, persisted in a cookie and returned. Otherwise the variant will be read from the cooki...
(SENT_START_CONJUNCTIVE_LINKING_ADVERB_COMMA)
[formatting] ~127-~127: If the ‘needs’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...ned. ##### Parameters The name of the test, needs to be one of the defined tests. ##### ...
(COMMA_AFTER_PREPOSITION_PHRASES)
[uncategorized] ~135-~135: Did you mean the adjective “higher-order” (spelled with a hyphen)?
Context: ... #### withDevtools
withDevtoolsis a higher order function to wrap the Devtools from [`@t...(HIGHER_ORDER_HYPHEN)
[uncategorized] ~151-~151: Use a comma before “and” if it connects two independent clauses (unless they are closely connected and short).
Context: ...r. This means the cookie will be deleted and the user will get a new variant on the ...
(COMMA_COMPOUND_SENTENCE_2)
[formatting] ~155-~155: If the ‘needs’ clause is essential to the meaning, do not use a comma before the clause.
Context: ...load. #### Parameters The name of the test, needs to be one of the defined tests. #### E...
(COMMA_AFTER_PREPOSITION_PHRASES)