mergeAll объединяет наблюдаемую из наблюдаемых.
Вы хотите
cards: Observable<PlanCard[]> = plans.pipe(
map(plans => plans.filter(plan => plan.is_active)), // An array comes down the pipe, you don't want to filter out the arrays but the elements in the array
map(plans => plans.map(plan => new PlanCard(plan, 1, 1))), // An array of active plans can be mapped into an array of PlanCards
reduce((results, plans) => [...results, ...plans], []) // Reduce all the arrays into a single array
);
Вы можете использовать сканирование вместо уменьшения, если вы хотите, чтобы аккумулятор сокращения уменьшался по трубе каждый раз, когдановый массив рушится, уменьшайте только пожары после того, как все массивы спустятся по трубе.
Обычно я не использую фильтр, за которым следует карта, но легче увидеть, что происходит, я обычно делал быэто за один шаг с уменьшением,
plans => plans.reduce((results, plan) => plan.is_active ? [...results, new PlanCard(plan, 1, 1)] : results, [])
То же, что фильтр, за которым следует карта, но делает это за одну итерацию вместо двух.
Это может быть довольно запутаннымкогда у вас есть наблюдаемые массивы, вам нужно подумать, какие функции вы хотите применить к наблюдаемой, а какие - к массиву, который идет по трубе.
const { from } = rxjs;
const { map, reduce } = rxjs.operators;
const plans = from([
[{id: 1, is_active: true}, {id: 2, is_active: false}, {id: 3, is_active: true}, {id: 4, is_active: true}],
[{id: 5, is_active: true}, {id: 6, is_active: true}],
[{id: 7, is_active: false}, {id: 8, is_active: true}, {id: 9, is_active: true}],
[{id: 10, is_active: true}, {id: 11, is_active: false}, {id: 12, is_active: true}, {id: 13, is_active: false}],
]);
function PlanCard(plan) {
this.id = plan.id;
}
plans.pipe(
map(plans => plans.reduce((results, plan) => plan.is_active ? [...results, new PlanCard(plan, 1, 1)] : results, [])),
reduce((results, plans) => [...results, ...plans], [])
).subscribe(results => { console.log(results); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.3.3/rxjs.umd.min.js"></script>