Skip to content

Commit

Permalink
prepare 6.0.0-alpha.11
Browse files Browse the repository at this point in the history
  • Loading branch information
sclausen committed Apr 23, 2018
1 parent ad5280a commit 7b4c3ea
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mqtt",
"version": "6.0.0-alpha.9",
"version": "6.0.0-alpha.11",
"description": "ngx mqtt client library",
"main": "bundles/ngx-mqtt.min.js",
"module": "./src/index.js",
Expand Down
21 changes: 8 additions & 13 deletions src/mqtt.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ export const MQTT_SERVICE_OPTIONS: IMqttServiceOptions = {
path: ''
};

export const MqttServiceConfig = new InjectionToken<IMqttServiceOptions>('NgxMqttServiceConfig');
export const MqttClientService = new InjectionToken<MqttClient>('NgxMqttClientService');
export function mqttServiceFactory() {
return new MqttService(MQTT_SERVICE_OPTIONS);
}

@NgModule()
export class MqttModule {
static forRoot(config: IMqttServiceOptions, client?: MqttClient): ModuleWithProviders {
static forRoot(providedService: any = {
provide: MqttService,
useFactory: mqttServiceFactory
}): ModuleWithProviders {
return {
ngModule: MqttModule,
providers: [
{
provide: MqttServiceConfig,
useValue: config
},
{
provide: MqttClientService,
useValue: client
}
]
providers: [providedService]
};
}
}
9 changes: 3 additions & 6 deletions src/mqtt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ import {
IPublishOptions
} from './mqtt.model';

import { MqttModule, MqttServiceConfig, MqttClientService } from './index';
import { MqttModule } from './index';

/**
* With an instance of MqttService, you can observe and subscribe to MQTT in multiple places, e.g. in different components,
* to only subscribe to the broker once per MQTT filter.
* It also handles proper unsubscription from the broker, if the last observable with a filter is closed.
*/
@Injectable({
providedIn: 'root',
})
export class MqttService {
/** a map of all mqtt observables by filter */
public observables: { [filter: string]: Observable<IMqttMessage> } = {};
Expand Down Expand Up @@ -63,8 +60,8 @@ export class MqttService {
* @param client an instance of IMqttClient
*/
constructor(
@Inject(MqttServiceConfig) private options: IMqttServiceOptions,
@Inject(MqttClientService) private client?: IMqttClient
private options: IMqttServiceOptions,
private client?: IMqttClient
) {
if (options.connectOnCreate !== false) {
this.connect({}, client);
Expand Down
13 changes: 0 additions & 13 deletions tests/mqtt.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { MqttService } from '../src/mqtt.service';
import { MqttModule } from '../src/mqtt.module';

describe('TestService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [MqttModule.forRoot({})]
});
});

it('should be created', inject([MqttService], (service: MqttService) => {
expect(service).toBeTruthy();
}));
});

describe('MqttService', () => {
it('is defined', () => {
Expand Down

0 comments on commit 7b4c3ea

Please sign in to comment.