npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-crono

v2.0.9

Published

Simple timers/jobs for vue components

Downloads

679

Readme

vue-crono

CircleCI

Easily schedule and manage cron jobs in Vue components

jsfiddle example

Project Example here

Project Example Source here

Installation

npm install vue-crono --save

Install globally

import crono from 'vue-crono';
Vue.use(crono);

or inside your component

import { crono } from 'vue-crono';

//Your component
export default{
    mixins: [crono]
}

or include from https://unpkg.com/[email protected]/dist/index.js

<script src="https://unpkg.com/[email protected]/dist/index.js"></script> which will put the plugin on window.crono

or npm install the package and browse to node_modules/vue-cron/dist/index.js and copy the file into your application

Usage

Schedule Vue methods to run on interval using the cron property on your Vue component. cron also accepts an array of objects to call multiple methods.

cron option structure is as follows

{
    // Number in milliseconds
    time: Number,

    // Vue component method name
    method: String,
    
    // Automatic Start (true by default)
    autoStart: true
}

Example Component to keep a timer up to date.

Other use cases:

  • Polling to check a status
  • Refreshing data from a service periodically
  • Warning a user about a time sensitive action

Example:

export default{
    data(){
        return {
            currentTime: undefined,
        }
    },
    methods:{
      load(){
          this.currentTime = (new Date().toLocaleTimeString());
      }
    },
    cron:{
        time: 1000,
        method: 'load'
    }
}

Multiple cron definition:

cron:[{
    time: 5000,
    method: 'load',
},
{
    time: 32000,
    method: 'stopTimer'
}]

API

If you create jobs via the cron option, you can start, stop, and restart them on the component instance using

this.$cron.stop(methodName)

this.$cron.start(methodName)

this.$cron.restart(methodName)

Note: Jobs are restarted from the beginning after being stopped. Timers are cleaned up when components are destroyed.

You can adjust the time of existing jobs, even while they're running, using

this.$cron.time(methodName, time)

This method is intelligent enough to know if the timer should have been invoked when decreasing the time of a job as well as extending the time to the next job run if you're increasing the timer. Adjusting the time on a stopped job will behave as though you started it from scratch. (See unit tests if curious about this behavior)

clean-time Component

<clean-time></clean-time>

import cleanTime from 'vue-crono/cleanTime'

A Vue component that provides human readable, realtime updated, timestamp for past events. Supports localization and custom template strings.

clean-time requires a single prop time (a Date object) and offers some customization props.

Example here

Example Source here