@flipfeatureflag/vue 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.ts +19 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipfeatureflag/vue",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "flipFeatureFlag Vue SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -20,7 +20,7 @@
20
20
  "vue": ">=3"
21
21
  },
22
22
  "dependencies": {
23
- "@flipfeatureflag/core": "0.1.6",
24
- "@flipfeatureflag/js": "0.1.7"
23
+ "@flipfeatureflag/core": "0.1.8",
24
+ "@flipfeatureflag/js": "0.1.9"
25
25
  }
26
26
  }
package/src/index.ts CHANGED
@@ -52,12 +52,28 @@ export function useFlagsStatus(): FlagsStatus {
52
52
  return status;
53
53
  }
54
54
 
55
- export function useFlag(flagKey: string, defaultValue = false): Ref<boolean> {
55
+ export interface FlagValueResult<T = SdkFlagEvaluation["value"]> {
56
+ value: T;
57
+ enabled: boolean;
58
+ }
59
+
60
+ function toFlagResult(evaluation: SdkFlagEvaluation, known: boolean): FlagValueResult {
61
+ const enabled = known && evaluation.reason !== "disabled";
62
+ return {
63
+ value: evaluation.value,
64
+ enabled,
65
+ };
66
+ }
67
+
68
+ export function useFlag(
69
+ flagKey: string,
70
+ defaultValue: SdkFlagEvaluation["value"] = false,
71
+ ): Ref<FlagValueResult> {
56
72
  const client = useFlipFlagClient();
57
- const state = ref(client.isEnabled(flagKey, defaultValue));
73
+ const state = ref(toFlagResult(client.getVariant(flagKey, defaultValue), client.hasFlag(flagKey)));
58
74
 
59
75
  const update = () => {
60
- state.value = client.isEnabled(flagKey, defaultValue);
76
+ state.value = toFlagResult(client.getVariant(flagKey, defaultValue), client.hasFlag(flagKey));
61
77
  };
62
78
 
63
79
  client.on("update", update);