UNPKG

flagmint-vuejs-feature-flags

Version:

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

42 lines (40 loc) 1.19 kB
const useFlagsMixin = { data() { return { isFlagReady: false, flagClient: null, }; }, async created() { if (typeof this.$flagmintReady !== 'undefined') { await this.$flagmintReady; this.flagClient = this.$flagmint; this.isFlagReady = true; } }, mounted() { this.$nextTick(() => { if (typeof this.$flagmintReady !== 'undefined') { this.isFlagReady = true; this.$watch('$flagmintReady', (val) => { this.isFlagReady = val; }); } else if (typeof this.$flagmintInit === 'function') { this.$flagmintInit().then((client) => { this.flagClient = client; this.isFlagReady = true; }); } }); }, methods: { getFlag(key, fallback) { if (this.flagClient && typeof this.flagClient.getFlag === 'function') { return this.flagClient.getFlag(key, fallback); } return fallback; } } }; export { useFlagsMixin };