I have an observable categories
that gets a list of all categories from an api with url and name
{url: "http://test.com/1", name: "test1"}
{url: "http://test.com/2", name: "test2"}
and I have a list of selectedkeywords
with a name and a category (with url and name). I made a new map because i need to reorder them by category so I have a list of keywords that belong to a category like this:
this.keywordsSelected$ = this.keywords$.map((keywords) => {
return keywords.reduce((acc, keyword) => {
if (!acc.has(keyword.category.url)) {
acc.set(keyword.category.url, []);
}
acc.get(keyword.category.url).push(keyword);
return acc;
}, new Map<string, Keyword[]>());
});
So I get a map with an url as key and the keywords in the array:
Map(2) {"http://test.com/2" => Array(5)}
The first list categories has a specific order I need to retain. Thats why i want to filter that list by the second list so i show only the categories that are in the 'selecetedkeywords' list. Something like this:
categories.filter(cat => cat.url === selectedkeyword.key
I am a bit new with reactive programming so obviously I am missing something but maybe someone can give me a push in the right direction ?
categories
andselectedkeywords
:). – Patryk BrejdakcombineLatest
,withLatestFrom
orforkJoin
could be what you're looking for. – martin