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-prom

v1.0.4

Published

Vue promise wrapper component

Downloads

3

Readme

vue-prom

Vue promise wrapper component

About

The goal of this component is to simplify rendering logic based on promise state (pending / fulfilled, rejected). The component keeps track of the promise's state and proposes slots to render content accordingly.

You should avoid this component when:

  • You need to store the result of the promise (i.e to send it back later or if it is required for a computed property).
  • You need to make a function call inside of the promise callback (i.e store the result in Vuex or trigger your notification library).

Installation

NPM

npm install --save vue-prom

npm package link

CDN

<script src="https://unpkg.com/vue-prom@latest"></script>

Usage

With vue-prom we would write the following:

<template>
  <div>
      <vue-prom :promise="api.getUser()">
          <div slot="pending">
              Loading user...
          </div>
          <div slot="then" slot-scope="{result}">
              Hello {{ result.firstName }} {{ result.lastName }}
          </div>
          <div slot="catch" slot-scope="{error}">
              {{ error.message }}
          </div>
      </vue-prom>
  </div>
</template>

<script>
import VueProm from 'vue-prom';
import api from './api';
export default {
  data() {
    api
  },
  components: {
      VueProm
  }
};
</script>

Instead of:

<template>
    <div>
        <div v-if="loading">
            Loading user...
        </div>
        <div v-else-if="error">
            {{ error.message }}
        </div>
        <div v-else>
            Hello {{ result.firstName }} {{ result.lastName }}
        </div>
    </div>
</template>

<script>
import api from './api';
export default {
  created() {
    this.loading = true;
    this.error = null;
    api
      .getUser()
      .then(result => (this.user = result))
      .catch(error => (this.error = error))
      .finally(_ => (this.loading = false));
  },
  data() {
    return {
      loading: false,
      user: null
    };
  }
};
</script>

Alternatively, to keep the template concise, we can omit the 'pending' and 'catch' slots altogether and rely on the default labels provided by the component instead.

<template>
  <div>
      <vue-prom :promise="api.getUser()">
          <div slot="then" slot-scope="{result}">
              Hello {{ result.firstName }} {{ result.lastName }}
          </div>
      </vue-prom>
  </div>
</template>

Props

  • promise: required, the promise to resolve.
  • refresh: refresh trigger.

The component watches both the promise and refresh props, the promise will automatically re-execute when the value of either of these changes.

Slots

All slots are optional.

| Name | Visible when | Slot type(s) | If absent | |----------|---------------------------|--------------------|---------------------------| | pending | The promise is pending | Regular only | A span with 'Loading...' | | catch | The promise was rejected | Regular and scoped | A span with 'Error' | | then | The promise was fulfilled | Regular and scoped | A span with 'Loaded' |

Data exposed by scoped slots:

  • Scoped 'catch' slot exposes the 'error' object.
  • Scoped 'then' slot exposes the 'result' object.