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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@panosen/raf

v0.0.2

Published

panosen requestAnimationFrame

Readme

panosen-raf

@panosen/raf 是一个对 requestAnimationFrame 的轻量封装,支持延迟多帧执行回调,并提供取消功能。

参考自 https://github.com/react-component/util/blob/master/src/raf.ts

安装

npm install @panosen/raf
# 或
pnpm add @panosen/raf

使用示例

基本用法

在下一帧执行回调:

import wrapperRaf from '@panosen/raf';

const id = wrapperRaf(() => {
    console.log('在下一帧执行');
});

延迟多帧执行

等待指定帧数后再执行回调(默认 1 帧):

import wrapperRaf from '@panosen/raf';

// 等待 3 帧后执行
const id = wrapperRaf(() => {
    console.log('3 帧后执行');
}, 3);

取消执行

在回调触发前取消:

import wrapperRaf from '@panosen/raf';

const id = wrapperRaf(() => {
    console.log('这条消息不会被打印');
}, 5);

// 取消尚未执行的回调
wrapperRaf.cancel(id);

在 React 组件中使用

import React, { useEffect } from 'react';
import wrapperRaf from '@panosen/raf';

const MyComponent: React.FC = () => {
    useEffect(() => {
        const id = wrapperRaf(() => {
            // 在组件挂载后的下一帧执行 DOM 操作
            console.log('DOM 已更新,执行后续逻辑');
        });

        return () => {
            // 组件卸载时取消未执行的回调
            wrapperRaf.cancel(id);
        };
    }, []);

    return <div>示例组件</div>;
};

export default MyComponent;

API

wrapperRaf(callback, times?)

| 参数 | 类型 | 默认值 | 说明 | | ---------- | ------------ | ------ | ---------------------------- | | callback | () => void | - | 延迟执行的回调函数 | | times | number | 1 | 延迟的帧数,至少等待该帧数后执行 |

返回值:number —— 任务 ID,可用于取消。

wrapperRaf.cancel(id)

| 参数 | 类型 | 说明 | | ---- | -------- | --------------------------------- | | id | number | 由 wrapperRaf 返回的任务 ID |

取消尚未执行的回调。若回调已执行,则无任何效果。

发布

pnpm i

pnpm run build

npm publish --dry-run

npm publish