-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: Add Vue integration for Abby with feature parity to React #141
base: main
Are you sure you want to change the base?
Changes from 1 commit
fa20856
9b6796e
f0fd88d
313a8fd
d79d726
70df887
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,9 @@ | ||
{ | ||
"extends": [ | ||
"development" | ||
], | ||
"hints": { | ||
"typescript-config/consistent-casing": "off", | ||
"typescript-config/strict": "off" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./context"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./context"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./context"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export declare function useAbby(experimentName: string): { | ||
variant: import("vue").Ref<any>; | ||
onAct: any; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export declare function useAbby(experimentName: string): { | ||
variant: import("vue").Ref<any>; | ||
onAct: any; | ||
}; | ||
a | ||
feliciien marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ref, onMounted } from 'vue'; | ||
import { createAbby, ABTestReturnValue } from '@tryabby/core'; | ||
feliciien marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export function useAbby(experimentName: string): ABTestReturnValue { | ||
const abby = createAbby(); | ||
const variant = ref<string | null>(null); | ||
|
||
onMounted(() => { | ||
variant.value = abby.getVariant(experimentName); | ||
}); | ||
|
||
return { | ||
variant, | ||
onAct: abby.onAct | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export declare function useAbby(experimentName: string): { | ||
variant: import("vue").Ref<any>; | ||
onAct: any; | ||
}; | ||
a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export declare function useAbby(experimentName: string): { | ||
variant: import("vue").Ref<any>; | ||
onAct: any; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "vue", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "run-p type-check \"build-only {@}\" --", | ||
"preview": "vite preview", | ||
"test:unit": "vitest", | ||
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'", | ||
"test:e2e:dev": "start-server-and-test 'vite dev --port 4173' http://localhost:4173 'cypress open --e2e'", | ||
"build-only": "vite build", | ||
"type-check": "vue-tsc --build --force", | ||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", | ||
"format": "prettier --write src/" | ||
}, | ||
"dependencies": { | ||
"@tryabby/core": "workspace:^", | ||
"@vue/compiler-sfc": "^3.4.27", | ||
"vue": "^3.4.21" | ||
}, | ||
"devDependencies": { | ||
"@rushstack/eslint-patch": "^1.8.0", | ||
"@tsconfig/node20": "^20.1.4", | ||
"@types/jsdom": "^21.1.6", | ||
"@types/node": "^20.12.5", | ||
"@vitejs/plugin-vue": "^5.0.4", | ||
"@vue/eslint-config-prettier": "^9.0.0", | ||
"@vue/eslint-config-typescript": "^13.0.0", | ||
"@vue/test-utils": "^2.4.5", | ||
"@vue/tsconfig": "^0.5.1", | ||
"cypress": "^13.7.2", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-cypress": "^2.15.1", | ||
"eslint-plugin-vue": "^9.23.0", | ||
"jsdom": "^24.0.0", | ||
"npm-run-all2": "^6.1.2", | ||
"prettier": "^3.2.5", | ||
"start-server-and-test": "^2.0.3", | ||
"typescript": "~5.4.2", | ||
"vite": "^5.2.8", | ||
"vite-plugin-vue-devtools": "^7.0.25", | ||
"vitest": "^1.4.0", | ||
"vue-tsc": "^2.0.11" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "vue", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "run-p type-check \"build-only {@}\" --", | ||
"preview": "vite preview", | ||
"test:unit": "vitest", | ||
"test:e2e": "start-server-and-test preview http://localhost:4173 'cypress run --e2e'", | ||
"test:e2e:dev": "start-server-and-test 'vite dev --port 4173' http://localhost:4173 'cypress open --e2e'", | ||
"build-only": "vite build", | ||
"type-check": "vue-tsc --build --force", | ||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", | ||
"format": "prettier --write src/" | ||
}, | ||
"dependencies": { | ||
"@tryabby/core": "workspace:^", | ||
"@vue/compiler-sfc": "^3.4.27", | ||
"vue": "^3.4.21" | ||
}, | ||
"devDependencies": { | ||
"@rushstack/eslint-patch": "^1.8.0", | ||
"@tsconfig/node20": "^20.1.4", | ||
"@types/jsdom": "^21.1.6", | ||
"@types/node": "^20.12.5", | ||
"@vitejs/plugin-vue": "^5.0.4", | ||
"@vue/eslint-config-prettier": "^9.0.0", | ||
"@vue/eslint-config-typescript": "^13.0.0", | ||
"@vue/test-utils": "^2.4.5", | ||
"@vue/tsconfig": "^0.5.1", | ||
"cypress": "^13.7.2", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-cypress": "^2.15.1", | ||
"eslint-plugin-vue": "^9.23.0", | ||
"jsdom": "^24.0.0", | ||
"npm-run-all2": "^6.1.2", | ||
"prettier": "^3.2.5", | ||
"start-server-and-test": "^2.0.3", | ||
"typescript": "~5.4.2", | ||
"vite": "^5.2.8", | ||
"vite-plugin-vue-devtools": "^7.0.25", | ||
"vitest": "^1.4.0", | ||
"vue-tsc": "^2.0.11" | ||
} | ||
} | ||
a | ||
feliciien marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@tryabby/vue", | ||
"version": "0.1.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@tryabby/core": "^1.0.0", | ||
"vue": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^4.0.0", | ||
"@vue/compiler-sfc": "^3.0.0", | ||
"jest": "^26.0.0", | ||
"@types/jest": "^26.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { inject, provide, reactive } from 'vue'; | ||
|
||
const AbbySymbol = Symbol(); | ||
|
||
export function provideAbby(abby) { | ||
const state = reactive({ | ||
flags: abby.getFeatureFlags(), | ||
tests: abby.getTests(), | ||
}); | ||
|
||
provide(AbbySymbol, state); | ||
} | ||
|
||
export function useFeatureFlag(flagName) { | ||
const abby = inject(AbbySymbol); | ||
if (!abby) { | ||
throw new Error("useFeatureFlag must be used within a component that provides Abby data."); | ||
} | ||
return abby.flags[flagName]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { useAbby } from './useAbby'; | ||
export { useFeatureFlag } from './useFeatureFlag'; | ||
export { useRemoteConfig } from './useRemoteConfig'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import './assets/main.css' | ||
|
||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import './assets/main.css' | ||
|
||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') | ||
a | ||
feliciien marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./context"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./context"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { createAbby, type withDevtoolsFunction, type ABTestReturnValue } from "./packages/vue/src/context.tsx"; | ||
export { type ABConfig, type AbbyConfig, defineConfig } from "@tryabby/core"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import './assets/main.css' | ||
|
||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import './assets/main.css' | ||
|
||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
|
||
createApp(App).mount('#app') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { onMounted, ref } from 'vue'; | ||
import { getCurrentVariant, onAct } from '@tryabby/core'; | ||
|
||
export function useAbby(experimentName: string) { | ||
const variant = ref<string | null>(null); | ||
|
||
onMounted(() => { | ||
variant.value = getCurrentVariant(experimentName); | ||
}); | ||
|
||
return { | ||
variant, | ||
onAct | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { onMounted, ref } from 'vue'; | ||
import { getCurrentVariant, onAct } from '@tryabby/core'; | ||
|
||
export function useAbby(experimentName: string) { | ||
const variant = ref<string | null>(null); | ||
|
||
onMounted(() => { | ||
variant.value = getCurrentVariant(experimentName); | ||
}); | ||
|
||
return { | ||
variant, | ||
onAct | ||
}; | ||
} | ||
a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { onMounted, ref } from 'vue'; | ||
import { getVariant, onAct } from '@tryabby/core'; | ||
|
||
export function useAbby(experimentName: string) { | ||
const variant = ref<string | null>(null); | ||
|
||
onMounted(() => { | ||
variant.value = getVariant(experimentName); | ||
}); | ||
|
||
return { | ||
variant, | ||
onAct | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { onMounted, ref } from 'vue'; | ||
import { getFlag } from '@tryabby/core'; | ||
|
||
export function useFeatureFlag(flagName: string) { | ||
const flagValue = ref<boolean | null>(null); | ||
|
||
onMounted(() => { | ||
flagValue.value = getFlag(flagName); | ||
}); | ||
|
||
return { | ||
flagValue | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { onMounted, ref } from 'vue'; | ||
import { getConfig } from '@tryabby/core'; | ||
|
||
export function useRemoteConfig(configName: string) { | ||
const configValue = ref<any>(null); | ||
|
||
onMounted(() => { | ||
configValue.value = getConfig(configName); | ||
}); | ||
|
||
return { | ||
configValue | ||
}; | ||
} | ||
Comment on lines
+1
to
+14
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. The - 5~
- const configValue = ref<any>(null);
+ const configValue = ref<ConfigType | null>(null); // Replace `ConfigType` with the actual expected type
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useAbby } from '../src/useAbby'; | ||
import { mount } from '@vue/test-utils'; | ||
|
||
test('useAbby returns correct variant', () => { | ||
const experimentName = 'test-experiment'; | ||
const wrapper = mount({ | ||
template: '<div>{{ variant }}</div>', | ||
setup() { | ||
const { variant } = useAbby(experimentName); | ||
return { variant }; | ||
} | ||
}); | ||
|
||
// Mock the result to match your expectations | ||
expect(wrapper.text()).toBe('variant-A'); // Assuming 'variant-A' is the expected result | ||
}); | ||
Comment on lines
+4
to
+16
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. Consider improving the test to reflect actual functionality rather than using a mocked result. - // Mock the result to match your expectations
- expect(wrapper.text()).toBe('variant-A'); // Assuming 'variant-A' is the expected result
+ // TODO: Implement a more realistic test that does not rely on mocked results
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"files": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.node.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.vitest.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"module": "NodeNext" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"files": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.node.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.vitest.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"module": "NodeNext" | ||
} | ||
} |
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.
Specify more precise types instead of
any
for better type safety.