本文整理汇总了TypeScript中rxjs/operators.publishLast函数的典型用法代码示例。如果您正苦于以下问题:TypeScript publishLast函数的具体用法?TypeScript publishLast怎么用?TypeScript publishLast使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了publishLast函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getContributors
private getContributors() {
const contributors = this.http.get<{[key: string]: Contributor}>(contributorsPath).pipe(
// Create group map
map(contribs => {
const contribMap: { [name: string]: Contributor[]} = {};
Object.keys(contribs).forEach(key => {
const contributor = contribs[key];
contributor.groups.forEach(group => {
const contribGroup = contribMap[group] || (contribMap[group] = []);
contribGroup.push(contributor);
});
});
return contribMap;
}),
// Flatten group map into sorted group array of sorted contributors
map(cmap => {
return Object.keys(cmap).map(key => {
const order = knownGroups.indexOf(key);
return {
name: key,
order: order === -1 ? knownGroups.length : order,
contributors: cmap[key].sort(compareContributors)
} as ContributorGroup;
})
.sort(compareGroups);
}),
publishLast(),
);
(contributors as ConnectableObservable<ContributorGroup[]>).connect();
return contributors;
}
示例2: getVersionInfo
private getVersionInfo(navigationInfo: Observable<NavigationResponse>) {
const versionInfo = navigationInfo.pipe(
map(response => response.__versionInfo),
publishLast(),
);
(versionInfo as ConnectableObservable<VersionInfo>).connect();
return versionInfo;
}
示例3: it
it('should accept empty parameter', () => {
// Here, TypeScript versions 3.1 and earlier infer Observable<any>. However,
// the next version infers Observable<number>. It's not possible to specify
// an upper bound for the TypeScript version used by dtslint, so an
// expectation cannot be applied.
// TODO: put the test back after Typescript > 3.2
const a = of(1, 2, 3).pipe(publishLast());
});
示例4: getCategories
private getCategories(): Observable<Category[]> {
const categories = this.http.get<any>(resourcesPath).pipe(
map(data => mkCategories(data)),
publishLast(),
);
(categories as ConnectableObservable<Category[]>).connect();
return categories;
};
示例5: getNavigationViews
private getNavigationViews(navigationInfo: Observable<NavigationResponse>): Observable<NavigationViews> {
const navigationViews = navigationInfo.pipe(
map(response => {
const views = Object.assign({}, response);
Object.keys(views).forEach(key => {
if (key[0] === '_') { delete views[key]; }
});
return views as NavigationViews;
}),
publishLast(),
);
(navigationViews as ConnectableObservable<NavigationViews>).connect();
return navigationViews;
}
示例6: fetchNavigationInfo
/**
* Get an observable that fetches the `NavigationResponse` from the server.
* We create an observable by calling `http.get` but then publish it to share the result
* among multiple subscribers, without triggering new requests.
* We use `publishLast` because once the http request is complete the request observable completes.
* If you use `publish` here then the completed request observable will cause the subscribed observables to complete too.
* We `connect` to the published observable to trigger the request immediately.
* We could use `.refCount` here but then if the subscribers went from 1 -> 0 -> 1 then you would get
* another request to the server.
* We are not storing the subscription from connecting as we do not expect this service to be destroyed.
*/
private fetchNavigationInfo(): Observable<NavigationResponse> {
const navigationInfo = this.http.get<NavigationResponse>(navigationPath)
.pipe(publishLast());
(navigationInfo as ConnectableObservable<NavigationResponse>).connect();
return navigationInfo;
}
示例7:
export function publishLast<T>(this: Observable<T>): ConnectableObservable<T> {
//TODO(benlesh): correct type-flow through here.
return higherOrder<T>()(this) as ConnectableObservable<T>;
}