0.1.1 • Published 5 years ago

ss-auto-queue v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

ss-auto-queue

Build Status Coverage Status MIT Licence npm version

Typescript Version of ss-auto-queue

该工具是为了解决入栈之后,自动隔一段时间出栈的需求:比如当用户第一次操作后,在其 20s 后需要进行自动保存操作;即我们只需要调用入栈(enqueue)的操作即可,出栈的时间不同我们关心;

实现原理比较简单,使用队列 + throttle 功能就搞定了;

Installation

Node.js / Browserify

npm install ss-auto-queue --save
const AutoQueue = require('ss-auto-queue');

// 创建自动保存队列
const autoSaveQueue = new AutoQueue((config) => {
    const { type, value } = config!;
    if (type === QUEUE_OPERATION.EN) {
        // 当入队
    }
    // 出队的时候,执行任务
    if (type === QUEUE_OPERATION.DE) {
        // 当出队
    }
}, 100);

// 做了某操作之后,需要自动保存
autoSaveQueue.enqueue({from: 'user', action: 'click btn'})

Global object

Include the pre-built script.

<script src="./dist/index.umd.min.js"></script>

<script>
const AutoQueue = window.autoQueue;

// 创建自动保存队列
const autoSaveQueue = new AutoQueue((config) => {
    const { type, value } = config!;
    if (type === QUEUE_OPERATION.EN) {
        // 当入队
    }
    // 出队的时候,执行任务
    if (type === QUEUE_OPERATION.DE) {
        // 当出队
    }
}, 100);

// 做了某操作之后,需要自动保存
autoSaveQueue.enqueue({from: 'user', action: 'click btn'})

</script>

Build & test

npm run build
npm test

License

MIT.