Skip to content

Instantly share code, notes, and snippets.

@carlosdelfino
Last active November 16, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosdelfino/3afd388c9904497f8bbae7b233708f61 to your computer and use it in GitHub Desktop.
Save carlosdelfino/3afd388c9904497f8bbae7b233708f61 to your computer and use it in GitHub Desktop.
Teste com setInterval
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