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

v-status

v0.1.1

Published

A lib to control status of promises in Vue components

Downloads

37

Readme

v-status - Manage the loading of promises in Vuejs

A lib to control status of promises in Vuejs components

Features

  • Simple to use.
  • Allows you to listen to one or more promises.
  • Controls the status of more than one asynchronous resource in the same component.
  • Performable and consumes no memory if never called on the component.
  • Easy implementation to watch state changes.

Installation

Add v-status in your project using npm:

npm install v-status

or using yarn:

yarn add v-status

Usage

Importing

Globally

import Vue from 'vue'
import VStatus from 'v-status'

Vue.use(VStatus)

Local as Mixin

import { VStatus } from 'v-status'

// your component
export default {
  mixins: [VStatus()],
. . .

Using in your Components

<template>

  <!-- Loading State -->
  <div v-if="$status.myFeature.isLoading">Loading</div>

  <!-- Success State -->
  <div
    v-else-if="$status.myFeature.isSuccess"
  >Success!</div>

  <!-- Error State -->
  <div
    v-else-if="$status.myFeature.isError"
  >
    Oh no! An error has occurred.
    <div>Message: {{ $status.myFeature.error.message }}</div>
  </div>

</template>

<script>
export default {
  created() {
    this.$status.myFeature = async () => {
      . . . // some async logic
    }
  }
}
</script>

Reactive Properties

When using 'this.$status.myFeature', an object with the following properties will be automatically generated:

| Property | Type | Default | Description | |---------------|----------|-----------|------------------------------------------------------------------------------------| | isSuccess | bool | false | It is true when promise received has been resolved. | | isError | bool | false | It is true when promise received has not been resolved. | | isLoading | bool | false | It is true when promise received is waiting for some result. | | error.message | string | undefined | Catch error message when promise has not been resolved. | | erros | array | array | Returns a list of errors when one or more promises received has not been resolved. | | clear | function | function | Resets the state to the default when called. |

Passing Promises

When dispatch a promise, set it where you want to use:

this.$status.anotherFeature = this.$axios.get('/users') // async call example 

The setter accepts the following types: | Accepted Types | Description | |-------------------|--------------------------------------------------------------------------------------------| | Promise | Accept a Promise as value. | | function: Promise | Call the function automatically and receive a promise to return. No arguments is provided. | | array[Promise] | It runs automatically in Promise.all. Awaits all promises to return result. |

Returns the same Promise provided.

Advanced Configuration

You can customize the default name "$status" to whatever you want:

. . .
Vue.use(Vstatus, { name: 'customName' }) // global
. . .
// or (local in component)
export default {
  mixins: [VStatus({ name: 'customName' }],
. . .
// using example
this.customName.aCoolFeature.isLoading
. . .