configcat-vue 0.1.4
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/README.md +168 -0
- package/dist/configcat-vue.js +1724 -0
- package/dist/configcat-vue.umd.cjs +5 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# configcat-vue
|
|
2
|
+
|
|
3
|
+
## Pre-requisites
|
|
4
|
+
|
|
5
|
+
- [Vue 3](https://vuejs.org/)
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
1. Install the npm package:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install configcat-vue
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
In your `main.js` file:
|
|
18
|
+
|
|
19
|
+
1. Import the plugin
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { ConfigCatPlugin } from 'configcat-vue';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Use the plugin:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
app.use(ConfigCatPlugin, {
|
|
29
|
+
SDKKey: "YOUR-CONFIGCAT-SDK-KEY", // SDKKey is required
|
|
30
|
+
clientOptions: { // clientOptions is optional
|
|
31
|
+
pollIntervalSeconds: 95,
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Using the FeatureWrapper component
|
|
37
|
+
|
|
38
|
+
The **FeatureWrapper** component allows you to wrap features, components, and HTML within your Vue3 app. When the feature flag is enabled, the wrapped components are rendered.
|
|
39
|
+
|
|
40
|
+
1. In your `.vue` file import the **FeatureWrapper** component:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
<script>
|
|
44
|
+
import { FeatureWrapper } from "configcat-vue";
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
components: {
|
|
48
|
+
FeatureWrapper,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
</script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
2. You can use it in your template by passing your feature key to the **featureKey** prop:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
<template>
|
|
58
|
+
<div class="my-app">
|
|
59
|
+
<FeatureWrapper featureKey="featurekey">
|
|
60
|
+
<p>
|
|
61
|
+
This will show if the feature flag with <b>featurekey</b> is enabled in
|
|
62
|
+
ConfigCat
|
|
63
|
+
</p>
|
|
64
|
+
</FeatureWrapper>
|
|
65
|
+
</div>
|
|
66
|
+
</template>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
3. That's it! Need to know more? check out the [**Advanced usage**](https://github.com/codedbychavez/configcat-vue#advanced-usage) section below.
|
|
70
|
+
|
|
71
|
+
## Advanced usage
|
|
72
|
+
|
|
73
|
+
### Using the plugin with a logger
|
|
74
|
+
|
|
75
|
+
The plugin can also be used with a logger, as explained in the [ConfigCat Docs](https://configcat.com/docs/sdk-reference/js/#logging).
|
|
76
|
+
|
|
77
|
+
1. Install the `configcat-js` npm package:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npm install configcat-js
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Then in `main.js`:
|
|
84
|
+
|
|
85
|
+
2. Import ConfigCat:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import * as configcat from 'configcat-js';
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
3. Create the logger:
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const logger = configcat.createConsoleLogger(3);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
4. Use the logger in `clientOptions`:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
app.use(ConfigCatPlugin, {
|
|
101
|
+
SDKKey: "YOUR-CONFIGCAT-SDK-KEY", // SDKKey is required
|
|
102
|
+
clientOptions: { // clientOptions is optional
|
|
103
|
+
pollIntervalSeconds: 95,
|
|
104
|
+
logger: logger,
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
### Using the FeatureWrapper with a User Object
|
|
109
|
+
|
|
110
|
+
According to the documentation for ConfigCat, the [User Object](https://configcat.com/docs/advanced/user-object/) can be used to pass potential Targeting rules variables. In addition, it allows you to represent a user in your application.
|
|
111
|
+
|
|
112
|
+
A User Object can be passed as a prop to the **Feature Wrapper** component.
|
|
113
|
+
|
|
114
|
+
1. Define the User Object as a **data** property
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
<script>
|
|
118
|
+
import { FeatureWrapper } from "configcat-vue";
|
|
119
|
+
|
|
120
|
+
export default {
|
|
121
|
+
components: {
|
|
122
|
+
FeatureWrapper,
|
|
123
|
+
},
|
|
124
|
+
data() {
|
|
125
|
+
return {
|
|
126
|
+
userObject: { // Passing userObject as a prop to the FeatureWrapper is optional
|
|
127
|
+
identifier: 'john@example.com',
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
</script>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
2. Pass it to the **userObject** prop:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
<template>
|
|
139
|
+
<div class="my-app">
|
|
140
|
+
<FeatureWrapper featureKey="featurekey" :userObject="userObject">
|
|
141
|
+
<p>
|
|
142
|
+
This will show if the feature flag with <b>featurekey</b> is enabled in
|
|
143
|
+
ConfigCat
|
|
144
|
+
</p>
|
|
145
|
+
</FeatureWrapper>
|
|
146
|
+
</div>
|
|
147
|
+
</template>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Sample app
|
|
151
|
+
|
|
152
|
+
**[https://github.com/codedbychavez/configcat-vue-sample](https://github.com/codedbychavez/configcat-vue-sample)**
|
|
153
|
+
|
|
154
|
+
## References
|
|
155
|
+
|
|
156
|
+
### Logging
|
|
157
|
+
|
|
158
|
+
- [https://configcat.com/docs/sdk-reference/js/#user-object](https://configcat.com/docs/sdk-reference/js/#user-object)
|
|
159
|
+
|
|
160
|
+
### Polling modes
|
|
161
|
+
|
|
162
|
+
- [https://configcat.com/docs/sdk-reference/js/#user-object](https://configcat.com/docs/sdk-reference/js/#user-object)
|
|
163
|
+
|
|
164
|
+
### User Object
|
|
165
|
+
|
|
166
|
+
- [https://configcat.com/docs/advanced/user-object](https://configcat.com/docs/advanced/user-object/)
|
|
167
|
+
|
|
168
|
+
- [https://configcat.com/docs/sdk-reference/js/#user-object](https://configcat.com/docs/sdk-reference/js/#user-object)
|