-
-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(click): lazily initialise all click handlers
Fixes #942
- Loading branch information
1 parent
31fda3b
commit 823ee4d
Showing
3 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
projects/angular-calendar/src/modules/common/request-idle-callback.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Observable } from 'rxjs'; | ||
|
||
const isSupported = | ||
typeof window !== 'undefined' && | ||
typeof window['requestIdleCallback'] !== 'undefined'; | ||
|
||
export function requestIdleCallbackObservable() { | ||
return new Observable(observer => { | ||
/* istanbul ignore else */ | ||
if (isSupported) { | ||
const id = window['requestIdleCallback'](() => { | ||
observer.next(); | ||
observer.complete(); | ||
}); | ||
return () => { | ||
window['cancelIdleCallback'](id); | ||
}; | ||
} else { | ||
const timeoutId = setTimeout(() => { | ||
observer.next(); | ||
observer.complete(); | ||
}, 1); | ||
return () => { | ||
clearTimeout(timeoutId); | ||
}; | ||
} | ||
}); | ||
} |
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