Angular 使用NGRX在API调用中更新后将项添加到状态

Angular 使用NGRX在API调用中更新后将项添加到状态,angular,ngrx,angular9,Angular,Ngrx,Angular9,我将NGRX/Entity与Angular 9一起使用,我拥有以下实体: export interface Post { id: number; content: string; title: string; tags: Tag[]; } export interface Tag { id: number; name: string; } 减速器是这样的: export interface State extends EntityState<Post>

我将NGRX/Entity与Angular 9一起使用,我拥有以下实体:

export interface Post {
  id: number;
  content: string;
  title: string;
  tags: Tag[];
} 

export interface Tag {
  id: number;
  name: string;
}
减速器是这样的:

export interface State extends EntityState<Post> { }

export const adapter: EntityAdapter<Post> = createEntityAdapter<Post>();

export const initialState: State = adapter.getInitialState();

const postReducer = createReducer(
  initialState,
  on(PostActions.updatePost, (state, { post }) => {
    return adapter.updateOne(post, state)
  })
我的想法是产生一种效果,接受一个PostUpdateModel并将其发送到API,API返回一个Post,然后调用updateOne

这有意义吗?我该怎么做?

是的,这很有意义。 查看它的另一种方法是将整个Post对象发送到effect,并让effect将其映射到request对象


此外,目前每个帖子都存储了一组标签。在更复杂的场景中,这可能更难维护,因为此数据是重复的,如果您有此数据,则可以提供解决此问题的解决方案。

我一直在阅读有关规范化状态和规范化器的内容。。。通过使用这种方法,我不应该使用全局状态而不是每页的状态吗?想象一下,我有两个页面,一个页面显示带有标签的最新帖子,另一个页面显示没有标签的热门帖子。但两者都将使用全球状态,即POST和Tags实体以正常状态存在。或者我应该保持每页有一个特定的状态吗?您将有一个全局状态和多个选择器组成页面的viewmodel。
export interface PostUpdateModel {
  id: number;
  content: string;
  title: string;
  tagsIds: number[];
}