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-debounce-provider

v1.0.15

Published

A template-based debounce component using the provider pattern.

Downloads

23

Readme

npm version main Codacy Badge codecov Bundlephobia License

Vue Debounce Provider

A template-based debounce component that uses scoped slots to allow any method to be debounced or throttled without altering its code. It provides a interface similar to Lodash Debounce so debounces can be cancelled or flushed as well as a scoped status variable that makes toggling inputs a breeze.

Features

  • Tiny bundle size with no dependencies
  • Template-based debouncing using a scoped slot
  • Props and interface similar to Lodash Debounce
  • Throttling with optional max-wait prop
  • Support for leading and tailing evoking of @timeout event
  • Cancelable and flushable
  • Debouncing status variable to easily toggle inputs
  • Nuxt plugin built-in

Installation

Install with npm

npm install vue-debounce-provider

Install with Yarn

yarn install vue-debounce-provider

Usage

Add the Vue plugin in your main.js

import Vue from 'vue'
import VueDebounceProvider from 'vue-debounce-provider'

Vue.use(VueDebounceProvider)

In your template wrap your event emitter in the <debounce> component

<template>
  <debounce
    v-slot="{ debounce }"
    :wait="300"
    @timeout="rangeChanged"
  >
    <input type="range" @input="debounce" />
  </debounce>
</template>

<script>
export default {
  methods: {
    rangeChanged(e) {
      // perform some slow operation here
    }
  }
}
</script>

All you have to do is move your handler to the @timeout event and put the debounce function the scoped slot provides in its place.

Any event arguments received by the scoped debounce function are passed to @timeout when it is called.

Nuxt

Add the Nuxt plugin in your nuxt.config.js

export default {
  modules: [
    'vue-debounce-provider/nuxt'
  ]
}

Styling

By default, the <debounce> component behaves like a <div> meaning it displays as a block and will contribute to layout. However, this can be easily adjusted with classes and styles.

<debounce class="d-inline-block">
  ...
</debounce>

API

Props

wait

Type: Number Default: 0

Number of milliseconds to wait between debounce being called and invoking the @timeout method.

max-wait

Type: Number Default: null

Number of milliseconds to wait, regardless of the debounce, before calling @timeout method. This effectively acts as a throttle.

leading

Type: Boolean Default: false

Invokes the @timeout method the first time debounce is called with no delay.

trailing

Type: Boolean Default: true

Invokes the @timeout method after the last debounce is called and :wait has elapsed.

Events

start

Invoked once at leading edge of a debounce cycle. Will only be evoked again once the current debounce cycle has fully completed.

timeout

Invoked at the trailing edge of the debounce cycle if :trailing="true" (default).

Invoked at the leading edge of the debounce cycle if :leading="true".

Invoked at the leading and trailing edge if both are true.

cancel

Invoked when the cancel scoped function is called.

@timeout will not be invoked when a debounce is cancelled.

flush

Invoked when the flush scoped function is called.

@timeout will also be invoked if :trailing="true".

Scoped Slot

Several optional scoped functions and variables are yielded inside the scoped slot.

debounce scoped

Type: Function

Calling will start a new debounce cycle is one is not already started and will reset the timer on an existing cycle.

All arguments passed to this function will be forwarded to method on the @timeout handler. This means your handler will have access to $event.

cancel scoped

Type: Function

Calling this will immediately stop the current debounce cycle without evoking the @timeout handler.

The @cancel handler will be evoked.

flush scoped

Type: Function

Calling this will immediately stop the current debounce cycle but will evoke @timeout if :trailing="true".

The @flush handler will also be evoked.

debouncing scoped

Type: Boolean

Indicates whether a debounce cycle is currently running. This is very useful for toggling loading spinners or disabling buttons while the debounce cycle is active.

wait scoped

Type: Number

The number of milliseconds set in the :wait prop. Useful for being able to display the number even with hard coded props.

max-wait scoped

Type: Number

The number of milliseconds set in the :max-wait prop.