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

WARNING in Circular dependency detected: #2

Closed
sunger opened this issue Apr 18, 2018 · 5 comments
Closed

WARNING in Circular dependency detected: #2

sunger opened this issue Apr 18, 2018 · 5 comments
Labels
8 8 Scrum points good first issue Good for newcomers help wanted Extra attention is needed minor minor

Comments

@sunger
Copy link

sunger commented Apr 18, 2018

WARNING in Circular dependency detected:
libs\auth\src\auth.service.ts -> libs\auth\src\auth.state.ts -> libs\auth\src\auth.service.ts

WARNING in Circular dependency detected:
libs\auth\src\auth.state.ts -> libs\auth\src\auth.service.ts -> libs\auth\src\auth.state.ts

@xmlking
Copy link
Owner

xmlking commented Apr 23, 2018

@sunger thanks for informing. for now you can ignore this warning. I will see how I can avoid such circular dependency.

I may have to reference AuthState's selector as text. but it is not working at the moment.
@amcdnl is there a solution/workaround for this case?

    this.store.select(AuthState.authMode).subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

may be like this:

     this.store.select('auth.authMode').subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

@xmlking xmlking added help wanted Extra attention is needed good first issue Good for newcomers minor minor 8 8 Scrum points labels Jun 24, 2018
@eranshmil
Copy link

You can try:
@Select(AuthState) authMode$: Observable<AuthMode>;

@xmlking
Copy link
Owner

xmlking commented Jul 22, 2018

@eranshmil as long as you use/refer AuthState in AuthService you will get Circular dependency WARNING.
if you don't want to see warning, then you can try this.

  @Select('auth.authMode') authMode$: Observable<AuthMode>;

and 

    this.authMode$.subscribe(authMode => {
      console.log(`Auth Mode Changed: ${this.authMode} => ${authMode}`);
      this.authMode = authMode;
    });

with this approach, I see ngxs store fires change event twice. which I don't like :(

Console log:

Auth Mode Changed: undefined => undefined
Auth Mode Changed: undefined => ImplicitFLow

With static reference to AuthState ie. this.store.select(AuthState.authMode).subscribe(....) it only fire one time as I expected.

 Auth Mode Changed: undefined => ImplicitFLow

@eranshmil
Copy link

I'd guess that's because the auth service is being initialized before auth state.
I recommend you to move some of the logic from auth service into the state, for example:

    if (this.authMode === AuthMode.PasswordFlow) {
      // For Password Flow
      return this.ropcService.logOut();
    } else {
      // For ImplicitFlow
      this.oauthService.logOut();
    }

I don't see any reason for that to be in the service and not in an action.

@xmlking
Copy link
Owner

xmlking commented May 4, 2019

fixed.

@xmlking xmlking closed this as completed May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8 8 Scrum points good first issue Good for newcomers help wanted Extra attention is needed minor minor
Projects
None yet
Development

No branches or pull requests

3 participants