Hi!
I'm testing LaunchDarkly in Vue 3.2 through LaunchDarkly Client SDK v1.2.1. I don't want to pollute my application code with SDK calls directly in components. My idea is to move all LD handling into separate Pinia store slice. Rough idea shown below:
import type { Ref } from 'vue';
import { defineStore } from 'pinia';
import { useLDFlag } from 'launchdarkly-vue-client-sdk';
export const useFeatureFlagsStore = defineStore(
'LaunchDarklyFeatureFlags',
() => {
const flagOne: Readonly<Ref<boolean>> = useLDFlag('flagOne', false);
const flagTwo: () => Readonly<Ref<boolean>> = () =>
useLDFlag('flagTwo', false);
const flagThree = computed(() => useLDFlag('flagThree', false));
return {
flagOne,
flagTwo,
flagThree,
};
}
);
This does not work. useLDFlag description states:
Evaluates a single feature flag. Automatically subscribes to streamed updates
unless the `streaming` option was set to false.
Uses Vue's inject API, so will only work if run inside a Vue setup hook or `<script setup>`.
I was not able to find solution in the docs. Is there any known way to work around that? Unfortunately this is make or break situation for me when it comes to using LaunchDarkly altogether.
From my understanding this is somewhere between feature request and bug report. SDK should allow to do this kind of stuff otherwise it is incomplete at best.
Any help is appreciated. Thanks!
Hi!
I'm testing LaunchDarkly in Vue 3.2 through LaunchDarkly Client SDK v1.2.1. I don't want to pollute my application code with SDK calls directly in components. My idea is to move all LD handling into separate Pinia store slice. Rough idea shown below:
This does not work.
useLDFlagdescription states:I was not able to find solution in the docs. Is there any known way to work around that? Unfortunately this is make or break situation for me when it comes to using LaunchDarkly altogether.
From my understanding this is somewhere between feature request and bug report. SDK should allow to do this kind of stuff otherwise it is incomplete at best.
Any help is appreciated. Thanks!