This file contains hidden or 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
export function watch<T>( | |
changeDetectorRef: ChangeDetectorRef, | |
): MonoTypeOperatorFunction<T> { | |
return (source: Observable<T>) => | |
source.pipe( | |
tap(() => { | |
changeDetectorRef.markForCheck(); | |
}), | |
); | |
} |
This file contains hidden or 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
export class ReplayControlValueChanges<T> extends Observable<T> { | |
constructor(control: AbstractControl | AbstractControlDirective) { | |
super(subscriber => { | |
if (!control.valueChanges) { | |
throw new Error('Control does not have valueChanges'); | |
} | |
control.valueChanges.pipe(startWith(control.value)).subscribe(subscriber); | |
}); | |
} |
This file contains hidden or 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 {AbstractControl, FormArray, FormGroup} from '@angular/forms'; | |
export function markControlAsTouchedAndValidate(control: AbstractControl) { | |
if (control instanceof FormArray) { | |
control.controls.forEach(nestedControl => { | |
markControlAsTouchedAndValidate(nestedControl); | |
}); | |
return; | |
} |
This file contains hidden or 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 {DOCUMENT} from '@angular/common'; | |
import {inject, InjectionToken} from '@angular/core'; | |
export const WINDOW = new InjectionToken<Window>( | |
'An abstraction over global window object', | |
{ | |
factory: () => { | |
const {defaultView} = inject(DOCUMENT); | |
if (!defaultView) { |
This file contains hidden or 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
@Injectable({ providedIn: 'root' }) | |
export class StaticRequestService { | |
private readonly cache = new Map<string, Observable<string>>(); | |
request(url: string): Observable<string> { | |
const cache = this.cache.get(url); | |
if (cache) { | |
return cache; | |
} |
This file contains hidden or 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
/** | |
* Returns current active element, including shadow dom | |
* | |
* @return element or null | |
*/ | |
export function getNativeFocused(documentRef: Document): Element | null { | |
if (!documentRef.activeElement || !documentRef.activeElement.shadowRoot) { | |
return documentRef.activeElement; | |
} |
This file contains hidden or 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 { inject, InjectionToken } from '@angular/core'; | |
// from https://github.com/ng-web-apis/common | |
import { USER_AGENT } from '@ng-web-apis/common'; | |
// https://stackoverflow.com/a/11381730/2706426 http://detectmobilebrowsers.com/ | |
const firstRegex = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/; | |
const secondRegex = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go |
This file contains hidden or 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
{ | |
"scripts": { | |
"build": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --configuration=production" | |
} | |
} |
This file contains hidden or 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
const pageVisibility$ = fromEvent(documentRef, 'visibilitychange').pipe( | |
startWith(0), | |
map(() => documentRef.visibilityState !== 'hidden'), | |
distinctUntilChanged(), | |
); |
This file contains hidden or 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 {DOCUMENT} from '@angular/common'; | |
import {inject, InjectionToken} from '@angular/core'; | |
import {fromEvent, Observable} from 'rxjs'; | |
import {distinctUntilChanged, map, share, startWith} from 'rxjs/operators'; | |
export const PAGE_VISIBILITY = new InjectionToken<Observable<boolean>>( | |
'Shared Observable based on `document visibility changed`', | |
{ | |
factory: () => { | |
const documentRef = inject(DOCUMENT); |
OlderNewer