
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
vue-timers
Advanced tools
Simple mixin to manage timers or intervals for Vue.js
<script src="https://cdn.jsdelivr.net/npm/vue-timers/dist/vue-timers.umd.js"></script>
npm install vue-timers
yarn add vue-timers
import Vue from 'vue'
import VueTimers from 'vue-timers'
Vue.use(VueTimers)
import {mixin as VueTimers} from 'vue-timers'
export default {
mixins: [VueTimers]
}
nuxt.config.js
:
export default {
plugins: [
{ src: '~/plugins/vue-timers', mode: 'client' }
]
}
plugins/vue-timers.js
:
import Vue from 'vue'
import VueTimers from 'vue-timers'
Vue.use(VueTimers)
It creates timer instances in components and slightly reduces boilerplate code with their handling.
See the following code
export default {
methods: {
log () {
console.log('Hello world')
}
},
created () {
// It looks OK for the first look
// But imagine that you have more than one timer
this.$options.interval = setInterval(this.log, 1000)
// Ok? What about check if timer works?
// And it's not reactive so you should create data option
console.log(this.$options.interval !== null)
// Still ok? So what about reusable timers?
// New method for that? Rly?
},
// Did you forget that it should be destroyed?
beforeDestroy () {
clearInterval(this.$options.interval)
}
}
It's ugly, isn't it? So let's try to fix this :)
Same code with vue-timers
:
export default {
timers: {
log: { time: 1000, autostart: true }
},
methods: {
log () {
console.log('Hello world')
}
}
}
{
// Name of timer
// Default: timer key (with object notation)
name: String,
// Tick callback or method name from component
// Note: callback is binded to component instance
// Default: name
callback: Function/String,
// Autostart timer from created hook
// Default: false
autostart: Boolean,
// Set true to repeat (with setInterval) or false (setTimeout)
// Default: false
repeat: Boolean,
// Set true to call first tick immediate
// Note: repeat must be true too
// Default: false
immediate: Boolean,
// Time between ticks
// Default: 1000
time: Number
// Switch timer`s status between activated and deactivated
// Default: false
isSwitchTab: Boolean
}
this.timers.log.time = 2000
NOTE: you should restart timer to apply changes
// Starts `log` timer
this.$timer.start('log')
// Stops `log` timer
this.$timer.stop('log')
this.timers.log.isRunning
import { timer } from 'vue-timers'
export default {
timers: [
timer('log', 1000)
],
methods: {
log () {
console.log('It works!')
}
}
}
<template>
<timer-component
@timer-start:log="timerStarted"
@timer-stop:log="timerStopped"
@timer-tick:log="timerTicked"
/>
</template>
export default {
timers: {
log: { time: 1000, ...options }
}
}
export default {
timers: [
{ name: 'log', time: 1000, ...options }
]
}
import { timer } from 'vue-timers'
export default {
timers: [
timer('log', 1000, { ...options })
]
}
MIT
FAQs
Mixin to manage your intervals in Vue.js
The npm package vue-timers receives a total of 1,463 weekly downloads. As such, vue-timers popularity was classified as popular.
We found that vue-timers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.