All Projects → o2team → timer-miniprogram

o2team / timer-miniprogram

Licence: MIT license
小程序定时器管理库,更合理地使用 setTimeout 和 setInterval,在页面显示时重启定时器,页面隐藏时暂停定时器,页面卸载时清除定时器

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to timer-miniprogram

driftless
Driftless setInterval and setTimeout replacement for Node and the browser
Stars: ✭ 67 (+157.69%)
Mutual labels:  settimeout, setinterval
chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-42.31%)
Mutual labels:  settimeout, setinterval
timer
Timing Events tied to @gamestdio/clock
Stars: ✭ 20 (-23.08%)
Mutual labels:  settimeout, setinterval
audio-context-timers
A replacement for setInterval() and setTimeout() which works in unfocused windows.
Stars: ✭ 12 (-53.85%)
Mutual labels:  settimeout, setinterval
openapplus
专为小程序共享而生的小程序容器
Stars: ✭ 51 (+96.15%)
Mutual labels:  miniprogram
jgb
小程序渐进式编译框架
Stars: ✭ 21 (-19.23%)
Mutual labels:  miniprogram
mpvue-wechat-zhihu
一个入门级别的资讯类微信小程序
Stars: ✭ 25 (-3.85%)
Mutual labels:  miniprogram
wechat-1password
🔐微信小程序 云开发 『有本密码』,大师级UI、指纹验证存储密码。
Stars: ✭ 82 (+215.38%)
Mutual labels:  miniprogram
SXAU-guide
微信小程序校园导航地图——小标识
Stars: ✭ 12 (-53.85%)
Mutual labels:  miniprogram
91 Python Mini Projects
No description or website provided.
Stars: ✭ 212 (+715.38%)
Mutual labels:  miniprogram
mpapi
🐤 小程序API兼容插件,一次编写,多端运行。支持:微信小程序、支付宝小程序、百度智能小程序、字节跳动小程序
Stars: ✭ 40 (+53.85%)
Mutual labels:  miniprogram
PopRun
跑鸭:这是我的毕业设计,“跑鸭”微信小程序-一款基于校园跑步的社交小程序(实时里程配速、运动路径、整公里提醒、周榜月榜、打卡分享、热门推荐、线上活动、勋章墙、隐私设置),技术栈:Vant-Weapp UI、Laravel+MySQL
Stars: ✭ 64 (+146.15%)
Mutual labels:  miniprogram
ByteDanceOpen
Bytedance(TikTok, Toutiao)third party open platform backend SDK, provides easy-to-use authorization, template management, code package management and other APIs.字节跳动(抖音, 头条)第三方开放平台小程序sdk, 提供了简单易用的授权,模版管理,代码包管理等api.
Stars: ✭ 67 (+157.69%)
Mutual labels:  miniprogram
nginx-docker-miniprogram
给微信小程序业务域名做反向代理的Nginx Docker配置
Stars: ✭ 33 (+26.92%)
Mutual labels:  miniprogram
uniapp-scaffold
基于Vue.js的跨平台小程序脚手架、设计语言、组件库及插拔式模板
Stars: ✭ 87 (+234.62%)
Mutual labels:  miniprogram
mp-ci
微信小程序、小游戏发布助手(CI)
Stars: ✭ 76 (+192.31%)
Mutual labels:  miniprogram
wxml-languageserver
Language server implementation for wxml file in wechat miniprogram
Stars: ✭ 18 (-30.77%)
Mutual labels:  miniprogram
taro-tax
taro版个税小程序
Stars: ✭ 12 (-53.85%)
Mutual labels:  miniprogram
three-platformize
一个让 THREE 平台化的项目,目前已适配微信,淘宝,头条小程序,微信小游戏
Stars: ✭ 418 (+1507.69%)
Mutual labels:  miniprogram
miniprogram-network
Redefine the Network API of Wechat MiniProgram (小程序网络库)
Stars: ✭ 93 (+257.69%)
Mutual labels:  miniprogram

timer-miniprogram

小程序定时器管理库,更合理地使用 setTimeout 和 setInterval,在页面显示时重启定时器,页面隐藏时暂停定时器,页面卸载时清除定时器。 写这个库的缘由详看

使用

可参考 example 目录下的示例项目或参照以下流程:

  1. 通过 npm 安装
npm install --save timer-miniprogram

安装完成之后在微信开发者工具中点击构建 npm。

  1. 导入小程序适配版本的 timer-miniprogram
import { TimerBehavior } from 'timer-miniprogram'
// 在页面中使用
Page({
  behaviors: [TimerBehavior],
  onReady() {
    const timer1 = this.$setTimeout(() => {
      console.log('setTimeout')
    })
    this.$clearTimeout(timer1)

    const timer2 = this.$setInterval(() => {
      console.log('setInterval')
    })
    this.$clearInterval(timer2)
  }
})

// 在组件中使用
Components({
  behaviors: [TimerBehavior],
  ready() {
    const timer1 = this.$setTimeout(() => {
      console.log('setTimeout')
    })
    this.$clearTimeout(timer1)

    const timer2 = this.$setInterval(() => {
      console.log('setInterval')
    })
    this.$clearInterval(timer2)
  }
})

eslint 配置

为了让团队更好地遵守定时器使⽤规范,你还可以配置 eslint 增加代码提示,配置如下:

// .eslintrc.js
module.exports = {
    'rules': {
        'no-restricted-globals': ['error', {
            'name': 'setTimeout',
            'message': 'Please use TimerBehavior and this.$setTimeout instead. see the link: https://github.com/o2team/timer-miniprogram'
        }, {
            'name': 'setInterval',
            'message': 'Please use TimerBehavior and this.$setInterval instead. see the link: https://github.com/o2team/timer-miniprogram'
        }, {
            'name': 'clearInterval',
            'message': 'Please use TimerBehavior and this.$clearInterval instead. see the link: https://github.com/o2team/timer-miniprogram'
        }, {
            'name': 'clearTimout',
            'message': 'Please use TimerBehavior and this.$clearTimout  instead. see the link: https://github.com/o2team/timer-miniprogram'
        }]
    }
}

License

MIT License

Copyright (c) 2020 AOTU Labs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].