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

v0.5.0

Published

Lazily render components in React

Downloads

5

Readme

vue-laze

Lazily render components in Vue 3

NPM JavaScript Style Guide Open in CodeSandbox

Install

npm install --save vue-laze
yarn add vue-laze

Usage

<template>
  <h1 ref="container" :class="{ visible: visible }">
    Item is now visible!
  </h1>
</template>
<script lang="ts">
  import { toRefs } from 'vue';
  import useLaze from 'vue-laze';

  export default {
    name: 'Lazy',
    setup(props) {
      const { ref: container, visible } = useLaze<HTMLDivElement>();

      return {
        container,
        visible,
      };
    }
  }
</script>
<style scoped>
  h1 {
    margin: 1rem;

    text-align: center;

    transition: opacity 200ms, transform 200ms;
    opacity: 0;
    transform: scale(0.5);
  }

  h1.visible {
    opacity: 1;
    transform: scale(1);
  }
</style>

Introduction

vue-laze defers rendering of components until they are visible in the viewport. This helps our pages to prioritize rendering the components that are critical (and already are visible) than those that are offscreen and has no impact towards the user until visible. The behavior is similar to that of idle-until-urgent pattern but the "idleness" is determined by the user's demand.

vue-laze is useful for on-screen transitions, lazy-loading media sources, client-only components, etc..

SSR

There are different strategies vue-laze may help in server-side rendering.

For instance, you can lazify images such that the "src" property is pre-rendered through "data-src" then reverted back after the image becomes visible.

You can also force a certain element into a client-side-only render given that useLaze's visible property only becomes true on a client-side context and never on server-side.

API

useLaze<HTMLElement>(): { ref, visible }

a Vue 3 Composition function that observes an element and provides a visibility state.

ref: Ref<HTMLElement>

A Vue ref object that captures the element to observe with. The ref isn't a plain Vue ref object but rather has "reactive" current property: when assigned, ref prompts a re-render for the component that owns it. This allows useLaze to re-evaluate everytime the observed element is attempted to be changed during the component's lifecycle (Example of this scenario includes force-remounting an element).

visible: boolean

A boolean value that represents the state of which the element is "visible" or not in the viewport. This value only updates once after the element becomes visible, and only resets back to false if the observed element changes (assuming that the mounting element is offscreen).

License

MIT © lxsmnsyc