Angular 4处理删除链
Angular 4 handling chain of delete
我创建了一个大小为 3 的 ReplaySubject 并且删除链必须按顺序进行。问题是我应该在用户完成删除时重定向用户,当我订阅这个 ReplaySubject 方法时它发送 "here finish" 而仍然没有真正完成数据库中的删除。
我应该使用哪种方法以及如何处理请求链并确切知道它们何时完成。
const subject = new Rx.ReplaySubject(3 /* buffer size */);
if (allIds.length > 0) {
subject.next(this.cService.delete1(Ids1).subscribe(data => { console.log('deleted 1'); }));
subject.next(this.cService.delete2(Ids2).subscribe(data => { console.log('deleted 2'); }));
subject.next(this.cService.delete3(Ids3).subscribe(data => { console.log('deleted 3'); }));
}
return subject.map(() => { console.log('here finish'); });
抱歉,我不知道什么是 Apollo 客户端或 multi mutation。在我最后的评论中,我想告诉你做一些像
this.cService.delete1(Ids1)
.switchMap((data)=>{ //data from delete 1
console.log('delete 1');
return this.cService.delete2(Isd2).switchMap((data)=>{ //data from delete 2
console.log('delete 2');
return this.cService.delete3(Isd3);
})
}).subscribe(data=>{ //data from delete 3
console.log('delete 3');
console.log("the end")
});
我们只订阅最后一个
我创建了一个大小为 3 的 ReplaySubject 并且删除链必须按顺序进行。问题是我应该在用户完成删除时重定向用户,当我订阅这个 ReplaySubject 方法时它发送 "here finish" 而仍然没有真正完成数据库中的删除。 我应该使用哪种方法以及如何处理请求链并确切知道它们何时完成。
const subject = new Rx.ReplaySubject(3 /* buffer size */);
if (allIds.length > 0) {
subject.next(this.cService.delete1(Ids1).subscribe(data => { console.log('deleted 1'); }));
subject.next(this.cService.delete2(Ids2).subscribe(data => { console.log('deleted 2'); }));
subject.next(this.cService.delete3(Ids3).subscribe(data => { console.log('deleted 3'); }));
}
return subject.map(() => { console.log('here finish'); });
抱歉,我不知道什么是 Apollo 客户端或 multi mutation。在我最后的评论中,我想告诉你做一些像
this.cService.delete1(Ids1)
.switchMap((data)=>{ //data from delete 1
console.log('delete 1');
return this.cService.delete2(Isd2).switchMap((data)=>{ //data from delete 2
console.log('delete 2');
return this.cService.delete3(Isd3);
})
}).subscribe(data=>{ //data from delete 3
console.log('delete 3');
console.log("the end")
});
我们只订阅最后一个