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

anti-shake-and-per

v0.1.4

Published

防抖与权限控制

Downloads

3

Readme

anti-shake-and-per

防抖与权限控制

创建日期:2020-10-23

防抖使用方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>dome1</title>
    <script src="anti-shake-and-per.js"></script>
</head>
<body>

<button onclick="clickc()">按钮</button>

<script>

    var {AntiShakeAndPer, AntiShakeAndPerConfig} = AntiShakeAndPer

    var antiShakeAndPer = new AntiShakeAndPer(new AntiShakeAndPerConfig(
        function () { /** 设置事件开始事件 */
            console.log('请求中')
        },
        function () { /** 设置事件结束事件 */
            console.log('结束')
        },
        function (type) { /** 设置事件异常事件,传入事件类型,1:上一个事件还未结束,2:没有权限 */
            console.log(type)
            if (type === 1) {
                console.log('请勿重复请求')
            }
            if (type === 2) {
                console.log('没有权限')
            }
        },
        10000 /** 设置10秒后不执行结束操作将自动结束,次此控制台会出现警告 */
    ))

    var clickc = function () {
        antiShakeAndPer.run(function (done) {
            console.log('a')
            setTimeout(() => { /** 模拟异步请求,得到响应后调用结束操作 */
                done()
            }, 3000)
        })
    }
</script>
</body>
</html>

权限控制使用方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>dome2</title>
    <script src="anti-shake-and-per.js"></script>
</head>
<body>

<button onclick="setUserData()">设置用户信息</button>
<button onclick="openSystem()">启动</button>
<button onclick="closeSystem()">关闭</button>

<script>

    var {AntiShakeAndPer, AntiShakeAndPerConfig} = AntiShakeAndPer

    var antiShakeAndPer = new AntiShakeAndPer(new AntiShakeAndPerConfig(
        function () {
            console.log('请求中')
        },
        function () {
            console.log('结束')
        },
        function (type) {
            if (type === 1) {
                console.log('请勿重复请求')
            }
            if (type === 2) {
                console.log('没有权限')
            }
        },
        10000
    ), ['OPEN_SYSTEM', 'CLOSE_SYSYTEM']) /** 创建对象时,将当前用户的角色权限传入 */

    var setUserData = function () {
        antiShakeAndPer.run(function (done) {
            console.log('SET_USER_DATA')
            setTimeout(function () {
                done()
            }, 3000)
        }, 'SET_USER_DATA') 
        /** 执行操作时传入该事件的权限标识符,当这个权限标识符存在与这个用户的角色权限列表时才会执行这个事件,否在执行错误事件并传入参数2 */
    }

    var openSystem = function () {
        antiShakeAndPer.run(function (done) {
            console.log('OPEN_SYSTEM')
            setTimeout(function () {
                done()
            }, 3000)
        }, 'OPEN_SYSTEM')
    }

    var closeSystem = function () {
        antiShakeAndPer.run(function (done) {
            console.log('CLOSE_SYSYTEM')
            setTimeout(function () {
                done()
            }, 3000)
        }, ['SET_USER_DATA', 'DELETE_USER_DATA']) /** 当一个事件存在多个权限时,可传入多个权限标识符,其中一个符合就会执行事件 */
    }
</script>
</body>
</html>

<<<<<<< HEAD 完

2020-10-28:修复执行事件时,不传权限标识符报没权限问题 2020-10-28:新增没有调用结束事件时,响应错误事件,传入参数3

2020-12-28:兼容ie11