<分区>
在使用 Redux(带有 ngrx-store)的 Angular 4 应用程序中,我有以下内容:
调用服务的智能组件
this.contentService.update(this.content).subscribe( data => {
//output some success message
});
调用 API 然后分派(dispatch)操作的服务
update(content: Content) {
return this.http.put(`http://someendpoint/contents.json`, { content })
.map( (updated_content: Content) => {
this.store.dispatch( { type: 'SOME_KEY', payload: updated_content } );
return updated_content;
});
}
这种方法非常有效,没问题。但我不知道这是否是正确的方法:让组件处理 API 的响应并将操作分派(dispatch)到商店会更好吗?我应该把它分开吗?优缺点都有什么?我找不到关于此的好文章。