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

vue-darkly

v1.0.2

Published

![GitHub top language](https://img.shields.io/github/languages/top/EvanBurbidge/vue-darkly) ![npm](https://img.shields.io/npm/dt/vue-darkly) ![version](https://img.shields.io/npm/v/vue-darkly) ![NPM](https://img.shields.io/npm/l/vue-darkly)

Downloads

57

Readme

vue-darkly

GitHub top language npm version NPM

This project will give you access to launch darkly apis in your vuejs application

Project setup

to install the launchdarkly vue client run the following npm command

  yarn add vue-darkly
  // or
  yarn add vue-darkly

Usage Api

Setup

import Vue from 'vue';
import App from './App.vue';
import VueDarkly from 'vue-darkly';

Vue.use(VueDarkly, {
  ldKey: process.env.VUE_APP_LD_KEY,
  user: {
    anonymous: true,
  },
});

Vue.config.productionTip = false;

new Vue({
  render: h => h(App),
  mounted() {
    setTimeout(() => {
      this.$ldIdentify({
        firstName: 'Bob',
        lastName: 'Loblaw',
        key: 'aa0ceb',
      });
    }, 2000);
  },
}).$mount('#app');

<template>
  <div id="app">
    <pre>
      {{ flagsComputed }}
    </pre>
    <div v-if="flagsComputed['some-flag-name']">
      its on
    </div>
    <div v-else>
      its not on
    </div>
  </div>
</template>

<script>
export default {
  created() {
    this.$ld.on('ready', () => this.setFlags());
    this.$ld.on('change', () => this.setFlags());
  },
  data: () => ({
    flags: {},
  }),
  methods: {
    setFlags() {
      this.flags = this.$ldFlags();
    },
  },
  computed: {
    flagsComputed() {
      return this.flags;
    },
  },
};
</script>

$ld

  • gives you access to the launch darkly client
  this.$ld.allFlags()// returns all flags

$ldFlush

Internally, the LaunchDarkly SDK keeps an analytics event buffer. These events are flushed periodically (asynchronously). In some situations, you may want to manually call flush to process events immediately.

Note that this method is asynchronous. You may pass a callback or wait for the returned Promise to determine when all events have been flushed.

this.$ldFlush()

$ldFlags

The $ldFlags method will return a key / value map of all your feature flags.

The map will contain null values for any flags that would return the fallback value (the second argument that you normally pass to variation).

this.$ldFlags()

$ldVariation

The ldVariation method determines which variation of a feature flag a user receives. $ldVariation calls take the feature flag key and a default value. The default value will only be returned if an error is encountered—for example, if the feature flag key doesn't exist or the user doesn't have a key specified.

this.$ldVariation('my-key', true)

$ldIdentify

You may wish to change the user context dynamically and receive the new set of feature flags for that user or generate events for the new user. For example, on a sign-in page in a single-page app, you might initialize the client with an anonymous user. When the user logs in, you'd want the feature flag settings for the authenticated user. To do this, you can call the identify function:

this.$ldIdentify(newUser, hash, () => {
   console.log("New user's flags available");
 });

The hash parameter is the hash for the new user, assuming that the user's key has changed. It is only required in secure mode-- if secure mode is not enabled, you can pass in null for the hash.

If you provide a callback function, it will be called (with a map of flag keys and values) once the flag values for the new user are available; after that point, variation() will be using the new values. You can also use a Promise for the same purpose.

Note that the SDK always has one current user. The client-side SDKs are not designed for evaluating flags for different users at the same time.

var user = {
  "key": "aa0ceb",
  "firstName": "hello",
  "lastName": "there",
  "email": "[email protected]",
  "custom": {
    "groups": ["Google", "Microsoft"]
  }
};

Events

ready

this.$ld.on('ready', () => {
  // its ready do some feature flagging
})

change

this.$ld.on('change', (values) => {
  console.log(values);
  // values is an object of values e.g. 
  // { key: { current, previous }}
})

change:specific-key

this.$ld.on('change:specific-key', (value, previous) => {
  // update the ui
})