Skip to content

Vue LaunchDarkly plugin and routing utilities

License

Notifications You must be signed in to change notification settings

dashhudson/vue-ld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ec0a7eb · Sep 4, 2020

History

9 Commits
Sep 4, 2020
Sep 4, 2020
Sep 4, 2020
Aug 7, 2020
Aug 20, 2020
Aug 20, 2020
Aug 20, 2020
Sep 2, 2020
Aug 20, 2020
Aug 7, 2020
Sep 2, 2020
Aug 19, 2020
Aug 19, 2020
Aug 20, 2020
Sep 4, 2020
Aug 20, 2020

Repository files navigation

Vue LaunchDarkly

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 other utilities.

Usage

Installation

$ npm install --save vue-ld

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

key description default type
readyBeforeIdentify If set to false, the $ld.ready will only be true after identify has been called. true Boolean

Template

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

Identify

A wrapper around ldClient.identify to allow for

const options = {
  newUser: to,
};
const vueLdCallback = () => {
  // ...
};

export default {
  watch: {
    user(to) {
      this.$ld.identify(options, 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.

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. Boolean
to The path or object which vue router will push. string or object