private getVersionInfo(navigationInfo: Observable<NavigationResponse>) { const versionInfo = navigationInfo .map(response => response.__versionInfo) .publishLast(); versionInfo.connect(); return versionInfo; }
/** * Get an observable that will list the nodes that are currently selected * We use `publishReplay(1)` because otherwise subscribers will have to wait until the next * URL change before they receive an emission. * See above for discussion of using `connect`. */ private getSelectedNodes(navigationViews: Observable<NavigationViews>) { const selectedNodes = combineLatest( navigationViews.map(this.computeUrlToNodesMap), this.location.currentUrl, (navMap, url) => navMap[url] || []) .publishReplay(1); selectedNodes.connect(); return selectedNodes; }
private getCategories(): Observable<Category[]> { const categories = this.http.get<any>(resourcesPath) .map(data => mkCategories(data)) .publishLast(); categories.connect(); return categories; };
private getNavigationViews(navigationInfo: Observable<NavigationResponse>): Observable<NavigationViews> { const navigationViews = navigationInfo.map(response => { const views: NavigationViews = Object.assign({}, response); Object.keys(views).forEach(key => { if (key[0] === '_') { delete views[key]; } }); return views; }).publishReplay(1); navigationViews.connect(); return navigationViews; }
/** * Get an observable of the current node (the one that matches the current URL) * We use `publishReplay(1)` because otherwise subscribers will have to wait until the next * URL change before they receive an emission. * See above for discussion of using `connect`. */ private getCurrentNode(navigationViews: Observable<NavigationViews>): Observable<CurrentNode> { const currentNode = combineLatest( navigationViews.map(this.computeUrlToNavNodesMap), this.location.currentPath, (navMap, url) => { const urlKey = url.startsWith('api/') ? 'api' : url; return navMap[urlKey] || { view: '', url: urlKey, nodes: [] }; }) .publishReplay(1); currentNode.connect(); return currentNode; }
/** * Get an observable of the current nodes (the ones that match the current URL) * We use `publishReplay(1)` because otherwise subscribers will have to wait until the next * URL change before they receive an emission. * See above for discussion of using `connect`. */ private getCurrentNodes(navigationViews: Observable<NavigationViews>): Observable<CurrentNodes> { const currentNodes = combineLatest( navigationViews.map(views => this.computeUrlToNavNodesMap(views)), this.location.currentPath, (navMap, url) => { const urlKey = url.startsWith('api/') ? 'api' : url; return navMap.get(urlKey) || { '' : { view: '', url: urlKey, nodes: [] }}; }) .publishReplay(1); currentNodes.connect(); return currentNodes; }
private getContributors() { const contributors = this.http.get(contributorsPath) .map(res => res.json()) // Create group map .map(contribs => { const contribMap = new Map<string, Contributor[]>(); Object.keys(contribs).forEach(key => { const contributor = contribs[key]; const group = contributor.group; const contribGroup = contribMap[group]; if (contribGroup) { contribGroup.push(contributor); } else { contribMap[group] = [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.connect(); return contributors; }
private getContributors() { const contributors = this.http.get(contributorsPath) .map(res => res.json()) .map(contribs => { const contribGroups = new Map<string, Contributor[]>(); Object.keys(contribs).forEach(key => { const contributor = contribs[key]; const group = contributor.group; const contribGroup = contribGroups[group]; if (contribGroup) { contribGroup.push(contributor); } else { contribGroups[group] = [contributor]; } }); return contribGroups; }) .publishLast(); contributors.connect(); return contributors; }
private getNavigationViews(navigationInfo: Observable<NavigationResponse>): Observable<NavigationViews> { const navigationViews = navigationInfo.map(response => unpluck(response, '__versionInfo')).publishReplay(1); navigationViews.connect(); return navigationViews; }