Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Utility class to simplify use of timers created by setTimeout

branch: master
README.md

chronoman

Utility class to simplify use of timers created by setTimeout.

NPM version

Installation

Node

npm install chronoman

Component

component install gamtiq/chronoman

Jam

jam install chronoman

Bower

bower install chronoman

SPM

spm install chronoman

AMD, <script>

Use dist/chronoman.js or dist/chronoman.min.js (minified version).

Usage

Node, Component, SPM

var Timer = require("chronoman");

Jam

require(["chronoman"], function(Timer) {
    ...
});

AMD

define(["path/to/dist/chronoman.js"], function(Timer) {
    ...
});

Bower, <script>

<!-- Use bower_components/chronoman/dist/chronoman.js if the library was installed by Bower -->
<script type="text/javascript" src="path/to/dist/chronoman.js"></script>
<script type="text/javascript">
    // сhronoman is available via Chronoman field of window object
    var Timer = Chronoman;
    ...
</script>

Example

var nI = 0;

var tmrOne = new Timer({
    period: 1000,
    action: function(timer) {
        console.log("---> Timer one. ", timer);   // timer is undefined because passToAction is false by default
    }
});

var tmrTwo = new Timer();
tmrTwo.setPeriod(2000)
    .setRecurrent(true)
    .setPassToAction(true)
    .setAction(function(timer) {
        nI++;
        console.log("Timer two. #", nI, timer);
        tmrOne.setActive(! tmrOne.isActive());
        if (nI === 10) {
            timer.stop();
        }
    });

tmrTwo.start();

API

See doc folder.

Inspiration

This module is inspired by qooxdoo's qx.event.Timer class.

Licence

MIT

Something went wrong with that request. Please try again.