@flipfeatureflag/vue 0.1.8 → 0.1.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipfeatureflag/vue",
3
- "version": "0.1.8",
3
+ "version": "0.1.11",
4
4
  "description": "flipFeatureFlag Vue SDK",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -20,7 +20,10 @@
20
20
  "vue": ">=3"
21
21
  },
22
22
  "dependencies": {
23
- "@flipfeatureflag/core": "0.1.7",
24
- "@flipfeatureflag/js": "0.1.8"
25
- }
23
+ "@flipfeatureflag/core": "0.1.10",
24
+ "@flipfeatureflag/js": "0.1.11"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ]
26
29
  }
package/src/index.ts DELETED
@@ -1,87 +0,0 @@
1
- import { App, inject, InjectionKey, reactive, readonly, ref, onUnmounted, Ref } from "vue";
2
- import { FlipFlagClient, FlipFlagClientOptions, FlagsStatus, SdkFlagEvaluation } from "@flipfeatureflag/core";
3
- import { createClient as createBrowserClient } from "@flipfeatureflag/js";
4
-
5
- const clientKey: InjectionKey<FlipFlagClient> = Symbol("FlipFlagClient");
6
- const statusKey: InjectionKey<FlagsStatus> = Symbol("FlipFlagStatus");
7
-
8
- export interface FlipFlagPluginOptions {
9
- client?: FlipFlagClient;
10
- config?: FlipFlagClientOptions;
11
- }
12
-
13
- export function createFlipFlag(options: FlipFlagPluginOptions) {
14
- return {
15
- install(app: App) {
16
- const client = options.client ?? (options.config ? createBrowserClient(options.config) : null);
17
- if (!client) {
18
- throw new Error("flipFeatureFlag plugin requires client or config");
19
- }
20
-
21
- const status = reactive<FlagsStatus>({ ...client.getStatus() });
22
-
23
- const handleUpdate = () => {
24
- Object.assign(status, client.getStatus());
25
- };
26
-
27
- client.on("ready", handleUpdate);
28
- client.on("update", handleUpdate);
29
- client.on("error", handleUpdate);
30
-
31
- void client.start();
32
-
33
- app.provide(clientKey, client);
34
- app.provide(statusKey, readonly(status));
35
- },
36
- };
37
- }
38
-
39
- export function useFlipFlagClient(): FlipFlagClient {
40
- const client = inject(clientKey, null);
41
- if (!client) {
42
- throw new Error("useFlipFlagClient must be used within flipFeatureFlag plugin");
43
- }
44
- return client;
45
- }
46
-
47
- export function useFlagsStatus(): FlagsStatus {
48
- const status = inject(statusKey, null);
49
- if (!status) {
50
- throw new Error("useFlagsStatus must be used within flipFeatureFlag plugin");
51
- }
52
- return status;
53
- }
54
-
55
- export function useFlag(flagKey: string, defaultValue = false): Ref<boolean> {
56
- const client = useFlipFlagClient();
57
- const state = ref(client.isEnabled(flagKey, defaultValue));
58
-
59
- const update = () => {
60
- state.value = client.isEnabled(flagKey, defaultValue);
61
- };
62
-
63
- client.on("update", update);
64
- onUnmounted(() => client.off("update", update));
65
-
66
- return state;
67
- }
68
-
69
- export function useVariant(
70
- flagKey: string,
71
- defaultValue: SdkFlagEvaluation["value"] = false,
72
- ): Ref<SdkFlagEvaluation> {
73
- const client = useFlipFlagClient();
74
- const state = ref(client.getVariant(flagKey, defaultValue));
75
-
76
- const update = () => {
77
- state.value = client.getVariant(flagKey, defaultValue);
78
- };
79
-
80
- client.on("update", update);
81
- onUnmounted(() => client.off("update", update));
82
-
83
- return state;
84
- }
85
-
86
- export type { FlipFlagClientOptions } from "@flipfeatureflag/core";
87
- export { FlipFlagClient } from "@flipfeatureflag/core";
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["src"]
4
- }