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

yann-usedefer

v1.3.2

Published

## 介绍

Downloads

360

Readme

yann-usedefer

介绍

useDefer

maxCount默认值为100

declare function useDefer(maxCount?: number): {
  defer: (count: number) => boolean
  updateMaxCount: (newMaxCount: number) => void
  index: Readonly<Ref<number>>
}
import { useDefer } from 'yann-usedefer';

const list = ref(100)
const { defer, updateMaxCount } = useDefer(list.value);


setTimeout(() => {
  // 3s后更新
  list.value = 200
  updateMaxCount(list.value);
},3000)

<template>
  <div class="main">
    <div class="box" v-for="n in list" :key="n">
      <div class="item" v-if="defer(n)"></div>
    </div>
  </div>
</template>

useDeferWatch

useDeferWatch函数接受一个Ref或者一个number类型的值,如果传入的值是一个Ref,那么useDeferWatch会监听这个Ref的变化,如果传入的是一个number类型的值,那么useDeferWatch会直接使用这个值。

declare function useDeferWatch(maxCount: Ref<number> | number): {
  defer: (count: number) => boolean
  index: Readonly<Ref<number>>
}
import { useDeferWatch } from 'yann-usedefer';

const list = ref(100)
const val = computed(() => {
  return list.value
})

const { defer } = useDeferWatch(val);


setTimeout(() => {
  list.value = 200
},3000)

<template>
  <div class="main">
    <div class="box" v-for="n in list" :key="n">
      <div class="item" v-if="defer(n)"></div>
    </div>
  </div>
</template>

useDeferData

useDeferData 函数接受一个数组或者对象或者Ref的数组或者对象,返回一个计算属性的数组或者对象

type ListData<T> = Array<T>

interface MapData<T> {
  [k: string | symbol]: T
}

type DataType<T> = ListData<T> | Ref<ListData<T>> | MapData<T> | Ref<MapData<T>>

export declare function useDeferData<T>(data: DataType<T>): ComputedRef<ListData<T> | MapData<T>>
import { useDeferData } from 'yann-usedefer';

const list = ref([1,2,3])
const data = useDeferData(list)


<template>
  <div class="main">
    <div class="box" v-for="n in data" :key="n">
      <div class="item"></div>
    </div>
  </div>
</template>