Skip to content

Commit

Permalink
perf(app): adds fast path in isEnabled() and isScrolling()
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Nov 28, 2016
1 parent 36eb834 commit 5526d70
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/app/app.ts
Expand Up @@ -135,22 +135,34 @@ export class App {
* @return {boolean}
*/
isEnabled(): boolean {
return (this._disTime < Date.now());
const disTime = this._disTime;
if (disTime === 0) {
return true;
}
return (disTime < Date.now());
}

/**
* @private
*/
setScrolling() {
this._scrollTime = Date.now();
this._scrollTime = Date.now() + ACTIVE_SCROLLING_TIME;
}

/**
* Boolean if the app is actively scrolling or not.
* @return {boolean} returns true or false
*/
isScrolling(): boolean {
return ((this._scrollTime + ACTIVE_SCROLLING_TIME) > Date.now());
const scrollTime = this._scrollTime;
if (scrollTime === 0) {
return false;
}
if (scrollTime < Date.now()) {
this._scrollTime = 0;
return false;
}
return true;
}

/**
Expand Down

0 comments on commit 5526d70

Please sign in to comment.