This commit is contained in:
crusader 2018-05-31 22:11:23 +09:00
parent 87f68ca3f3
commit 68e0e578c7
5 changed files with 68 additions and 40 deletions

View File

@ -6,10 +6,9 @@ import { Anim } from './animation';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { Observable, of, Subscription } from 'rxjs'; import { Observable, of, Subscription } from 'rxjs';
import { DiscoveryService } from '../service/discovery.service'; import { DiscoveryService } from '../service/discovery.service';
import { DiscoveryNotify } from '../subscriber/discovery.subscriber.subject';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators'; import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { DiscoverZone, Zone, Host, Port, Service } from '@overflow/commons-typescript/model/discovery'; 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({ @Component({
selector: 'of-discovery', selector: 'of-discovery',
@ -39,9 +38,7 @@ export class DiscoveryComponent {
this.requested = true; this.requested = true;
const discovery$ = this.discoverySubscriber.subscribe(); this.discoverySubscriber.observable().pipe(
discovery$.pipe(
tap(() => { tap(() => {
this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz); this.discoveryService.discoverZone(this.selectedProbe.probe.probeKey, dz);
}), }),

View File

@ -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<DiscoveryNotify> {
}

View File

@ -14,7 +14,15 @@ import {
Port, Port,
Service, Service,
} from '@overflow/commons-typescript/model/discovery'; } 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<DiscoveryNotify> {
}
@Injectable() @Injectable()
export class DiscoverySubscriber { export class DiscoverySubscriber {
@ -23,13 +31,13 @@ export class DiscoverySubscriber {
public constructor( public constructor(
private loggerService: LoggerService, private loggerService: LoggerService,
) { ) {
this.discoverySubscriberSubject = new DiscoverySubscriberSubject(); this.discoverySubscriberSubject = null;
} }
/** public observable(): Observable<DiscoveryNotify> {
* name if (null === this.discoverySubscriberSubject) {
*/ this.discoverySubscriberSubject = new DiscoverySubscriberSubject();
public subscribe(): Observable<DiscoveryNotify> { }
return this.discoverySubscriberSubject.asObservable(); return this.discoverySubscriberSubject.asObservable();
} }

View File

@ -10,6 +10,7 @@ import { DomainMember } from '@overflow/commons-typescript/model/domain';
import { NoAuthProbeService } from '../service/noauth-probe.service'; import { NoAuthProbeService } from '../service/noauth-probe.service';
import { NoAuthProbeConnectingSelector } from '../store'; import { NoAuthProbeConnectingSelector } from '../store';
import { NoAuthProbeSubscriber, NoAuthProbeNotify } from '../subscriber/noauth-probe.subscriber';
@Component({ @Component({
selector: 'of-noauth-probe-list', selector: 'of-noauth-probe-list',
@ -21,12 +22,13 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy {
error$: Observable<any>; error$: Observable<any>;
noauthProbes: NoAuthProbe[]; noauthProbes: NoAuthProbe[];
connectingSubscription$: Subscription; // connectingSubscription$: Subscription;
constructor( constructor(
private confirmationService: ConfirmationService, private confirmationService: ConfirmationService,
private store: Store<any>, private store: Store<any>,
private noAuthProbeService: NoAuthProbeService, private noAuthProbeService: NoAuthProbeService,
private noAuthProbeSubscriber: NoAuthProbeSubscriber,
) { ) {
this.noauthProbes = []; this.noauthProbes = [];
} }
@ -54,14 +56,30 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy {
}), }),
).take(1).subscribe(); ).take(1).subscribe();
this.connectingSubscription$ = this.store.pipe( // this.connectingSubscription$ = this.store.pipe(
select(NoAuthProbeConnectingSelector.selectEntities), // select(NoAuthProbeConnectingSelector.selectEntities),
tap((entities: { [id: number]: NoAuthProbe }) => { // 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 = []; const noauthProbes = [];
this.noauthProbes.forEach(noauthProbe => { this.noauthProbes.forEach(noauthProbe => {
const t = entities[noauthProbe.id]; const n = noAuthProbeNotify.params;
if (undefined !== t) { if (noauthProbe.id === n.id) {
noauthProbes.push(t); noauthProbes.push(n);
} else { } else {
noauthProbes.push(noauthProbe); noauthProbes.push(noauthProbe);
} }
@ -100,7 +118,7 @@ export class NoAuthProbeListComponent implements OnInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.connectingSubscription$.unsubscribe(); // this.connectingSubscription$.unsubscribe();
} }

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { Observable, Subject } from 'rxjs';
import { RPCSubscriber } from '@loafer/ng-rpc'; import { RPCSubscriber } from '@loafer/ng-rpc';
import { LoggerService } from '@loafer/ng-logger'; import { LoggerService } from '@loafer/ng-logger';
@ -8,26 +9,47 @@ import { NoAuthProbe } from '@overflow/commons-typescript/model/noauth';
import * as NoAuthProbeConnectingStore from '../store/connecting'; import * as NoAuthProbeConnectingStore from '../store/connecting';
export interface NoAuthProbeNotify {
method: string;
params: NoAuthProbe;
}
export class NoAuthProbeSubscriberSubject extends Subject<NoAuthProbeNotify> {
}
@Injectable() @Injectable()
export class NoAuthProbeSubscriber { export class NoAuthProbeSubscriber {
private noAuthProbeSubscriberSubject: NoAuthProbeSubscriberSubject;
public constructor( public constructor(
private store: Store<any>,
private loggerService: LoggerService, private loggerService: LoggerService,
) { ) {
this.noAuthProbeSubscriberSubject = null;
}
public observable(): Observable<NoAuthProbeNotify> {
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'}) @RPCSubscriber({method: 'NoAuthProbeService.onConnect'})
public onConnect(noAuthProbe: NoAuthProbe): void { public onConnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe); this.loggerService.debug('NoAuthProbeService.onConnect noAuthProbe:', noAuthProbe);
this.store.dispatch(new NoAuthProbeConnectingStore.OnConnect(noAuthProbe)); this.publish('NoAuthProbeService.onConnect', noAuthProbe);
} }
@RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'}) @RPCSubscriber({method: 'NoAuthProbeService.onDisconnect'})
public onDisconnect(noAuthProbe: NoAuthProbe): void { public onDisconnect(noAuthProbe: NoAuthProbe): void {
this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe); this.loggerService.debug('NoAuthProbeService.onDisconnect noAuthProbe:', noAuthProbe);
this.store.dispatch(new NoAuthProbeConnectingStore.OnDisconnect(noAuthProbe)); this.publish('NoAuthProbeService.onDisconnect', noAuthProbe);
} }
} }