Skip to content

Commit f6816f2

Browse files
Anton LillebyAnton Lilleby
authored andcommitted
refactor: remove unused ref
1 parent 6358e5c commit f6816f2

File tree

10 files changed

+61
-129
lines changed

10 files changed

+61
-129
lines changed

README.md

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,22 @@ Replace 'your-azure-configuration-readonly-connection-string' with your actual c
3131

3232
## Using in Vue Components
3333

34-
The plugin provides two methods: getFeatureFlag for a non-reactive, one-time check, and getFeatureFlagReactive for a reactive, continuously updated check.
35-
36-
### Using getFeatureFlagReactive
37-
38-
For a ref check of the feature flag:
39-
40-
```html
41-
<script setup lang="ts">
42-
import { inject } from "vue";
43-
import { FeatureFlagsManagerKey } from "vue3-app-configuration";
44-
45-
const { getFeatureFlag } = inject(FeatureFlagsManagerKey);
46-
47-
const isFeatureEnabled = getFeatureFlagRef(
48-
"your-feature-flag-name",
49-
"your-label"
50-
);
51-
</script>
52-
53-
<template>
54-
<p v-if="isFeatureEnabled">This feature is enabled!</p>
55-
<p v-else>This feature is disabled.</p>
56-
</template>
57-
```
58-
59-
### Using getFeatureFlag
60-
61-
For a one-time check of the feature flag:
34+
This plugin provides a non-reactive, one-time check called getFeatureFlag
6235

