0.0.2-190 • Published 5 months ago

smart.connectors v0.0.2-190

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

smart.connectors@0.0.2-181

Building

To build an compile the typescript sources to javascript use:

npm install
npm run build

publishing

First build the package than run npm publish

consuming

navigate to the folder of your consuming project and run one of next commando's.

published:

npm install smart.connectors@0.0.2-181 --save

unPublished (not recommended):

npm install PATH_TO_GENERATED_PACKAGE --save

using npm link:

In PATH_TO_GENERATED_PACKAGE:

npm link

In your project:

npm link smart.connectors@0.0.2-181

In your Angular project:

// configuring providers Structures example
import { ApiModule } from 'smart.connectors';
import { StructuresService, StructuresServiceConfiguration } from 'smart.connectors';
import { StructuresServiceConfiguration } from 'smart.connectors';
import { AuthService } from './authentication/auth.service';
import { environment } from '../../environments/environment';
import { HttpClient as AngularHttpClient } from '@angular/common/http';

export function structuresConfigurationService() {
  return (http: AngularHttpClient ,token,povToken): StructuresServiceConfiguration => {
    return new StructuresServiceConfiguration({
      httpClient: http,
      basePath: environment.structureServiceBasePath,
      SubscriberToken: token,
      POVToken: povToken
    });
  };
}
export function StructuresFactoryService() {
  return (_structuresServiceConfiguration: StructuresServiceConfiguration): StructuresService => {
    return new StructuresService(_structuresServiceConfiguration);
  };
}

@NgModule({
    imports: [ ApiModule ],
    declarations: [ AppComponent ],
    providers: [    
    {
      provide: StructuresService,
      useFactory: StructuresFactoryService(),
      deps: [StructuresServiceConfiguration]
    },
    {
      provide: StructuresServiceConfiguration,
      useFactory: structuresConfigurationService(),
      deps: [AuthService]
    },
     {
      provide: StructuresAdmMediator,
      useFactory: StructuresAdmMediatorFactory(),
      deps: [StructuresService]
    }
    ],
    bootstrap: [ AppComponent ]
})
export class AppModule {}

Service Implementation

export function factory() { return (_server: StructuresService): Mediator => { return new Mediator(_server); }; }

@Injectable({ providedIn: 'root' }) export default class Mediator { constructor(_server: StructuresService) { this.server = _server; } private server: StructuresService;

getPerspectives(): Observable<Perspective[]> { return this.server.getAllPerspectives(); }

}

Using @angular/cli

First extend your src/environments/*.ts files by adding the corresponding base path:

export const environment = {
  production: false,
  API_BASE_PATH: 'http://127.0.0.1:8080'
};

In the src/app/app.module.ts:

import { BASE_PATH } from 'smart.connectors';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [ ],
  providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
  bootstrap: [ AppComponent ]
})
export class AppModule { }