1.1.0 • Published 3 years ago

@ifake/easy-polling v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

欢迎使用 @ifake/easy-polling 👋

Version Npm Bundle Size License: MIT

针对视频多屏播放需求: 轮巡策略,包括单路依次轮巡和多路同时轮巡..

本项目的脚手架来自 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模式生效 每次替换几个视频
}

方法

方法类型描述返回值
startFunction开始轮巡-
stopFunction结束轮巡g-
observeFunction订阅轮巡数据data[]
updateIntervalTimeFunction更新轮巡周期-

注意事项

请在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