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

example of how to use with ngrx v4 and effects? #18

Closed
pjmagee opened this issue Jul 25, 2017 · 4 comments
Closed

example of how to use with ngrx v4 and effects? #18

pjmagee opened this issue Jul 25, 2017 · 4 comments
Labels

Comments

@pjmagee
Copy link

pjmagee commented Jul 25, 2017

I'm submitting a ... (check one with "x")

[ ] bug report => check the README and search github for a similar issue or PR before submitting
[X] support request => check the README and search github for a similar issue or PR before submitting
[] feature request

I'm currently using ngrx and have migrated to v4 which is inline with Angular4 versioning (they want to make this the standard way of developing angular4 apps with the ngrx platform). Previously I was able to get my configuration bootstrapped prior to the ngrx effects being loaded immediatley but now in the ngrx v4 the effects seem to be loaded instantly and I'm not sure how I can now bootstrap my configuration. Because my ngrx effects are being injected with the config service and now the values are undefined because they are instantiated because the config is bootstrapped. This is quite a major breaking change from the ngrx side, however nobody has responded and I'm kind of looking at this repo with your knowledge to see if maybe you might have some working examples with applications that will use the ngrx platform.

@fulls1z3 fulls1z3 self-assigned this Aug 2, 2017
@fulls1z3 fulls1z3 changed the title Example of how to use with ngrx v4 and Effects? [question] example of how to use with ngrx v4 and Effects? Aug 2, 2017
@fulls1z3 fulls1z3 changed the title [question] example of how to use with ngrx v4 and Effects? [question] example of how to use with ngrx v4 and effects? Aug 2, 2017
@fulls1z3
Copy link
Owner

fulls1z3 commented Aug 2, 2017

@pjmagee I think I understood what you meant. It seems like @ngrx began to use APP_INITIALIZER to resolve the effects before the app gets bootstrapped - as @ngx-config does. However, there's no interface which allows to prioritize the execution of functions supplied by the APP_INITIALIZER.

I would recommend to change the order of imports (at the app.module.ts, in NgModule section for instance) and see those values are still undefined or not.

Also try to update this post after you make some tries, and meanwhile I'll see what can I do for this.

@fulls1z3 fulls1z3 closed this as completed Aug 2, 2017
@fulls1z3 fulls1z3 reopened this Aug 3, 2017
@fulls1z3
Copy link
Owner

fulls1z3 commented Aug 3, 2017

@pjmagee I chosen one of my projects as a victim and upgraded the ngrx to v4.0. It took a few hours, but got it running somehow. I tried to get the state of an object which comes from ngx-config (language) and resulted OK.

Well, resulted OK is such a very generic expression - I'm aware of that.

Is it possible for you to post the repro steps (github, plunkr, etc) so that I can try to have a look. Well, it might be a commercial project, or could take much time to elaborate even a smaller version.

I'll try to integrate ngrx v4.x to ng-seed/universal on the upcoming weeks (might be even closer, but don't want to cite a very precise and optimistic time) and maybe it could give you some clue.

@pjmagee
Copy link
Author

pjmagee commented Aug 4, 2017

I always ensure the ConfigModule is defined first in the imports list. Then I define near the bottom my EffectsModule. It seems like I'm looking for something now called ngrxOnRunEffects ngrx/platform#174

Essentially my problem is, I have a UserEffects that has a Security Service which takes the ngx-config service. This Security service has end points required for the user to login (I use Identity Server 4) so I need external endpoints to manage authentication. So this configuration really does need to happen before ANY ngrx effects are triggered. Because my Security Service is injected into multiple Effects I have.

I'm not sure how this ngrxOnRunEffects solve my problem, because my Security service is already injected into the Effect at that point. I can try to defer calling the config service GetSettings function and see how it plays out.

No matter what I try, it just appears that ConfigService never has the keys/values set in time, even once the page has rendered. So yeah, not sure how I can do this.

class Effects {  
   constructor(securityService: SecurityService) { } 
} 

class SecurityService { 
  constructor(configService: ConfigService) { }
 
  // configService getSettings() undefined v4.0
  // configService getSettings() defined perfectly pre v4.0 using RunAfterBootstrap
} 

@NgModule({ imports [  
          ConfigModule.forRoot({   // produces my ConfigService from Http to be injected into any Service 
            provide: ConfigLoader,
            useFactory: (createConfigLoader),
            deps: [Http, [ORIGIN_URL]]
        }),
        ...,
        EffectsModule.forRoot(EFFECTS) // new ngrx v4.0 (config settings always undefined)
        // Effects.RunAfterBootstrap(Effects) // pre ngrx v4.0 (config settings worked fine)
     ]})
class AppModule {

}

@fulls1z3 fulls1z3 removed their assignment Aug 10, 2017
@fulls1z3
Copy link
Owner

@pjmagee you can have a look at ng-seed/universal, commit 6a50aac which closes fulls1z3/universal#70.

@fulls1z3 fulls1z3 changed the title [question] example of how to use with ngrx v4 and effects? example of how to use with ngrx v4 and effects? Sep 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants