@ifake/easy-polling
v1.1.0
Published
![Version](https://img.shields.io/npm/v/@ifake/easy-polling) ![Npm Bundle Size](https://img.shields.io/bundlephobia/min/@ifake/easy-polling) ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
Downloads
6
Readme
欢迎使用 @ifake/easy-polling 👋
针对视频多屏播放需求: 轮巡策略,包括单路依次轮巡和多路同时轮巡..
本项目的脚手架来自 pkg
🏠 Homepage
安装
npm install @ifake/easy-polling
# or
yarn add @ifake/easy-polling
使用
- 浏览器端
// 我们提供了一个全局变量 `EasyPolling` 以便使用CDN时直接在浏览器端使用.
const EasyPolling = window.EasyPolling
- ES6 Module
import { EasyPolling } from "@ifake/easy-polling"
DEMO
import { EasyPolling } from "@ifake/easy-polling"
const instance = new EasyPolling({
source: [param1, param2, param3...],
intervalTime: 2000
type: 'single' || 'double'
returnCount: 2
})
instance.observe((data) => {
})
instance.start()
// stop
instance.stop()
// update intervalTime
instance.updateIntervalTime(5000)
本地运行
git clone https://github.com/ifakejs/easy-polling.git
cd easy-polling
yarn
yarn start
// 新打开命令行
yarn start:demo
API
EasyPolling [Class]
- 参数
type RunType = "single" | "double"
interface EasyPollingOptions {
type: RunType // polling type
source: any[] // Data source
intervalTime: number // ms
returnCount: number // 返回的数据(每次展示几屏)个数
replaceCount: number // 仅在single模式生效 每次替换几个视频
}
方法
方法 | 类型 | 描述 | 返回值 ----- | ----- | ----- | ----- start | Function | 开始轮巡 | - stop | Function | 结束轮巡g | - observe | Function | 订阅轮巡数据 | data[] updateIntervalTime | Function | 更新轮巡周期 | -
注意事项
请在observe
之后调用start
方法,因为在调用轮巡策略时内部我们有初始数据的逻辑
否则,将丢失初始回调数据。
e.g
# 正确用法
instance.observe(() => {})
instance.start()
作者
👤 BiYuqi
🤝 贡献
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
📝 License
This project is MIT licensed.
This README was generated with ❤️ by readme-md-generator