@ ngrx / entities适配器-删除实体并使用此类更改更新相对实体

时间:2020-08-28 11:22:18

标签: angular ngrx ngrx-entity

@ nfrx / entity适配器是否具有这种功能? 假设我有2个实体:用户和帖子:

users = {
  'id1': {
   id: id1,
   name: user1,
   posts: [1, 2, 3]
 }  
}

posts = {
  1: {
    id: 1,
    userId: id1
  },
  2: {
    id: 2,
    userId: id1
  },
  3: {
    id: 3,
    userId: id1
  }
}

当我删除帖子时:

adaptor.removeOne(action.payload.id, state)

但是此行仅从帖子中删除实体,但已删除帖子的ID保留在user.posts数组中

是否可以根据帖子实体的操作来更新user.post?有一个动作吗?

现在我有两个动作:

  1. 删除帖子
  2. 从user.posts数组中删除相关的postId

0 个答案:

没有答案