Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dashhudson/vue-ld
Vue LaunchDarkly plugin and routing utilities
https://github.com/dashhudson/vue-ld
Last synced: about 1 month ago
JSON representation
Vue LaunchDarkly plugin and routing utilities
- Host: GitHub
- URL: https://github.com/dashhudson/vue-ld
- Owner: dashhudson
- License: mit
- Created: 2020-08-05T17:43:01.000Z (almost 4 years ago)
- Default Branch: dev
- Last Pushed: 2023-02-09T07:38:50.000Z (over 1 year ago)
- Last Synced: 2024-01-08T08:50:53.273Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.61 MB
- Stars: 25
- Watchers: 13
- Forks: 5
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Lists
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
- awesome-vue - vue-ld - Vue LaunchDarkly plugin and routing utilities (Components & Libraries / Integrations)
README
# Vue LaunchDarkly
[![Mentioned in Awesome Vue.js](https://awesome.re/mentioned-badge.svg)](https://github.com/vuejs/awesome-vue#integrations)
[![Maintainability](https://api.codeclimate.com/v1/badges/d87da39dfb63340702bd/maintainability)](https://codeclimate.com/github/dashhudson/vue-ld/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/d87da39dfb63340702bd/test_coverage)](https://codeclimate.com/github/dashhudson/vue-ld/test_coverage) [![npm version](https://img.shields.io/npm/v/vue-ld?color=%23d6b034)](https://www.npmjs.com/package/vue-ld) [![Last Commit](https://img.shields.io/github/last-commit/dashhudson/vue-ld?color=%23d6b034)](https://github.com/dashhudson/vue-ld/graphs/commit-activity)
[![Licence](https://img.shields.io/github/license/dashhudson/vue-ld?color=%23d6b034)](https://github.com/dashhudson/vue-ld/blob/dev/LICENSE.txt) [![Stars](https://img.shields.io/github/stars/dashhudson/vue-ld?color=%23d6b034&logoColor=%23d6b034)](https://github.com/dashhudson/vue-ld)A simple wrapper around the [js-client-sdk](https://github.com/launchdarkly/js-client-sdk) that provides observable feature flags, a ready state to ensure all feature flags are up to date, and routing utilities. Compatabile with both Vue 2 and Vue 3 via [vue-demi](https://github.com/vueuse/vue-demi).
## Usage
### Installation
```bash
$ npm install --save vue-ld launchdarkly-js-client-sdk
```
- Requires `@vue/composition-api` for Vue 2 support.Main.js
```javascript
import Vue from 'vue';
import { VueLd } from 'vue-ld';Vue.use(VueLd, {
clientSideId: 'YOUR_CLIENT_SIDE_ID',
user: {
key: '...',
email: '...',
name: '...',
},
options: {
// Standard LaunchDarkly JavaScript SDK options
},
});
```#### Additional Plugin Options
| key | description | default | type |
| :-------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------------------ |
| `readyBeforeIdentify` | If set to false, the `$ld.ready` will only be true after identify has been called. | `true` | `Boolean` |
| `flagsStub` | If provided, the ldClient will not be initialized and `$ld.flags` will set to the provided stub; this can be helpful in e2e tests. | `undefined` | `Object` / `Proxy` |### Template
```html
// Render after feature flags are ready
```
### Identify
A wrapper around `ldClient.identify` to allow for
```javascript
export default {
methods: {
vueLdCallback() {
// ...
},
},
watch: {
user(to) {
const options = {
newUser: to,
};
this.$ld.identify(options, this.vueLdCallback);
},
},
};
```#### Arguments
| key | description | type |
| :-------------- | ------------------------------------------------------------------------------- | ---------- |
| `options` | The standard `ldclient.identify` arguments. | `object` |
| `vueLdCallback` | A method called after the identify promise resolves; bound to the \$ld context. | `function` |### Redirect Mixin
Adds a temporary redirect watcher that will either redirect or destroy itself after the flags are ready.
```javascript
import { ldRedirectMixin } from 'vue-ld';export default {
// ...
mixins: [ldRedirectMixin('yourFlag', { name: 'home' })],
// ...
};
```#### Arguments
| key | description | type |
| :------------- | ---------------------------------------------------------------------------------------------- | --------------------------------- |
| `requiredFlag` | If the given feature flag is false, the user will be redirected to the given route. | `string` |
| `to` | The path which vue router will push. Functions passed are expected to resolve to a valid path. | `string`, `object`, or `function` |
| `invertFlag` | If set to true the the inverse of the requiredFlag's value will be used. | `boolean` |### LDRouteGuard Component
Use this as an intermediary component on a route you need to guard with a feature flag; it is based on the `ldRedirectMixin`.
```javascript
import { LDRouteGuard } from 'vue-ld';
import SecretComponent from '@/components/Secret';const route = {
path: '/secret',
component: LDRouteGuard,
props: {
component: SecretComponent,
componentProps: { exampleProp: true },
requiredFeatureFlag: 'palantir',
to: { name: 'away' },
},
};
```#### Props
| key | description | type |
| :--------------- | ---------------------------------------------------------------------------------------------- | --------------------------------- |
| `component` | The component to be rendered given the required feature flag is true. | `vue component` |
| `componentProps` | The props object to hand to the component above. | `object` |
| `requiredFlag` | If the given feature flag is false, the user will be redirected to the given route. | `string` |
| `to` | The path which vue router will push. Functions passed are expected to resolve to a valid path. | `string`, `object`, or `function` |
| `invertFlag` | If set to true the the inverse of the requiredFlag's value will be used. | `boolean` |## Development
After cloning the repo to your machine:
```bash
$ npm install
$ npm run watch
```### Local
If you wish to test out your changes in another project locally, you can install with `npm install --save `. Your vue app will detect changes so long as vue-ld is being watched (by running `npm run watch`).