-
Notifications
You must be signed in to change notification settings - Fork 401
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
Circular dependency #632
Comments
Please, add example on stackblitz for reproduce |
Not sure if we will see the circular dependency warning on stackblitz, I also tried to do a selectSnapshot in a stackblitz ngxs https://stackblitz.com/edit/angular-ngxs-app To reproduce, if you have an app that has 2 stores, just do a selectSnapshot() from each and at build time you get the circular dependency warning. |
I was able to recreate in stackblitz but since you can't see warnings I have attached the zip file, just install and ng serve. |
This is a JavaScript/TypeScript issue. |
We are using ngxs in a very big app, with multiple stores. With our actions in one store we need an attribute from another store, so we use selectSnapshot to get it. But with the circular dependency we can only get snapshots inside of one store, because if we use selectsnapshot from the first store we use it originally in, it gives the circular dependency warning. I'm also not importing one state into the other, I'm only importing the top level store: Store in the constructor, and using this.store.selectSnapshot(otherstore.attribute). |
You import FakeAppState in app.state.ts and AppState in fake.state.ts. I still don't understand what you're trying to achieve. |
It's just a very simple re-creation to show the circular dependency. Our app is much more complex currently with 4 stores and over 100 actions, so setting up optional payloads just to get pieces of another state as work around isn't viable. So basically I am trying to see if there is a fix on your end, as this actually seems like a common function to get snapshots from other states to use in actions. Or if there is a better way to get that slice of state without the circular dependency. |
I guess this is your only option: this.store.selectSnapshot(state => state.fakeState.username);
// or
this.store.selectSnapshot('fakeState.username'); And get rid of the imports of both states. |
This seems to work, thank you. |
hate to bring up an old issue, but i am having this exact issue, but with a dynamic selector. |
@Dedme please add example for reproduce |
I'm submitting a...
Current behavior
With 2 stores, if you do a selectSnapshot in each from the other store you get a circular dependency warning.
Expected behavior
No circular dependency warning
Minimal reproduction of the problem with instructions
Create 2 stores and do a select snapshot from each
What is the motivation / use case for changing the behavior?
Environment
I understand why this is happening, but in reality there shouldn't be a warning for a circular dependency or another way to get a slice of the other stores state without creating the dependency.
The text was updated successfully, but these errors were encountered: