Skip to content

Bit-Coin/Bit-Coin-3

Repository files navigation

Bit-Coin-3

Utility class to simplify use of timers created by setTimeout.

NPM version Build Status Built with Grunt

Installation

Node

npm install chronoman
jspm install chronoman
bower install chronoman
jam install chronoman

AMD, <script>

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

Usage

ECMAScript 6/2015

import Timer from "chronoman";

Node, JSPM

var Timer = require("chronoman");
var Timer = require("gamtiq/chronoman");

JSPM

System.import("chronoman").then(function(Timer) {
    ...
});

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);
        if (! tmrThree.isActive()) {
            tmrThree.start();
        }
    }
});

var tmrTwo = new Timer();
tmrTwo.setPeriod(2000)
    .setRepeatQty(9)
    .setPassToAction(true)
    .setAction(function(timer) {
        nI++;
        console.log("Timer two. #", nI, timer);
        tmrOne.setActive(nI % 2 === 1);
    });

var tmrThree = new Timer()
                    .setPeriod(3000)
                    .setRepeatTest(function() {
                        return tmrTwo.isActive();
                    });
tmrThree.onExecute = function() {
    console.log("* Timer three. #", this.getExecutionQty() + 1);
};

tmrTwo.start();

API

See doc folder.

Inspiration

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

Licence

Copyright (c) 2013-2016 Bit-Coin-#
Licensed under the MIT license.

About

Utility class to simplify use of timers created by setTimeout.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages