From 68e0e578c7ec2d1d569173ae3a5b8a24ca455cf8 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 31 May 2018 22:11:23 +0900 Subject: [PATCH] ing --- .../component/discovery.component.ts | 7 ++-- .../discovery.subscriber.subject.ts | 17 ---------- .../subscriber/discovery.subscriber.ts | 20 +++++++---- .../component/noauth-probe-list.component.ts | 34 ++++++++++++++----- .../subscriber/noauth-probe.subscriber.ts | 30 +++++++++++++--- 5 files changed, 68 insertions(+), 40 deletions(-) delete mode 100644 @overflow/discovery/subscriber/discovery.subscriber.subject.ts diff --git a/@overflow/discovery/component/discovery.component.ts b/@overflow/discovery/component/discovery.component.ts index 521cbab..13d9dc4 100644 --- a/@overflow/discovery/component/discovery.component.ts +++ b/@overflow/discovery/component/discovery.component.ts @@ -6,10 +6,9 @@ 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 '../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'; +import { DiscoverySubscriber, DiscoveryNotify } from '../subscriber/discovery.subscriber'; @Component({ selector: 'of-discovery', @@ -39,9 +38,7 @@ export class DiscoveryComponent { this.requested = true; - const discovery$ = this.discoverySubscriber.subscribe(); - - discovery$.pipe( + this.discoverySubscriber.observable().pipe( tap(() => { this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz); }), diff --git a/@overflow/discovery/subscriber/discovery.subscriber.subject.ts b/@overflow/discovery/subscriber/discovery.subscriber.subject.ts deleted file mode 100644 index f17a169..0000000 --- a/@overflow/discovery/subscriber/discovery.subscriber.subject.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Subject } from 'rxjs'; - -import { - Zone, - Host, - Port, - Service, -} from '@overflow/commons-typescript/model/discovery'; - -export interface DiscoveryNotify { - method: string; - params: Date | Zone | Host | Port | Service; -} - -export class DiscoverySubscriberSubject extends Subject { - -} diff --git a/@overflow/discovery/subscriber/discovery.subscriber.ts b/@overflow/discovery/subscriber/discovery.subscriber.ts index 5e3a19c..c4157e7 100644 --- a/@overflow/discovery/subscriber/discovery.subscriber.ts +++ b/@overflow/discovery/subscriber/discovery.subscriber.ts @@ -14,7 +14,15 @@ import { Port, Service, } from '@overflow/commons-typescript/model/discovery'; -import { DiscoverySubscriberSubject, DiscoveryNotify } from './discovery.subscriber.subject'; + +export interface DiscoveryNotify { + method: string; + params: Date | Zone | Host | Port | Service; +} + +export class DiscoverySubscriberSubject extends Subject { + +} @Injectable() export class DiscoverySubscriber { @@ -23,13 +31,13 @@ export class DiscoverySubscriber { public constructor( private loggerService: LoggerService, ) { - this.discoverySubscriberSubject = new DiscoverySubscriberSubject(); + this.discoverySubscriberSubject = null; } - /** - * name - */ - public subscribe(): Observable { + public observable(): Observable { + if (null === this.discoverySubscriberSubject) { + this.discoverySubscriberSubject = new DiscoverySubscriberSubject(); + } return this.discoverySubscriberSubject.asObservable(); } diff --git a/@overflow/noauth-probe/component/noauth-probe-list.component.ts b/@overflow/noauth-probe/component/noauth-probe-list.component.ts index 825c405..87c9682 100644 --- a/@overflow/noauth-probe/component/noauth-probe-list.component.ts +++ b/@overflow/noauth-probe/component/noauth-probe-list.component.ts @@ -10,6 +10,7 @@ import { DomainMember } from '@overflow/commons-typescript/model/domain'; import { NoAuthProbeService } from '../service/noauth-probe.service'; import { NoAuthProbeConnectingSelector } from '../store'; +import { NoAuthProbeSubscriber, NoAuthProbeNotify } from '../subscriber/noauth-probe.subscriber'; @Component({ selector: 'of-noauth-probe-list', @@ -21,12 +22,13 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy { error$: Observable; noauthProbes: NoAuthProbe[]; - connectingSubscription$: Subscription; + // connectingSubscription$: Subscription; constructor( private confirmationService: ConfirmationService, private store: Store, private noAuthProbeService: NoAuthProbeService, + private noAuthProbeSubscriber: NoAuthProbeSubscriber, ) { this.noauthProbes = []; } @@ -54,14 +56,30 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy { }), ).take(1).subscribe(); - this.connectingSubscription$ = this.store.pipe( - select(NoAuthProbeConnectingSelector.selectEntities), - tap((entities: { [id: number]: NoAuthProbe }) => { + // this.connectingSubscription$ = this.store.pipe( + // select(NoAuthProbeConnectingSelector.selectEntities), + // tap((entities: { [id: number]: NoAuthProbe }) => { + // const noauthProbes = []; + // this.noauthProbes.forEach(noauthProbe => { + // const t = entities[noauthProbe.id]; + // if (undefined !== t) { + // noauthProbes.push(t); + // } else { + // noauthProbes.push(noauthProbe); + // } + // }); + + // this.setNoauthProbes(noauthProbes); + // } + // ), + // ).subscribe(); + this.noAuthProbeSubscriber.observable().pipe( + tap((noAuthProbeNotify: NoAuthProbeNotify) => { const noauthProbes = []; this.noauthProbes.forEach(noauthProbe => { - const t = entities[noauthProbe.id]; - if (undefined !== t) { - noauthProbes.push(t); + const n = noAuthProbeNotify.params; + if (noauthProbe.id === n.id) { + noauthProbes.push(n); } else { noauthProbes.push(noauthProbe); } @@ -100,7 +118,7 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { - this.connectingSubscription$.unsubscribe(); + // this.connectingSubscription$.unsubscribe(); } diff --git a/@overflow/noauth-probe/subscriber/noauth-probe.subscriber.ts b/@overflow/noauth-probe/subscriber/noauth-probe.subscriber.ts index bf6358c..7e299b8 100644 --- a/@overflow/noauth-probe/subscriber/noauth-probe.subscriber.ts +++ b/@overflow/noauth-probe/subscriber/noauth-probe.subscriber.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; -import { Store, select } from '@ngrx/store'; + +import { Observable, Subject } from 'rxjs'; import { RPCSubscriber } from '@loafer/ng-rpc'; import { LoggerService } from '@loafer/ng-logger'; @@ -8,26 +9,47 @@ import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth'; import * as NoAuthProbeConnectingStore from '../store/connecting'; +export interface NoAuthProbeNotify { + method: string; + params: NoAuthProbe; +} + +export class NoAuthProbeSubscriberSubject extends Subject { + +} + @Injectable() export class NoAuthProbeSubscriber { + private noAuthProbeSubscriberSubject: NoAuthProbeSubscriberSubject; public constructor( - private store: Store, private loggerService: LoggerService, ) { + this.noAuthProbeSubscriberSubject = null; + } + + public observable(): Observable { + if (null === this.noAuthProbeSubscriberSubject) { + this.noAuthProbeSubscriberSubject = new NoAuthProbeSubscriberSubject(); + } + return this.noAuthProbeSubscriberSubject.asObservable(); + } + + private publish(method: string, params: any): void { + this.noAuthProbeSubscriberSubject.next({ method: method, params: params }); } @RPCSubscriber({method: 'NoAuthProbeService.onConnect'}) public onConnect(noAuthProbe: NoAuthProbe): void { this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe); - this.store.dispatch(new NoAuthProbeConnectingStore.OnConnect(noAuthProbe)); + this.publish('NoAuthProbeService.onConnect', noAuthProbe); } @RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'}) public onDisconnect(noAuthProbe: NoAuthProbe): void { this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe); - this.store.dispatch(new NoAuthProbeConnectingStore.OnDisconnect(noAuthProbe)); + this.publish('NoAuthProbeService.onDisconnect', noAuthProbe); } }