-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(universal): bundle mocks with the related libs and remove global…
… `mocks.js` (#350)
- Loading branch information
Showing
15 changed files
with
51 additions
and
137 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
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
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
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
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,14 @@ | ||
export const SafeObserver = | ||
typeof IntersectionObserver !== `undefined` | ||
? IntersectionObserver | ||
: class implements IntersectionObserver { | ||
readonly root = null; | ||
readonly rootMargin = ``; | ||
readonly thresholds = []; | ||
observe(): void {} | ||
unobserve(): void {} | ||
disconnect(): void {} | ||
takeRecords(): IntersectionObserverEntry[] { | ||
return []; | ||
} | ||
}; |
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
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
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
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,10 @@ | ||
export const SafeObserver = | ||
typeof MutationObserver !== `undefined` | ||
? MutationObserver | ||
: class implements MutationObserver { | ||
observe(): void {} | ||
disconnect(): void {} | ||
takeRecords(): MutationRecord[] { | ||
return []; | ||
} | ||
}; |
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
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
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,8 @@ | ||
export const SafeObserver = | ||
typeof ResizeObserver !== `undefined` | ||
? ResizeObserver | ||
: class implements ResizeObserver { | ||
observe(): void {} | ||
unobserve(): void {} | ||
disconnect(): void {} | ||
}; |
22 changes: 3 additions & 19 deletions
22
libs/resize-observer/src/services/resize-observer.service.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 |
---|---|---|
@@ -1,39 +1,23 @@ | ||
import {ElementRef, Inject, Injectable, NgZone} from '@angular/core'; | ||
import {ElementRef, Inject, Injectable} from '@angular/core'; | ||
import {Observable} from 'rxjs'; | ||
import {share} from 'rxjs/operators'; | ||
|
||
import {SafeObserver} from '../classes/safe-observer'; | ||
import {RESIZE_OPTION_BOX} from '../tokens/resize-option-box'; | ||
import {RESIZE_OBSERVER_SUPPORT} from '../tokens/support'; | ||
|
||
@Injectable() | ||
export class ResizeObserverService extends Observable<readonly ResizeObserverEntry[]> { | ||
constructor( | ||
@Inject(ElementRef) {nativeElement}: ElementRef<Element>, | ||
@Inject(NgZone) ngZone: NgZone, | ||
@Inject(RESIZE_OBSERVER_SUPPORT) support: boolean, | ||
@Inject(RESIZE_OPTION_BOX) box: ResizeObserverBoxOptions, | ||
) { | ||
let observer: ResizeObserver; | ||
|
||
super(subscriber => { | ||
if (!support) { | ||
subscriber.error(`ResizeObserver is not supported in your browser`); | ||
|
||
return; | ||
} | ||
const observer = new SafeObserver(entries => subscriber.next(entries)); | ||
|
||
observer = new ResizeObserver(entries => { | ||
ngZone.run(() => { | ||
subscriber.next(entries); | ||
}); | ||
}); | ||
observer.observe(nativeElement, {box}); | ||
|
||
return () => { | ||
observer.disconnect(); | ||
}; | ||
}); | ||
|
||
return this.pipe(share()); | ||
} | ||
} |
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
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