Last active
November 16, 2017 21:29
-
-
Save carlosdelfino/3afd388c9904497f8bbae7b233708f61 to your computer and use it in GitHub Desktop.
Teste com setInterval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Observable} from 'data/observable'; | |
export class HelloWorldModel extends Observable { | |
private _counter1: number; | |
private _counter2: number; | |
private _id1: number; | |
private _id2: number; | |
constructor() { | |
super(); | |
// Initialize default values. | |
this._counter1 = 0; | |
this._counter2 = 0; | |
} | |
get counter1(): number{ | |
return this._counter1; | |
} | |
set counter1(value: number){ | |
this._counter1 = value; | |
this.notifyPropertyChange("counter1",value); | |
} | |
get counter2(): number{ | |
return this._counter2; | |
} | |
set counter2(value: number){ | |
this._counter2 = value; | |
this.notifyPropertyChange("counter2",value); | |
} | |
public onTap() { | |
if(this._id1 == null){ | |
this._id1 = setInterval(()=>{ | |
this.counter1++ | |
}, 100); | |
}else{ | |
clearTimeout(this._id1); | |
this._id1 = null; | |
} | |
if(this._id2 == null){ | |
this._id2 = setInterval(()=>{ | |
this.counter2++ | |
}, 200); | |
}else{ | |
clearTimeout(this._id2); | |
this._id2 = null; | |
} | |
console.log("onTap"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment