本文整理匯總了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>;
}