6336
```html
6437
<script setup lang="ts">
6538
import { inject, onMounted } from "vue";
6639
import { FeatureFlagsManagerKey } from "vue3-app-configuration";
6740
68-
const { getFeatureFlag } = inject(FeatureFlagsManagerKey);
6941
const isFeatureEnabled = ref(false);
42+
const featureFlagsManager = inject(FeatureFlagsManagerKey);
7043
7144
onMounted(async () => {
72-
isFeatureEnabled.value = await getFeatureFlag(
73-
"your-feature-flag-name', 'your-label"
74-
);
45+
if (featureFlagsManager) {
46+
isFeatureEnabled.value = await getFeatureFlag(
47+
"your-feature-flag-name', 'your-label"
48+
);
49+
}
7550
});
7651
</script>
7752

dist/index.d.mts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { InjectionKey, App } from 'vue';
22

3-
interface FeatureFlagsManager {
4-
getFeatureFlag(name: string, label?: string): Promise<boolean>;
5-
}
6-
declare const FeatureFlagsManagerKey: InjectionKey<FeatureFlagsManager>;
3+
type GetFeatureFlagFunction = (name: string, label?: string) => Promise<boolean>;
4+
declare const FeatureFlagsManagerKey: InjectionKey<{
5+
getFeatureFlag: GetFeatureFlagFunction;
6+
}>;
77
declare function AppConfigurationPlugin(app: App, connectionString?: string): void;
88

99
export { AppConfigurationPlugin, FeatureFlagsManagerKey };

dist/index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { InjectionKey, App } from 'vue';
22

3-
interface FeatureFlagsManager {
4-
getFeatureFlag(name: string, label?: string): Promise<boolean>;
5-
}
6-
declare const FeatureFlagsManagerKey: InjectionKey<FeatureFlagsManager>;
3+
type GetFeatureFlagFunction = (name: string, label?: string) => Promise<boolean>;
4+
declare const FeatureFlagsManagerKey: InjectionKey<{
5+
getFeatureFlag: GetFeatureFlagFunction;
6+
}>;
77
declare function AppConfigurationPlugin(app: App, connectionString?: string): void;
88

99
export { AppConfigurationPlugin, FeatureFlagsManagerKey };

dist/index.js

Lines changed: 19 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.mjs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,33 @@ import {
2626
isFeatureFlag,
2727
parseFeatureFlag
2828
} from "@azure/app-configuration";
29+
var FeatureFlagsManagerKey = Symbol("FeatureFlagsManager");
2930
var featureFlagsManager = (connectionString) => {
3031
let client = null;
3132
if (connectionString) {
3233
client = new AppConfigurationClient(connectionString);
3334
}
34-
return {
35-
getFeatureFlag(name, label) {
36-
return __async(this, null, function* () {
37-
if (!client) {
38-
console.warn(
39-
"[App Configuration Plugin] AppConfigurationClient is not initialized."
40-
);
41-
return false;
42-
}
43-
try {
44-
const response = yield client.getConfigurationSetting({
45-
key: `${featureFlagPrefix}${name}`,
46-
label
47-
});
48-
if (!isFeatureFlag(response))
49-
return false;
50-
return parseFeatureFlag(response).value.enabled;
51-
} catch (error) {
52-
console.error(
53-
"[App Configuration Plugin] Error fetching feature flag.",
54-
error
55-
);
56-
return false;
57-
}
35+
const getFeatureFlag = (name, label) => __async(void 0, null, function* () {
36+
if (!client)
37+
return false;
38+
try {
39+
const response = yield client.getConfigurationSetting({
40+
key: `${featureFlagPrefix}${name}`,
41+
label
5842
});
43+
if (!isFeatureFlag(response))
44+
return false;
45+
return parseFeatureFlag(response).value.enabled;
46+
} catch (error) {
47+
console.error(
48+
"[App Configuration Plugin] Error retrieving feature flag.",
49+
error
50+
);
51+
return false;
5952
}
60-
};
53+
});
54+
return { getFeatureFlag };
6155
};
62-
var FeatureFlagsManagerKey = Symbol(
63-
"FeatureFlagsManager"
64-
);
6556
function AppConfigurationPlugin(app, connectionString) {
6657
app.provide(FeatureFlagsManagerKey, featureFlagsManager(connectionString));
6758
}

dist/index.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-app-configuration",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A Vue 3 plugin for integrating Azure App Configuration, including feature flags management.",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/index.ts

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@ import {
44
isFeatureFlag,
55
parseFeatureFlag,
66
} from "@azure/app-configuration";
7-
import { ref, type App, type InjectionKey, type Ref } from "vue";
8-
9-
interface FeatureFlagsManager {
10-
getFeatureFlag(name: string, label?: string): Promise<boolean>;
11-
getFeatureFlagRef(name: string, label?: string): Ref<boolean>;
12-
}
7+
import { type App, type InjectionKey } from "vue";
138

149
type GetFeatureFlagFunction = (
1510
name: string,
1611
label?: string
1712
) => Promise<boolean>;
1813

19-
type GetFeatureFlagRefFunction = (name: string, label?: string) => Ref<boolean>;
14+
interface FeatureFlagsManager {
15+
getFeatureFlag: GetFeatureFlagFunction;
16+
}
2017

2118
const FeatureFlagsManagerKey: InjectionKey<{
2219
getFeatureFlag: GetFeatureFlagFunction;
23-
getFeatureFlagRef: GetFeatureFlagRefFunction;
2420
}> = Symbol("FeatureFlagsManager");
2521

2622
const featureFlagsManager = (
@@ -53,28 +49,7 @@ const featureFlagsManager = (
5349
}
5450
};
5551

56-
const getFeatureFlagRef = (name: string, label?: string): Ref<boolean> => {
57-
const isEnabled = ref(false);
58-
59-
if (!client) return isEnabled;
60-
61-
client
62-
.getConfigurationSetting({ key: `${featureFlagPrefix}${name}`, label })
63-
.then((response) => {
64-
if (!isFeatureFlag(response)) return false;
65-
isEnabled.value = parseFeatureFlag(response).value.enabled;
66-
})
67-
.catch((error) => {
68-
console.error(
69-
"[App Configuration Plugin] Error retrieving feature flag",
70-
error
71-
);
72-
});
73-
74-
return isEnabled;
75-
};
76-
77-
return { getFeatureFlag, getFeatureFlagRef };
52+
return { getFeatureFlag };
7853
};
7954

8055
function AppConfigurationPlugin(app: App, connectionString?: string) {

src/test.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)