Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setEntities([]) will not update the store #112

Closed
ogix opened this issue Jan 6, 2022 · 1 comment
Closed

setEntities([]) will not update the store #112

ogix opened this issue Jan 6, 2022 · 1 comment

Comments

@ogix
Copy link

ogix commented Jan 6, 2022

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

entities

Is this a regression?

No

Description

I would expect that setEntities([]) would delete entities as deleteAllEntities() does. Now it seems it has no effect.
I see that this is done intentionally:

if (!entities.length) return state;

What is the reason for that?

Example:

interface Todo {
  id: number;
  label: string;
}

const { state, config } = createState(withEntities<Todo>());

const todosStore = new Store({ name: 'todos', state, config });

todosStore.pipe(selectAll()).subscribe((todos) => {
  console.log(todos);
});

todosStore.update(
  setEntities([
    { id: 1, label: 'one ' },
    { id: 2, label: 'two' },
  ])
);

todosStore.update(
  setEntities([]) // this has no effect and nothing is written to console
);

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?

Yes

@ogix
Copy link
Author

ogix commented Jan 6, 2022

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant