我有一个可观察的丰富_sns$,我通过使用 concatMap 对每个发出的项目执行操作来丰富它,然后使用 toArray() 将结果组合到数组中。但是,我很好奇是否有其他方法可以在不使用 toArray() 的情况下实现相同的结果。
这是我当前的代码:
private enriched_sns$ = toObservable(this.sn_results).pipe(
concatMap((results) => results as StreamNotificationResult[]),
concatMap((notification) => {
const user_id = notification.activities[0].actor.id;
return zip(of(notification), this.read_user_data_service.readUserData(user_id));
}),
map(([notification, user]) => {
return {
notification,
user: user,
};
}),
toArray(),
);
有没有一种方法可以在可观察对象的末尾获取发出的项目数组,而无需诉诸 toArray() ?任何帮助或替代方法将不胜感激。谢谢你!