0.4.0 • Published 2 years ago

vue-ld v0.4.0

Weekly downloads
494
License
MIT
Repository
github
Last release
2 years ago

Vue LaunchDarkly

Mentioned in Awesome Vue.js Maintainability Test Coverage npm version Last Commit Licence Stars

A simple wrapper around the 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.

Usage

Installation

$ npm install --save vue-ld launchdarkly-js-client-sdk
  • Requires @vue/composition-api for Vue 2 support.

Main.js

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

keydescriptiondefaulttype
readyBeforeIdentifyIf set to false, the $ld.ready will only be true after identify has been called.trueBoolean
flagsStubIf provided, the ldClient will not be initialized and $ld.flags will set to the provided stub; this can be helpful in e2e tests.undefinedObject / Proxy

Template

<template>
  <div v-if="$ld.ready && $ld.flags.yourFlag">
    // Render after feature flags are ready
  </div>
</template>

Identify

A wrapper around ldClient.identify to allow for

export default {
  methods: {
    vueLdCallback() {
      // ...
    },
  },
  watch: {
    user(to) {
      const options = {
        newUser: to,
      };
      this.$ld.identify(options, this.vueLdCallback);
    },
  },
};

Arguments

keydescriptiontype
optionsThe standard ldclient.identify arguments.object
vueLdCallbackA 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.

import { ldRedirectMixin } from 'vue-ld';

export default {
  // ...
  mixins: [ldRedirectMixin('yourFlag', { name: 'home' })],
  // ...
};

Arguments

keydescriptiontype
requiredFlagIf the given feature flag is false, the user will be redirected to the given route.string
toThe path which vue router will push. Functions passed are expected to resolve to a valid path.string, object, or function
invertFlagIf 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.

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

keydescriptiontype
componentThe component to be rendered given the required feature flag is true.vue component
componentPropsThe props object to hand to the component above.object
requiredFlagIf the given feature flag is false, the user will be redirected to the given route.string
toThe path which vue router will push. Functions passed are expected to resolve to a valid path.string, object, or function
invertFlagIf set to true the the inverse of the requiredFlag's value will be used.boolean

Development

After cloning the repo to your machine:

$ 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_local_path_to_/vue-ld>. Your vue app will detect changes so long as vue-ld is being watched (by running npm run watch).

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago