From 87f68ca3f3d2fd87acad55ccd9a9410003a86938 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 31 May 2018 21:44:11 +0900 Subject: [PATCH] ing --- .../component/discovery.component.ts | 11 ++++-- .../discovery/service/discovery.service.ts | 35 +++---------------- .../discovery.subscriber.subject.ts} | 2 +- .../subscriber/discovery.subscriber.ts | 27 +++++++------- 4 files changed, 28 insertions(+), 47 deletions(-) rename @overflow/discovery/{core/discovery-subject.ts => subscriber/discovery.subscriber.subject.ts} (76%) diff --git a/@overflow/discovery/component/discovery.component.ts b/@overflow/discovery/component/discovery.component.ts index 0ab96a3..521cbab 100644 --- a/@overflow/discovery/component/discovery.component.ts +++ b/@overflow/discovery/component/discovery.component.ts @@ -6,9 +6,10 @@ import { Anim } from './animation'; import { Store, select } from '@ngrx/store'; import { Observable, of, Subscription } from 'rxjs'; import { DiscoveryService } from '../service/discovery.service'; -import { DiscoveryNotify } from '../core/discovery-subject'; +import { DiscoveryNotify } from '../subscriber/discovery.subscriber.subject'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; +import { DiscoverySubscriber } from '../subscriber/discovery.subscriber'; @Component({ selector: 'of-discovery', @@ -28,6 +29,7 @@ export class DiscoveryComponent { constructor( private discoveryService: DiscoveryService, + private discoverySubscriber: DiscoverySubscriber, private store: Store ) { } @@ -37,7 +39,12 @@ export class DiscoveryComponent { this.requested = true; - this.discoverySubscription = this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz).pipe( + const discovery$ = this.discoverySubscriber.subscribe(); + + discovery$.pipe( + tap(() => { + this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz); + }), map((discoveryNotify: DiscoveryNotify) => { switch (discoveryNotify.method) { case 'DiscoveryService.discoveryStart': { diff --git a/@overflow/discovery/service/discovery.service.ts b/@overflow/discovery/service/discovery.service.ts index 707eac9..856fb4c 100644 --- a/@overflow/discovery/service/discovery.service.ts +++ b/@overflow/discovery/service/discovery.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; -import { RPCService, RPCSubscribeService } from '@loafer/ng-rpc'; +import { RPCService } from '@loafer/ng-rpc'; import { DiscoverZone as MDDiscoverZone, DiscoverHost as MDDiscoverHost, @@ -13,50 +13,25 @@ import { Service, } from '@overflow/commons-typescript/model/discovery'; -import { DiscoverySubject, DiscoveryNotify } from '../core/discovery-subject'; -import * as DiscoverStore from '../store/discover'; -import { DiscoverySubscriber } from '../subscriber/discovery.subscriber'; - @Injectable() export class DiscoveryService { public constructor( - private discoverySubscriber: DiscoverySubscriber, private rpcService: RPCService, ) { } - public discoverZone(probeID: string, discoverZone: MDDiscoverZone): Observable { - const discoverySubject: DiscoverySubject = new DiscoverySubject(); - this.discoverySubscriber.setDiscoverySubject(discoverySubject); - + public discoverZone(probeID: string, discoverZone: MDDiscoverZone): void { this.rpcService.send('DiscoveryService.discoverZone', probeID, discoverZone); - - return discoverySubject; } - public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): Observable { - const discoverySubject: DiscoverySubject = new DiscoverySubject(); - this.discoverySubscriber.setDiscoverySubject(discoverySubject); - + public discoverHost(probeID: string, zone: Zone, discoverHost: MDDiscoverHost): void { this.rpcService.send('DiscoveryService.discoverHost', probeID, zone, discoverHost); - - return discoverySubject; } - public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): Observable { - const discoverySubject: DiscoverySubject = new DiscoverySubject(); - this.discoverySubscriber.setDiscoverySubject(discoverySubject); - + public discoverPort(probeID: string, host: Host, discoverPort: MDDiscoverPort): void { this.rpcService.send('DiscoveryService.discoverPort', probeID, host, discoverPort); - - return discoverySubject; } - public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): Observable { - const discoverySubject: DiscoverySubject = new DiscoverySubject(); - this.discoverySubscriber.setDiscoverySubject(discoverySubject); - + public discoverService(probeID: string, port: Port, discoverService: MDDiscoverService): void { this.rpcService.send('DiscoveryService.discoverService', probeID, port, discoverService); - - return discoverySubject; } } diff --git a/@overflow/discovery/core/discovery-subject.ts b/@overflow/discovery/subscriber/discovery.subscriber.subject.ts similarity index 76% rename from @overflow/discovery/core/discovery-subject.ts rename to @overflow/discovery/subscriber/discovery.subscriber.subject.ts index b9c0c37..f17a169 100644 --- a/@overflow/discovery/core/discovery-subject.ts +++ b/@overflow/discovery/subscriber/discovery.subscriber.subject.ts @@ -12,6 +12,6 @@ export interface DiscoveryNotify { params: Date | Zone | Host | Port | Service; } -export class DiscoverySubject extends Subject { +export class DiscoverySubscriberSubject extends Subject { } diff --git a/@overflow/discovery/subscriber/discovery.subscriber.ts b/@overflow/discovery/subscriber/discovery.subscriber.ts index fa59140..5e3a19c 100644 --- a/@overflow/discovery/subscriber/discovery.subscriber.ts +++ b/@overflow/discovery/subscriber/discovery.subscriber.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core'; +import { Observable, Subject } from 'rxjs'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; import { RPCSubscriber } from '@loafer/ng-rpc'; @@ -13,63 +14,61 @@ import { Port, Service, } from '@overflow/commons-typescript/model/discovery'; -import { DiscoverySubject } from '../core/discovery-subject'; +import { DiscoverySubscriberSubject, DiscoveryNotify } from './discovery.subscriber.subject'; @Injectable() export class DiscoverySubscriber { - discoverySubject: DiscoverySubject | null; + discoverySubscriberSubject: DiscoverySubscriberSubject; public constructor( private loggerService: LoggerService, ) { + this.discoverySubscriberSubject = new DiscoverySubscriberSubject(); } /** * name */ - public setDiscoverySubject(discoverySubject: DiscoverySubject) { - this.discoverySubject = discoverySubject; + public subscribe(): Observable { + return this.discoverySubscriberSubject.asObservable(); } private publish(method: string, params: any): void { - if (null !== this.discoverySubject) { - this.discoverySubject.next({method: method, params: params}); - } + this.discoverySubscriberSubject.next({ method: method, params: params }); } - @RPCSubscriber({method: 'DiscoveryService.discoveryStart'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveryStart' }) public discoveryStart(startDate: Date): void { this.loggerService.debug('DiscoverySubscriber.discoveryStart startDate:', startDate); this.publish('DiscoveryService.discoveryStart', startDate); } - @RPCSubscriber({method: 'DiscoveryService.discoveryStop'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveryStop' }) public discoveryStop(stopDate: Date): void { this.loggerService.debug('DiscoverySubscriber.discoveryStop stopDate:', stopDate); this.publish('DiscoveryService.discoveryStop', stopDate); - this.setDiscoverySubject(null); } - @RPCSubscriber({method: 'DiscoveryService.discoveredZone'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveredZone' }) public discoveredZone(zone: Zone): void { this.loggerService.debug('DiscoverySubscriber.discoveredZone zone:', zone); this.publish('DiscoveryService.discoveredZone', zone); } - @RPCSubscriber({method: 'DiscoveryService.discoveredHost'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveredHost' }) public discoveredHost(host: Host): void { this.loggerService.debug('DiscoverySubscriber.discoveredHost host:', host); this.publish('DiscoveryService.discoveredHost', host); } - @RPCSubscriber({method: 'DiscoveryService.discoveredPort'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveredPort' }) public discoveredPort(port: Port): void { this.publish('DiscoveryService.discoveredPort', port); } - @RPCSubscriber({method: 'DiscoveryService.discoveredService'}) + @RPCSubscriber({ method: 'DiscoveryService.discoveredService' }) public discoveredService(service: Service): void { this.loggerService.debug('DiscoverySubscriber.discoveredService service:', service); this.publish('DiscoveryService.discoveredService', service);