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

v0.2.7

Published

Optimized and easy way to manage events across Vue.js components.

Downloads

83

Readme

vue-aware

Optimized and easy way to manage events across Vue.js components.

stability-wip NPM version CircleCI Coverage Status Commitizen friendly Conventional Commits License

Description

vue-aware allows your components to easily listen to "common global" events such as:

  • scroll
  • viewport resize
  • appear on viewport
  • request animation frame

Another kind of bus event?

What makes vue-aware special is how it manages events for you. vue-aware will create as LESS listeners as possible and ONLY when some components need it! Which is good performance wise…


Installation

npm install --save vue-aware

Import

import Vue from 'vue';
import VueAware from 'vue-aware';

Vue.use(VueAware);

Browser

<script src="vue.js"></script>
<script src="https://unpkg.com/thierrymichel/vue-aware"></script>

vue-aware should be auto-installed. If not, use Vue.use(VueAware).

Usage

General

  1. Simply add the v-aware directive to your element(s).
  2. Define a handler for an event (appear, raf, scroll, viewport):
  • @[event]="handler" or
  • v-on:[event]="handler" or
  • v-aware="{ [event]: { callback: handler } }"

🚨Components (vs elements) only accept callback property with v-aware directive (@ or v-on won't work)

Note: callback property has precedence over @ or v-on directive…

Example (scroll)

<div v-aware @scroll="scrollHandler"></div>
<div v-aware v-on:scroll="scrollHandler"></div>
<div v-aware="{ scroll: { callback: scrollHandler }}"></div>

Appear

appear uses the IntersectionObserver API. If it is incompatible with your browser support, you can polyfill it.

appear will let you know if your element is:

  • partially in viewport
  • fully in viewport
  • positionned on top, bottom or center of the viewport

Like IntersectionObserver, it accepts options:

  • root (HTMLElement, default is browser viewport)
  • rootMargin (CSS margin prop, with % or px, default is 0px 0px 0px 0px)
  • threshold (related to target's visibility, number or number[], default is [0, 1])

and an extra one:

  • once (your callback is only trigger once, default false)

Example

<!-- no options -->
<div v-aware @appear="appearHandler"></div>
<!-- full options -->
<div
  v-aware="{
  appear: {
    root: document.querySelector('.foo'),
    rootMargin: '-25% 0px',
    threshold:  [0, 0.25, 0.5, 0.75, 1],
    once: true,
  }}"
  @appear="appearHandler"
></div>
export default {
  methods: {
    appearHandler(isInViewport, isFullyInViewport, position, context) {},
  },
};

Raf (requestAnimationFrame)

Use requestAnimationFrame to trigger your handler. There is no options.

Example

<div v-aware @raf="rafHandler"></div>
export default {
  methods: {
    rafHandler(delta, now, context) {},
  },
};

Scroll

Gives you the scroll position (x and y). You can throttle or debounce it (read more).

Example

<!-- no options -->
<div v-aware @scroll="scrollHandler"></div>
<!-- full options -->
<div
  v-aware="{
  scroll: {
    throttle: 250,
    debounce: 50,
  }}"
  @scroll="scrollHandler"
></div>
export default {
  methods: {
    scrollHandler(scrollX, scrollY, context) {},
  },
};

Viewport

When a window resize is detected. It gives you the width and height of the viewport + ratio (width/height). You can throttle or debounce it (read more). By default, it is throttled (150ms).

Example

<!-- no options -->
<div v-aware @viewport="viewportHandler"></div>
<!-- full options -->
<div
  v-aware="{
  viewport: {
    throttle: 250,
    debounce: 50,
  }}"
  @viewport="viewportHandler"
></div>
export default {
  methods: {
    viewportHandler(width, height, ratio, context) {},
  },
};

How to contribute

If you want to report a bug or if you just want to request for a new feature/improvement, please follow those instructions before.

Thanks for taking time to contribute to vue-aware :tada: :+1: