ngneat/elf

unionEntities not working as expected with non-default idKey

vzsolt1981 opened this issue · 1 comments

Which @ngneat/elf-* package(s) are the source of the bug?

entities

Is this a regression?

No

Description

Based on your test unit example, if I change the "id" key of the models used to a custom one, and set it up properly, it's not working properly, objects won't be merged.

interface TodoUI {
  uuid: number;
  open: boolean;
}
interface Todo {
  uuid: number;
  name: string;
}

const todosStore = createStore(
  { name: 'todos' },
  withEntities<Todo, 'uuid'>({
    idKey: 'uuid',
  }),
  withUIEntities<TodoUI, 'uuid'>({
    idKey: 'uuid',
  })
);

todosStore.update(
  addEntities({ uuid: 1, name: 'foo' }),
  addEntities({ uuid: 1, open: true }, { ref: UIEntitiesRef })
);

todosStore.pipe(selectEntity(1, { ref: UIEntitiesRef })).subscribe((todo) => {
  console.log(todo);
});

todosStore
  .combine({
    entities: todosStore.pipe(selectAllEntities()),
    UIEntities: todosStore.pipe(selectEntities({ ref: UIEntitiesRef })),
  })
  .pipe(unionEntities())
  .subscribe(console.log);

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in

No response

Anything else?

No response

Do you want to create a pull request?

No

unionEntities('uuid')