本文整理匯總了TypeScript中rxjs.forkJoin函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript forkJoin函數的具體用法?TypeScript forkJoin怎麽用?TypeScript forkJoin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了forkJoin函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: type
type('should support arrays of observables', () => {
/* tslint:disable:no-unused-variable */
let a: Observable<number>[];
let o1: Observable<number[]> = forkJoin(a);
let o2: Observable<number[]> = forkJoin(...a);
/* tslint:enable:no-unused-variable */
});
示例2: dispatchByEvents
private dispatchByEvents(actionOrActions: any | any[]): Observable<any> {
if (Array.isArray(actionOrActions)) {
return forkJoin(actionOrActions.map(a => this.dispatchSingle(a)));
} else {
return this.dispatchSingle(actionOrActions);
}
}
示例3: Observable
return new Observable((observer) => {
forkJoin(
involvedObservable,
myTaskObservable,
queuedObservable,
completeObservable
).subscribe(
(res) => {
let filters: FilterRepresentationModel[] = [];
res.forEach((filter) => {
if (filter.name === involvedTasksFilter.name) {
involvedTasksFilter.id = filter.id;
filters.push(involvedTasksFilter);
} else if (filter.name === myTasksFilter.name) {
myTasksFilter.id = filter.id;
filters.push(myTasksFilter);
} else if (filter.name === queuedTasksFilter.name) {
queuedTasksFilter.id = filter.id;
filters.push(queuedTasksFilter);
} else if (filter.name === completedTasksFilter.name) {
completedTasksFilter.id = filter.id;
filters.push(completedTasksFilter);
}
});
observer.next(filters);
observer.complete();
},
(err: any) => {
this.logService.error(err);
});
});
示例4: getModules
getModules(): Observable<Module[]> {
if (!this.modulesCache$) {
this.modulesCache$ = forkJoin(
this.configService.getModules(), // names of the enabled modules
this.toolResource.getModules() // all modules from the server
).pipe(
map(results => {
const enabledModules: string[] = results[0];
const allModules: Module[] = results[1];
return allModules
.filter(
(module: Module) => enabledModules.indexOf(module.name) >= 0
)
.map((module: Module) => {
// set moduleId
module.moduleId = module.name.toLowerCase();
// create categoriesMap
module.categoriesMap = UtilsService.arrayToMap(
module.categories,
"name"
);
return module;
});
}),
shareReplay(1)
);
}
return this.modulesCache$;
}
示例5: async
async(inject([HttpInterceptorService, MockBackend], (service: HttpInterceptorService, mockBackend: MockBackend) => {
mockBackend.connections.subscribe((connection: MockConnection) => {
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: JSON.stringify('success')},
)));
});
let success: boolean = false;
let error: boolean = false;
let complete: boolean = false;
forkJoin(
service.get('testurl'),
service.get('testurl'))
.subscribe((response: Response[]) => {
success = true;
}, () => {
error = true;
}, () => {
complete = true;
});
expect(success).toBe(true, 'on success didnt execute with observables');
expect(error).toBe(false, 'on error executed when it shouldnt have with observables');
expect(complete).toBe(true, 'on complete didnt execute with observables');
}),
示例6: forkJoin1
forkJoin1() {
const myPromise = val =>
new Promise(resolve =>
setTimeout(() => resolve(`Promise Resolved: ${val}`), 5000)
);
/*
when all observables complete, give the last
emitted value from each as an array
*/
const example = forkJoin(
// emit 'Hello' immediately
of('Hello'),
// emit 'World' after 1 second
of('World').pipe(delay(1000)),
// emit 0 after 1 second
interval(1000).pipe(take(1)),
// emit 0...1 in 1 second interval
interval(1000).pipe(take(2)),
// promise that resolves to 'Promise Resolved' after 5 seconds
myPromise('RESULT')
);
// output: ["Hello", "World", 0, 1, "Promise Resolved: RESULT"]
const subscribe = example.subscribe(val => console.log(val));
}
示例7: Observable
return new Observable((observer) => {
forkJoin(
runningObservable,
completedObservable,
allObservable
).subscribe(
(res) => {
let filters: FilterProcessRepresentationModel[] = [];
res.forEach((filter) => {
if (filter.name === runningFilter.name) {
runningFilter.id = filter.id;
filters.push(runningFilter);
} else if (filter.name === completedFilter.name) {
completedFilter.id = filter.id;
filters.push(completedFilter);
} else if (filter.name === allFilter.name) {
allFilter.id = filter.id;
filters.push(allFilter);
}
});
observer.next(filters);
observer.complete();
},
(err: any) => {
this.handleProcessError(err);
});
});
示例8: it
it('should accept array of observable contains single', () => {
const e1 = forkJoin(
[hot('--a--b--c--d--|')]
);
const expected = '--------------(x|)';
expectObservable(e1).toBe(expected, {x: ['d']});
});