npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ld-vue

v0.1.1

Published

A library to integrate Launch Darkly with Vue

Downloads

84

Readme

ld-vue

npm version npm downloads npm npm

Integrate Launch darkly with Vue in seconds :tada:

Why this package?

  • Easy and fast to use. Two steps to get Launch Darkly feature flags into your Vue app.
  • Supports subscription out of the box. You get live changes on the client as you toggle features.
  • You automatically get camelCased keys as opposed to the default kebab-cased.

Installation

yarn add ld-vue

Quickstart

  1. Use the withFlagProvider mixin in your root App:

    App.vue
    <script>
    import { withFlagProvider } from 'ld-vue'
       
    export default {
      mixins: [withFlagProvider({ clientSideId: 'your-client-side-id' })],
    }
    </script>
  2. Use the withFlags mixin in your Vue component to get them via props:

    <template>
      <div>
        <!-- this.flags is injected by withFlags -->
        {{this.flags.devTestFlag ? 'Flag on' : 'Flag off'}}
      </div>
    </template>
    <script>
    import { withFlags } from 'ld-vue'
       
    export default {
      mixins: [withFlags],
    }
    </script>

That's it!

API

withFlagProvider({clientSideId, user, options})

This is a function which accepts a config object with the above properties. Only clientSideId is mandatory. Returns a mixin which a Vue instance can use like a normal mixin. Use this mixin in your root App.vue instance to initialise ld-vue.

Example usage with class components:

App.vue
<script>
import Component, { mixins } from 'vue-class-component'
import { withFlagProvider } from 'ld-vue'

@Component
export default class App extends mixins(withFlagProvider({clientSideId: 'your-client-side-id'})) {}
</script>

The user property is optional. You can initialise the sdk with a custom user by specifying one. This must be an object containing at least a "key" property. If you don't specify a user object, ld-vue will create a default one that looks like this:

const defaultUser = {
  key: uuid.v4(), // random guid
  ip: ip.address(),
  custom: {
    browser: userAgentParser.getResult().browser.name,
    device
  }
};

For more info on the user object, see here.

The options property is optional. It can be used to pass in extra options such as Bootstrapping.

For example:

withFlagProvider({
    clientSideId,
    options: {
      bootstrap: 'localStorage',
    },
});

withFlags

This is a mixin which injects all your flags to the specified component via props. Your flags will be available as camelCased properties under this.flags. For example with class components:

<template>
  <div>
    <!-- Look ma feature flags! -->
    {{this.flags.devTestFlag ? 'Flag on' : 'Flag off'}}
  </div>
</template>
<script>
import Component, { mixins } from 'vue-class-component'
import { withFlags } from 'ld-vue'

@Component
export default class Home extends mixins(withFlags) {}
</script>

ldClient

Internally ld-vue initialises the ldclient-js sdk and stores a reference to the resultant ldClient object in memory. You can use this object to access the official sdk methods directly. For example, you can do things like:

<script>
import Vue from 'vue'
import Component from 'vue-class-component'
import {ldClient} from 'ld-vue';

@Component
export default class Home extends Vue {
  mounted() {
    ldClient.track('home page loaded');
  }
}
</script>

Example

Check the example for a standard vue cli app with feature flags. Remember to enter your client side sdk in the root app file and create a test flag called dev-test-flag before running the example!