michaelkrone / ngrx-normalizr

Managing normalized state in ngrx applications - transparently
https://michaelkrone.github.io/ngrx-normalizr/
MIT License
50 stars 17 forks source link

RemoveData & RemoveChildData not firing change #33

Open jaichandra opened 6 years ago

jaichandra commented 6 years ago

Im getting used to this library now.. Thanks for creating this. But, I see that my observables are not fired when I remove data. Not sure if Im doing anything wrong here. AddData fires my observables (this.store.select), but the same doesn't fire when I use RemoveData or RemoveChildData.

Here's what Im trying to do:

Say I have the following data:

export class User {
  id: number;
  name: string;
  tasks: Task[];
}

export class Task {
  id: number;
  name: string;
  comments: Comment[];
}

export class Comment{
  id: number;
  text: string;
}

export const userSchema = new schema.Entity('users');
export const commentSchema = new schema.Entity('comments');
export const taskSchema = new schema.Entity('tasks', { comments: [commentSchema] });

Once I use AddData, I get below normalized data

users: [
  "1": {
    id: "1",
    name: 'Example Task',
    tasks: ["2"]
  }
],
tasks: [
  "2": {
    id: "2",
    name: 'Example Task',
    comments: ["4"]
  }
],
comments: [
  "4": {
    id: "4",
    text: "My Comment",
  }
]

Now, if I want to remove a task from the data and use RemoveChildData({id: "2", taskSchema, userSchema, parentId: "1" }), I can see that it removes the task and reference from the tasks property under users. If I use RemoveData({id: "2", schema: taskSchema, removeChildren: {comments: 'comments'}}), I see that the task and the related comments are removed.

But in both cases, my this.store.select is not fired.