feat(aio): replace `take(1)` with more semantic `first()` (#14571)
This commit is contained in:
parent
45eac233eb
commit
c4a6263a01
|
@ -9,7 +9,7 @@ import { of } from 'rxjs/observable/of';
|
||||||
import 'rxjs/add/observable/throw';
|
import 'rxjs/add/observable/throw';
|
||||||
import 'rxjs/add/operator/catch';
|
import 'rxjs/add/operator/catch';
|
||||||
import 'rxjs/add/operator/delay';
|
import 'rxjs/add/operator/delay';
|
||||||
import 'rxjs/add/operator/take';
|
import 'rxjs/add/operator/first';
|
||||||
|
|
||||||
describe('DocService', () => {
|
describe('DocService', () => {
|
||||||
let docFetchingService: DocFetchingService;
|
let docFetchingService: DocFetchingService;
|
||||||
|
@ -31,7 +31,7 @@ describe('DocService', () => {
|
||||||
loggerSpy = jasmine.createSpyObj('logger', ['log', 'warn', 'error']);
|
loggerSpy = jasmine.createSpyObj('logger', ['log', 'warn', 'error']);
|
||||||
docFetchingService = new DocFetchingService(null, loggerSpy);
|
docFetchingService = new DocFetchingService(null, loggerSpy);
|
||||||
getFileSpy = spyOn(docFetchingService, 'getDocFile').and
|
getFileSpy = spyOn(docFetchingService, 'getDocFile').and
|
||||||
.returnValue(of(testDoc).delay(0).take(1)); // take(1) -> completes
|
.returnValue(of(testDoc).delay(0).first()); // first() -> completes
|
||||||
|
|
||||||
docService = new DocService(docFetchingService, loggerSpy);
|
docService = new DocService(docFetchingService, loggerSpy);
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,12 +19,12 @@ describe('NavMapService', () => {
|
||||||
|
|
||||||
beforeEach(done => {
|
beforeEach(done => {
|
||||||
httpSpy = jasmine.createSpyObj('http', ['get']);
|
httpSpy = jasmine.createSpyObj('http', ['get']);
|
||||||
httpSpy.get.and.returnValue(of(getTestNavMapResponse()).delay(0).take(1)); // take(1) -> completes
|
httpSpy.get.and.returnValue(of(getTestNavMapResponse()).delay(0).first()); // first() -> completes
|
||||||
loggerSpy = jasmine.createSpyObj('logger', ['log', 'warn', 'error']);
|
loggerSpy = jasmine.createSpyObj('logger', ['log', 'warn', 'error']);
|
||||||
|
|
||||||
navMapService = new NavMapService(new DocFetchingService(null, null), httpSpy, loggerSpy);
|
navMapService = new NavMapService(new DocFetchingService(null, null), httpSpy, loggerSpy);
|
||||||
|
|
||||||
navMapService.navMap.take(1).subscribe(
|
navMapService.navMap.first().subscribe(
|
||||||
nm => navMap = nm,
|
nm => navMap = nm,
|
||||||
null,
|
null,
|
||||||
done);
|
done);
|
||||||
|
|
|
@ -51,7 +51,7 @@ describe('SidenavComponent', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
navEngine = {
|
navEngine = {
|
||||||
currentDoc: of(fakeDoc).delay(0).take(1),
|
currentDoc: of(fakeDoc).delay(0).first(),
|
||||||
navigate: (docId: string) => { }
|
navigate: (docId: string) => { }
|
||||||
} as NavEngine;
|
} as NavEngine;
|
||||||
navigateSpy = spyOn(navEngine, 'navigate');
|
navigateSpy = spyOn(navEngine, 'navigate');
|
||||||
|
@ -69,7 +69,7 @@ describe('SidenavComponent', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
navMapService = {
|
navMapService = {
|
||||||
navMap: of(fakeNavMap).delay(0).take(1)
|
navMap: of(fakeNavMap).delay(0).first()
|
||||||
} as NavMapService;
|
} as NavMapService;
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
|
|
|
@ -41,7 +41,7 @@ export class SidenavComponent implements OnInit {
|
||||||
// Side effect: when the current doc changes,
|
// Side effect: when the current doc changes,
|
||||||
// get its NavNode and alert the navigation panel
|
// get its NavNode and alert the navigation panel
|
||||||
this.currentDocId = doc.metadata.docId;
|
this.currentDocId = doc.metadata.docId;
|
||||||
this.navMapService.navMap.take(1) // take makes sure it completes!
|
this.navMapService.navMap.first() // take makes sure it completes!
|
||||||
.map(navMap => navMap.docs.get(this.currentDocId))
|
.map(navMap => navMap.docs.get(this.currentDocId))
|
||||||
.subscribe( node => this.selectedNode.emit(node));
|
.subscribe( node => this.selectedNode.emit(node));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue