Skip to content

Commit

Permalink
refactor: rename NgxMatomoRouterModule to MatomoRouterModule
Browse files Browse the repository at this point in the history
DEPRECATION: `NgxMatomoRouterModule` has been deprecated, use `MatomoRouterModule` instead
  • Loading branch information
EmmanuelRoux committed Nov 12, 2023
1 parent eb70405 commit 8795a05
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 39 deletions.
74 changes: 74 additions & 0 deletions projects/ngx-matomo-client/router/matomo-router.module.ts
@@ -0,0 +1,74 @@
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { ɵMATOMO_ROUTER_ENABLED as MATOMO_ROUTER_ENABLED } from 'ngx-matomo-client/core';
import {
MATOMO_ROUTER_CONFIGURATION,
MatomoRouterConfigurationWithInterceptors,
} from './configuration';
import { provideInterceptors } from './interceptor';
import { MatomoRouter } from './matomo-router.service';

@NgModule({
providers: [{ provide: MATOMO_ROUTER_ENABLED, useValue: true }],
})
export class MatomoRouterModule {
constructor(
private readonly router: MatomoRouter,
@Optional() @SkipSelf() parent?: MatomoRouterModule,
@Optional() @SkipSelf() parentDeprecated?: NgxMatomoRouterModule
) {
if (!parent && !parentDeprecated) {
// Do not initialize if it is already (by a parent module)
this.router.initialize();
}
}

static forRoot(
configWithInterceptors: MatomoRouterConfigurationWithInterceptors = {}
): ModuleWithProviders<MatomoRouterModule> {
// Note: not using "rest" syntax here, in order to avoid any dependency on tslib (and reduce package size)
// The only drawback of this is that MATOMO_ROUTER_CONFIGURATION will actually
// contain a reference to provided interceptors
return {
ngModule: MatomoRouterModule,
providers: [
{ provide: MATOMO_ROUTER_CONFIGURATION, useValue: configWithInterceptors },
provideInterceptors(configWithInterceptors.interceptors),
],
};
}
}

/**
* @deprecated use MatomoRouterModule instead
* @breaking-change 7.0.0
*/
@NgModule({
providers: [{ provide: MATOMO_ROUTER_ENABLED, useValue: true }],
})
export class NgxMatomoRouterModule {
constructor(
private readonly router: MatomoRouter,
@Optional() @SkipSelf() parent?: MatomoRouterModule,
@Optional() @SkipSelf() parentDeprecated?: NgxMatomoRouterModule
) {
if (!parent && !parentDeprecated) {
// Do not initialize if it is already (by a parent module)
this.router.initialize();
}
}

static forRoot(
configWithInterceptors: MatomoRouterConfigurationWithInterceptors = {}
): ModuleWithProviders<NgxMatomoRouterModule> {
// Note: not using "rest" syntax here, in order to avoid any dependency on tslib (and reduce package size)
// The only drawback of this is that MATOMO_ROUTER_CONFIGURATION will actually
// contain a reference to provided interceptors
return {
ngModule: NgxMatomoRouterModule,
providers: [
{ provide: MATOMO_ROUTER_CONFIGURATION, useValue: configWithInterceptors },
provideInterceptors(configWithInterceptors.interceptors),
],
};
}
}
38 changes: 0 additions & 38 deletions projects/ngx-matomo-client/router/ngx-matomo-router.module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion projects/ngx-matomo-client/router/public-api.ts
Expand Up @@ -3,7 +3,7 @@
*/

export { withRouter, withRouterInterceptors, withRouteData } from './providers';
export { NgxMatomoRouterModule } from './ngx-matomo-router.module';
export { MatomoRouterModule, NgxMatomoRouterModule } from './matomo-router.module';
export {
MatomoRouterConfiguration,
MATOMO_ROUTER_CONFIGURATION,
Expand Down

0 comments on commit 8795a05

Please sign in to comment.