salesforce / akita

🚀 State Management Tailored-Made for JS Applications
https://salesforce.github.io/akita/
Apache License 2.0
3.7k stars 342 forks source link

Loading state is set to `false` unexpectedly. #1054

Open FunnyGhost opened 1 year ago

FunnyGhost commented 1 year ago

Is this a regression?

No

Description

In an application, I want to set the loading state to true, do some operations, some store updates, wait for some network requests, and after all is done, set loading to false. However, the moment I do a regular update to the store, the loading state is set back to false, even though I did not set it.

In the provided example, you can see that I only use setLoading(false) in the constructor of the service. In the TodosService on line 32, I set loading to true, but never set it to false. However, in the UI(and in the console log) you can see that the loading state is set to false somehow. If I move the delay(2000) on line 32, you'll see that the loading state is set to false after 2 seconds. This coincides with the store update(even though I'm not specifically telling it to update the loading state).

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/akita-todos-app-3behcu?file=src/app/todos/state/todos.service.ts

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

Den-dp commented 1 year ago

You can try

tap((todo) => this.todosStore.add(todo, { loading: true })),