本文整理匯總了TypeScript中rxjs/operators.shareReplay函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript shareReplay函數的具體用法?TypeScript shareReplay怎麽用?TypeScript shareReplay使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了shareReplay函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: ngOnInit
ngOnInit() {
this.toolbarMode$ = this.store.select(fromStore.getToolbarMode).pipe(
shareReplay());
this.folders$ = this.store.select(fromStore.getAllFolders);
this.currentFilter$ = this.store.select(fromStore.getCurrentFilter);
this.folderView$ = this.store
.select(fromStore.getCurrentFolder)
.pipe(shareReplay());
this.playlistView$ = this.store.select(fromStore.getCurrentPlaylist).pipe(shareReplay())
this.selectedVideos$ = this.store
.select(fromStore.getSelectedVideos)
.pipe(shareReplay());
}
示例2: _dispatch
private _dispatch(action: any): Observable<any> {
const meta = this[META_KEY] as StoreMetaInfo;
if (!meta) {
throw new Error(`${META_KEY} is not found, current store has not action`);
}
const actionMeta = meta.actions[action.type];
if (!actionMeta) {
throw new Error(`${action.type} is not found`);
}
let result: any = this[actionMeta.fn](this.snapshot, action.payload);
if (result instanceof Promise) {
result = from(result);
}
if (result instanceof Observable) {
result = result.pipe(map(r => r));
} else {
result = Observable.create((observer: Observer<any>) => {
observer.next({});
});
// result = of({});
}
return result.pipe(shareReplay());
}
示例3: getProjects
getProjects(): Observable<Project[]> {
return this.http.get<Project[]>('assets/data/projects.json')
.pipe(
map(res => res.map(r => ProjectModel(r))),
shareReplay()
);
}
示例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: discover
export function discover(config: PluginsConfig, coreContext: CoreContext) {
const log = coreContext.logger.get('plugins-discovery');
log.debug('Discovering plugins...');
if (config.additionalPluginPaths.length) {
log.warn(
`Explicit plugin paths [${
config.additionalPluginPaths
}] are only supported in development. Relative imports will not work in production.`
);
}
const discoveryResults$ = merge(
from(config.additionalPluginPaths),
processPluginSearchPaths$(config.pluginSearchPaths, log)
).pipe(
mergeMap(pluginPathOrError => {
return typeof pluginPathOrError === 'string'
? createPlugin$(pluginPathOrError, log, coreContext)
: [pluginPathOrError];
}),
shareReplay()
);
return {
plugin$: discoveryResults$.pipe(
filter((entry): entry is PluginWrapper => entry instanceof PluginWrapper)
),
error$: discoveryResults$.pipe(
filter((entry): entry is PluginDiscoveryError => !(entry instanceof PluginWrapper))
),
};
}
示例6: ngOnInit
ngOnInit () {
this.playlist$ = this._route.paramMap.pipe(
map(paramMap => ({ playlistId: paramMap.get('id'), playlistOwnerId: paramMap.get('user') })),
switchMap(params =>
this._spotifyService.getPlaylist(params.playlistOwnerId, params.playlistId)
),
map(playlist => ({
isLoading: false,
result: playlist
})),
startWith({
isLoading: true,
result: null
}),
shareReplay()
);
this.tracks$ = this.playlist$.pipe(
filter(o => !o.isLoading && !!o.result),
map(o => o.result.Tracks)
);
this.playlistUrl$ = this.playlist$.pipe(
filter(o => !o.isLoading && !!o.result),
map(o => o.result),
map(playlist => playlist.ImageUrls.length ? playlist.ImageUrls[0] : '')
);
}
示例7: combineLatest
// Invokes hub method on subscription, stores replay.
invokeAndListenFor<T>(method: string, listener: string, ...parameters: any[]): Observable<T> {
return combineLatest(this.listenFor<T>(listener), this.invoke(method, ...parameters)).pipe(
// Only pass the listenFor results
map((x) => { return x[0]; }),
// Keep the last result
shareReplay(1)
);
}
示例8: getProject
getProject(slug: string): Observable<Project> {
return this.http.get<Project[]>('assets/data/projects.json')
.pipe(
map(res => res.map(r => ProjectModel(r))),
map(projects => projects.find(p => p.slug.toLowerCase() === slug.toLowerCase())),
shareReplay()
);
}
示例9: getActionResultStream
private getActionResultStream(action: any): Observable<ActionContext> {
return this._actionResults.pipe(
filter(
(ctx: ActionContext) => ctx.action === action && ctx.status !== ActionStatus.Dispatched
),
take(1),
shareReplay()
);
}
示例10: observe
observe(key: string): Observable<any> {
key = StorageKeyManager.normalize(key);
return this.strategy.keyChanges.pipe(
filter((changed: string) => changed === null || changed === key),
switchMap(() => this.strategy.get(key)),
distinctUntilChanged(),
shareReplay()
);
}