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

buefy-loading-tracker

v1.4.0

Published

Vue mixin for tracking loading states of multiple named components

Downloads

53

Readme

Buefy-Loading-Tracker

A simple Vue mixin for tracking the loading states of multiple Bulma or Buefy components or elements.

Prerequisites

  • Vue 2.7 or Vue 3.

Features

  • Easily track loading states of multiple components or elements within the Bulma or Buefy UI framework.
  • Supports both the Options API and the Composition API.

Installation

npm install --save buefy-loading-tracker

Example Usage (Composition API)

<template>
    <div>
        <button class="is-button"
                :class="
                /* Reactively returns 'is-loading' depending on the loading state  */
                loading.class('createPostForm')"
                @click="createPost()">
            Start Loading
        </button>
    </div>
</template>
<script setup lang="ts">
import { useLoadingTracker } from 'buefy-loading-tracker';
import { someAsyncFunction } from './somewhere-in-your-app';

const loading = useLoadingTracker();

async function createPost() {
    loading.start('create-post-form');
    await someAsyncFunction().finally(() => loading.stop('create-post-form'));
}
</script>

Available methods (Composition API)

loading.class(name: string)

<template>
    <button class="is-button" :class="loading.class('myButton')">
        My Button
    </button>
</template>

Returns a reactive CSS class that can be applied to a component or element. The class will be 'is-loading' when the loading state is active, and an empty string when the loading state is inactive.

loading.start(name: string)

<template>
    <button class="button" @click="loading.start('myButton')">
        Start Loading
    </button>
</template>

Starts the loading state for my-button. The loading state will be active until loading.stop(name) is called.

loading.stop(name: string)

<template>
    <button class="button" @click="loading.stop('myButton')">
        Stop Loading
    </button>
</template>

Stops the loading state for myButton. The loading state will be inactive until loading.start(name) is called.

loading.is(name: string)

<template>
    <h1 class="title" v-if="loading.isLoading('myButton')">
        Loading...
    </h1>
    <h1 v-else>
        Click the button to start loading.
    </h1>
</template>

Returns a reactive boolean indicating whether the loading state for myButton is active or not.

Usage (Options API)

Add the loading tracker to the component you want to control:

<template>
    <div>
        <!-- Default loading state -->
        <button class="is-button" :class="loadingClass()"></button>
        
        <!-- Named loading state -->
       <button class="is-button" :class="loadingClass('named-loader')"></button>
    </div>
</template>

Import the loading tracker as a mixin:

<script>
    import LoadingTracker from 'buefy-loading-tracker';
    
    export default {
        mixins: [LoadingTracker],
    }
</script>

Starting and stopping the default loader:

// Start loading
this.startLoading();

// Stop loading
this.stopLoading();

// Check loading
this.isLoading();

Starting and stopping named loaders:

// Start loading
this.startLoading('named-loader');

// Stop loading
this.stopLoading('named-loader');

// Check loading
this.isLoading('named-loader');

(Optional) If you need to use some Vuex controlled loading state, define it using a loadingState computed property.

<template>
    <!-- Loading state from Vuex store -->
   <button class="is-button" :class="loadingClass('someLoadingState')"></button>
</template>
<script>
import LoadingTracker from 'buefy-loading-tracker';
import { mapState } from 'vuex';

export default {
    mixins: [LoadingTracker],
    computed: {
        loadingState() {
            return {
                ...mapState(['someLoadingState'])
            }
        }
    }
}
</script>

License

MIT - View License