class Timer{

    constructor() {
        this.currentTime = 0;
        this.isActive = false;
        this.idCounter = 0;

        this.events = {};
    }

    play(){
        this.isActive=true;
    }

    tick(){
        let event,eventId;

        if (this.isActive) {
            this.currentTime++;

            for (eventId in this.events){
                event = this.events[eventId];
                if (event){

                    if (event.type=="repeat"){
                        if ((this.currentTime-event.startOffset) % event.time == 0){
                            event.callback.apply(event.thisContext,event.args);
                        }
                    }
                    if(event.type=="single"){
                        if ((this.currentTime-event.startOffset) % event.time == 0) {
                            event.callback.apply(event.thisContext,event.args);
                            event.destroy();
                        }
                    }

                }

            }
        }
    }

    destroyEvent(eventId){
        delete this.events[eventId];
    };

    loop(time,callback) {
        let timerEvent = new TimerEvent(this,
            TimerEvent.TYPES.repeat,
            time,
            callback
        );

        this.events[timerEvent.id] = timerEvent;

        return timerEvent;
    }

    add(time,callback,thisContext,args){
        let timerEvent = new TimerEvent(this,
            TimerEvent.TYPES.single,
            time,
            callback,
            thisContext,
            args
        );

        this.events[timerEvent.id]=timerEvent;
        return timerEvent;
    };

    //todo implement timer delete all events

    destroy(id){
        delete this.events[id];
    }
}


//timer event
class TimerEvent{
    constructor(timer,type,time,callback,thisContext,args){
        this.id=++timer.idCounter;
        this.timer=timer;
        this.type=type;
        this.time=time;
        this.callback=callback;
        this.startOffset=timer.currentTime;
        this.thisContext=thisContext;
        this.args=args;

        this.destroy=function(){
            this.timer.destroy(this.id);
        }
    };
}

TimerEvent.TYPES={
    repeat: "repeat",
    single: "single"
};

module.exports = Timer;
@@ -1,16 +1,31 @@
+'use strict';%0A%0A
 class Timer%7B%0A%0A  
@@ -19,16 +19,17 @@
 ss Timer
+ 
 %7B%0A%0A    c
@@ -2219,17 +2219,19 @@
 nt.TYPES
-=
+ = 
 %7B%0A    re
@@ -2236,24 +2236,24 @@
 repeat: 
-%22
+'
 repeat
-%22
+'
 ,%0A    si
@@ -2258,24 +2258,24 @@
 single: 
-%22
+'
 single
-%22
+'
 %0A%7D;%0A%0Amod
@@ -2290,12 +2290,13 @@
 rts = Timer;
+%0A

fix crash on heroku