Skip to content

Commit

Permalink
fix(notifier): Fix circular dependency issues of injection tokens (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
M4R1KU authored and dominique-mueller committed Oct 18, 2019
1 parent 1bff46d commit 139d43c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { By } from '@angular/platform-browser';
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';

import { NotifierConfigToken } from '../notifier.module';
import { NotifierConfigToken } from '../notifier-token';
import { NotifierAction } from '../models/notifier-action.model';
import { NotifierConfig } from '../models/notifier-config.model';
import { NotifierQueueService } from '../services/notifier-queue.service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DebugElement, Component, ViewChild, NO_ERRORS_SCHEMA, TemplateRef } fro
import { By } from '@angular/platform-browser';
import { ComponentFixture, fakeAsync, TestBed, tick, async } from '@angular/core/testing';

import { NotifierConfigToken } from '../notifier.module';
import { NotifierConfigToken } from '../notifier-token';
import { NotifierAnimationData } from '../models/notifier-animation.model';
import { NotifierNotification } from '../models/notifier-notification.model';
import { NotifierConfig } from '../models/notifier-config.model';
Expand Down
19 changes: 19 additions & 0 deletions src/lib/src/notifier-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NotifierConfig, NotifierOptions } from './models/notifier-config.model';
import { InjectionToken } from '@angular/core';

// tslint:disable variable-name

/**
* Injection Token for notifier options
*/
export const NotifierOptionsToken: InjectionToken<NotifierOptions>
= new InjectionToken<NotifierOptions>( '[angular-notifier] Notifier Options' );

/**
* Injection Token for notifier configuration
*/
export const NotifierConfigToken: InjectionToken<NotifierConfig>
= new InjectionToken<NotifierConfig>( '[anuglar-notifier] Notifier Config' );

// tslint:enable variable-name

17 changes: 1 addition & 16 deletions src/lib/src/notifier.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ import { NotifierConfig, NotifierOptions } from './models/notifier-config.model'
import { NotifierAnimationService } from './services/notifier-animation.service';
import { NotifierQueueService } from './services/notifier-queue.service';
import { NotifierService } from './services/notifier.service';

// tslint:disable variable-name

/**
* Injection Token for notifier options
*/
export const NotifierOptionsToken: InjectionToken<NotifierOptions>
= new InjectionToken<NotifierOptions>( '[angular-notifier] Notifier Options' );

/**
* Injection Token for notifier configuration
*/
export const NotifierConfigToken: InjectionToken<NotifierConfig>
= new InjectionToken<NotifierConfig>( '[anuglar-notifier] Notifier Config' );

// tslint:enable variable-name
import { NotifierConfigToken, NotifierOptionsToken } from './notifier-token';

/**
* Factory for a notifier configuration with custom options
Expand Down
2 changes: 1 addition & 1 deletion src/lib/src/services/notifier.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, TestBed } from '@angular/core/testing';

import { NotifierConfigToken } from '../notifier.module';
import { NotifierConfigToken } from '../notifier-token';
import { NotifierConfig } from '../models/notifier-config.model';
import { NotifierNotificationOptions } from '../models/notifier-notification.model';
import { NotifierAction } from '../models/notifier-action.model';
Expand Down
4 changes: 2 additions & 2 deletions src/lib/src/services/notifier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Inject, Injectable, forwardRef } from '@angular/core';
import { NotifierConfig } from './../models/notifier-config.model';
import { NotifierNotificationOptions } from './../models/notifier-notification.model';
import { NotifierQueueService } from './notifier-queue.service';
import { NotifierConfigToken } from './../notifier.module';
import { NotifierConfigToken } from './../notifier-token';

/**
* Notifier service
Expand Down Expand Up @@ -33,7 +33,7 @@ export class NotifierService {
*/
public constructor(
notifierQueueService: NotifierQueueService,
@Inject( forwardRef( () => NotifierConfigToken ) ) config: NotifierConfig // The forwardRef is (sadly) required here
@Inject(NotifierConfigToken) config: NotifierConfig
) {
this.queueService = notifierQueueService;
this.config = config;
Expand Down

0 comments on commit 139d43c

Please sign in to comment.