UNPKG

flagmint-vuejs-feature-flags

Version:

A Vue.js SDK for managing feature flags in Flagmint applications, supporting both Vue 2 and Vue 3.

41 lines (37 loc) 1.18 kB
import { inject } from 'vue'; const FLAGMINT_INIT = Symbol.for('FLAGMINT_INIT'); const FLAGMINT_READY = Symbol.for('FLAGMINT_READY'); const FLAGMINT_CLIENT = Symbol.for('FLAGMINT_CLIENT'); /** * useFlagmint composable to access the FlagClient instance, its readiness state, and an initialization function. * This composable is designed to be used in Vue 3 applications to manage feature flags. * @returns An object containing the FlagClient instance, a boolean indicating if the client is ready, and an init function to initialize the client. */ function useFlagmint() { let client; let isReady; let init; const resolve = () => { client = inject(FLAGMINT_CLIENT, null); isReady = inject(FLAGMINT_READY, null); init = inject(FLAGMINT_INIT, null); }; return { get client() { if (!client) resolve(); return client; }, get isReady() { if (!isReady) resolve(); return isReady; }, get init() { if (!init) resolve(); return init; } }; } export { useFlagmint };