1 import { Injectable } from '@angular/core'
4 export class ScreenService {
5 private windowInnerWidth: number
6 private lastFunctionCallTime: number
7 private cacheForMs = 500
10 this.refreshWindowInnerWidth()
14 return this.getWindowInnerWidth() < 600
18 return this.getWindowInnerWidth() < 500
21 // Cache window inner width, because it's an expensive call
22 private getWindowInnerWidth () {
23 if (this.cacheWindowInnerWidthExpired()) this.refreshWindowInnerWidth()
25 return this.windowInnerWidth
28 private refreshWindowInnerWidth () {
29 this.lastFunctionCallTime = new Date().getTime()
31 this.windowInnerWidth = window.innerWidth
34 private cacheWindowInnerWidthExpired () {
35 return new Date().getTime() > (this.lastFunctionCallTime + this.cacheForMs)