Skip to content

Commit

Permalink
feat(router-store): Make usage of forRoot required (#1662)
Browse files Browse the repository at this point in the history
BREAKING CHANGES:

usage of forRoot is now required for StoreRouterConnectionModule

BEFORE:

@NgModule({
  providers: [
    {
      provide: _ROUTER_CONFIG,
      useValue: {},
    },
    {
      provide: ROUTER_CONFIG,
      useFactory: _createRouterConfig,
      deps: [_ROUTER_CONFIG],
    },
    {
      provide: RouterStateSerializer,
      useClass: DefaultRouterStateSerializer,
    },
  ],
})
export class StoreRouterConnectingModule {
  static forRoot<
    T extends BaseRouterStoreState = SerializedRouterStateSnapshot
  >(
    config: StoreRouterConfig<T> = {}
  ): ModuleWithProviders<StoreRouterConnectingModule> {
    return {
      ngModule: StoreRouterConnectingModule,
      providers: [
        { provide: _ROUTER_CONFIG, useValue: config },
        {
          provide: RouterStateSerializer,
          useClass: config.serializer
            ? config.serializer
            : DefaultRouterStateSerializer,
        },
      ],
    };
}

AFTER:

@NgModule()
export class StoreRouterConnectingModule {
  static forRoot<
    T extends BaseRouterStoreState = SerializedRouterStateSnapshot
  >(
    config: StoreRouterConfig<T> = {}
  ): ModuleWithProviders<StoreRouterConnectingModule> {
    return {
      ngModule: StoreRouterConnectingModule,
      providers: [
        { provide: _ROUTER_CONFIG, useValue: config },
        {
          provide: ROUTER_CONFIG,
          useFactory: _createRouterConfig,
          deps: [_ROUTER_CONFIG],
        },
        {
          provide: RouterStateSerializer,
          useClass: config.serializer
            ? config.serializer
            : DefaultRouterStateSerializer,
        },
      ],
    };
  }
  • Loading branch information
EnricoVogt committed Mar 31, 2019
1 parent 78e237c commit f6a0d1e
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions modules/router-store/src/router_store_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,15 @@ enum RouterTrigger {
* { path: '', component: SimpleCmp },
* { path: 'next', component: SimpleCmp }
* ]),
* StoreRouterConnectingModule
* StoreRouterConnectingModule.forRoot()
* ],
* bootstrap: [AppCmp]
* })
* export class AppModule {
* }
* ```
*/
@NgModule({
providers: [
{
provide: _ROUTER_CONFIG,
useValue: {},
},
{
provide: ROUTER_CONFIG,
useFactory: _createRouterConfig,
deps: [_ROUTER_CONFIG],
},
{
provide: RouterStateSerializer,
useClass: DefaultRouterStateSerializer,
},
],
})
@NgModule()
export class StoreRouterConnectingModule {
static forRoot<
T extends BaseRouterStoreState = SerializedRouterStateSnapshot
Expand All @@ -157,6 +141,11 @@ export class StoreRouterConnectingModule {
ngModule: StoreRouterConnectingModule,
providers: [
{ provide: _ROUTER_CONFIG, useValue: config },
{
provide: ROUTER_CONFIG,
useFactory: _createRouterConfig,
deps: [_ROUTER_CONFIG],
},
{
provide: RouterStateSerializer,
useClass: config.serializer
Expand Down

0 comments on commit f6a0d1e

Please sign in to comment.