unsubscribe

This commit is contained in:
insanity 2018-04-29 20:56:46 +09:00
parent 1d03044dd7
commit b61f203500
6 changed files with 64 additions and 19 deletions

View File

@ -1,4 +1,4 @@
import { Component, Injectable, OnInit, AfterContentInit, Output, EventEmitter } from '@angular/core'; import { Component, Injectable, OnInit, AfterContentInit, Output, EventEmitter, OnDestroy } from '@angular/core';
import * as ListStore from 'packages/notification/store/list'; import * as ListStore from 'packages/notification/store/list';
import * as DetailStore from 'packages/notification/store/detail'; import * as DetailStore from 'packages/notification/store/detail';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
@ -10,14 +10,16 @@ import { Member } from 'packages/member/model';
import { PagesComponent } from 'app/pages/pages.component'; import { PagesComponent } from 'app/pages/pages.component';
import { Notification } from 'packages/notification/model'; import { Notification } from 'packages/notification/model';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'of-notification-menu', selector: 'of-notification-menu',
templateUrl: './app.notification.component.html' templateUrl: './app.notification.component.html'
}) })
export class AppNotificationComponent implements OnInit, AfterContentInit { export class AppNotificationComponent implements OnInit, AfterContentInit, OnDestroy {
notificationSubscription$: Subscription;
notification$ = this.listStore.pipe(select(ReadAllByMemberSelector.select('page'))); notification$ = this.listStore.pipe(select(ReadAllByMemberSelector.select('page')));
notifications: Notification[]; notifications: Notification[];
@ -32,7 +34,7 @@ export class AppNotificationComponent implements OnInit, AfterContentInit {
} }
ngOnInit() { ngOnInit() {
this.notification$.subscribe( this.notificationSubscription$ = this.notification$.subscribe(
(page: Page) => { (page: Page) => {
if (page !== null) { if (page !== null) {
this.notifications = page.content; this.notifications = page.content;
@ -62,6 +64,12 @@ export class AppNotificationComponent implements OnInit, AfterContentInit {
); );
} }
ngOnDestroy() {
if (this.notificationSubscription$) {
this.notificationSubscription$.unsubscribe();
}
}
getUnconfirmedCount() { getUnconfirmedCount() {
if (this.notifications === null || this.notifications.length === 0) { if (this.notifications === null || this.notifications.length === 0) {
return; return;

View File

@ -1,5 +1,5 @@
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks'; import { AfterContentInit, OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { AuthSelector } from 'packages/member/store'; import { AuthSelector } from 'packages/member/store';
@ -10,6 +10,7 @@ import { NoAuthProbeSelector } from '../../store';
import { NoAuthProbe } from '../../model'; import { NoAuthProbe } from '../../model';
import { ConfirmationService, Message } from 'primeng/primeng'; import { ConfirmationService, Message } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice'; import { MessageService } from 'primeng/components/common/messageservice';
import { Subscription } from 'rxjs/Subscription';
class NoauthProbeDesc { class NoauthProbeDesc {
host: { host: {
@ -41,7 +42,8 @@ class NoauthProbeResult {
templateUrl: './list.component.html', templateUrl: './list.component.html',
providers: [ConfirmationService, MessageService] providers: [ConfirmationService, MessageService]
}) })
export class ListComponent implements OnInit, AfterContentInit { export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
noAuthProbesSubscription$: Subscription;
noAuthProbes$ = this.store.pipe(select(NoAuthProbeSelector.select('noAuthProbes'))); noAuthProbes$ = this.store.pipe(select(NoAuthProbeSelector.select('noAuthProbes')));
noauthProbes: NoauthProbeResult[]; noauthProbes: NoauthProbeResult[];
msgs: Message[]; msgs: Message[];
@ -56,7 +58,7 @@ export class ListComponent implements OnInit, AfterContentInit {
} }
ngOnInit() { ngOnInit() {
this.noAuthProbes$.subscribe( this.noAuthProbesSubscription$ = this.noAuthProbes$.subscribe(
(result: NoAuthProbe[]) => { (result: NoAuthProbe[]) => {
if (result) { if (result) {
this.arrangeData(result); this.arrangeData(result);
@ -76,6 +78,10 @@ export class ListComponent implements OnInit, AfterContentInit {
); );
} }
ngOnDestroy() {
this.noAuthProbesSubscription$.unsubscribe();
}
arrangeData(list) { arrangeData(list) {
if (!list || list.length === 0) { if (!list || list.length === 0) {
return; return;

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Input, ViewChild, AfterContentInit } from '@angular/core'; import { Component, OnInit, Input, ViewChild, AfterContentInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { RPCClientError } from '@loafer/ng-rpc/protocol';
@ -9,13 +9,15 @@ import { ReadAllByMemberSelector, ReadSelector } from '../../store';
import { AuthSelector } from 'packages/member/store'; import { AuthSelector } from 'packages/member/store';
import { Member } from '../../../member/model'; import { Member } from '../../../member/model';
import { PageParams, Page } from 'app/commons/model'; import { PageParams, Page } from 'app/commons/model';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'of-notification', selector: 'of-notification',
templateUrl: './notification.component.html', templateUrl: './notification.component.html',
}) })
export class NotificationComponent implements OnInit, AfterContentInit { export class NotificationComponent implements OnInit, AfterContentInit, OnDestroy {
notificationSubscription$: Subscription;
notification$ = this.listStore.pipe(select(ReadAllByMemberSelector.select('page'))); notification$ = this.listStore.pipe(select(ReadAllByMemberSelector.select('page')));
notifications: Notification[]; notifications: Notification[];
readSuccess$ = this.detailStore.pipe(select(ReadSelector.select('notification'))); readSuccess$ = this.detailStore.pipe(select(ReadSelector.select('notification')));
@ -31,7 +33,7 @@ export class NotificationComponent implements OnInit, AfterContentInit {
) { } ) { }
ngOnInit() { ngOnInit() {
this.notification$.subscribe( this.notificationSubscription$ = this.notification$.subscribe(
(page: Page) => { (page: Page) => {
if (page !== null) { if (page !== null) {
console.log(page); console.log(page);
@ -60,6 +62,12 @@ export class NotificationComponent implements OnInit, AfterContentInit {
this.getNotifications(this.currPage); this.getNotifications(this.currPage);
} }
ngOnDestroy() {
if (this.notificationSubscription$) {
this.notificationSubscription$.unsubscribe();
}
}
// updateData(noti: Notification) { // updateData(noti: Notification) {
// for (let i = 0; i < this.notifications.length; i++) { // for (let i = 0; i < this.notifications.length; i++) {
// const exist = this.notifications[i]; // const exist = this.notifications[i];

View File

@ -1,4 +1,4 @@
import { Component, OnInit, Inject, AfterContentInit } from '@angular/core'; import { Component, OnInit, Inject, AfterContentInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { ConfirmationService } from 'primeng/primeng'; import { ConfirmationService } from 'primeng/primeng';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
@ -6,14 +6,16 @@ import { RPCClientError } from '@loafer/ng-rpc/protocol';
import * as DetailStore from '../../store/detail'; import * as DetailStore from '../../store/detail';
import { sensorSelector } from '../../store'; import { sensorSelector } from '../../store';
import { Sensor } from '../../model'; import { Sensor } from '../../model';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'of-sensor-detail', selector: 'of-sensor-detail',
templateUrl: './detail.component.html', templateUrl: './detail.component.html',
providers: [ConfirmationService] providers: [ConfirmationService]
}) })
export class DetailComponent implements OnInit, AfterContentInit { export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
sensorSubscription$: Subscription;
sensor$ = this.detailStore.pipe(select(sensorSelector.select('sensor'))); sensor$ = this.detailStore.pipe(select(sensorSelector.select('sensor')));
sensor: Sensor; sensor: Sensor;
@ -25,7 +27,7 @@ export class DetailComponent implements OnInit, AfterContentInit {
) { } ) { }
ngOnInit() { ngOnInit() {
this.sensor$.subscribe( this.sensorSubscription$ = this.sensor$.subscribe(
(sensor: Sensor) => { (sensor: Sensor) => {
console.log(sensor); console.log(sensor);
this.sensor = sensor; this.sensor = sensor;
@ -45,6 +47,12 @@ export class DetailComponent implements OnInit, AfterContentInit {
); );
} }
ngOnDestroy() {
if (this.sensorSubscription$) {
this.sensorSubscription$.unsubscribe();
}
}
onStartOrStop() { } onStartOrStop() { }
onEdit() { } onEdit() { }

View File

@ -1,4 +1,4 @@
import { Component, OnInit, AfterViewInit, ViewChild, AfterContentInit } from '@angular/core'; import { Component, OnInit, AfterViewInit, ViewChild, AfterContentInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { Sensor } from '../../model'; import { Sensor } from '../../model';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
@ -16,6 +16,7 @@ import { SelectItem } from 'primeng/primeng';
import { Infra } from 'packages/infra/model'; import { Infra } from 'packages/infra/model';
import * as InfraDetailStore from 'packages/infra/store/detail'; import * as InfraDetailStore from 'packages/infra/store/detail';
import { DetailSelector as InfraDetailSelector } from 'packages/infra/store'; import { DetailSelector as InfraDetailSelector } from 'packages/infra/store';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
@ -23,8 +24,9 @@ import { DetailSelector as InfraDetailSelector } from 'packages/infra/store';
templateUrl: './list.component.html', templateUrl: './list.component.html',
styleUrls: ['./list.component.scss'] styleUrls: ['./list.component.scss']
}) })
export class ListComponent implements OnInit, AfterContentInit { export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
sensorsSubscription$: Subscription;
sensorList$ = this.store.pipe(select(sensorListSelector.select('page'))); sensorList$ = this.store.pipe(select(sensorListSelector.select('page')));
PAGE_SIZE = '99999'; PAGE_SIZE = '99999';
totalLength = 0; totalLength = 0;
@ -61,7 +63,7 @@ export class ListComponent implements OnInit, AfterContentInit {
} }
}); });
this.sensorList$.subscribe( this.sensorsSubscription$ = this.sensorList$.subscribe(
(page: Page) => { (page: Page) => {
if (page != null) { if (page != null) {
this.sensors = page.content; this.sensors = page.content;
@ -74,6 +76,12 @@ export class ListComponent implements OnInit, AfterContentInit {
); );
} }
ngOnDestroy() {
if (this.sensorsSubscription$) {
this.sensorsSubscription$.unsubscribe();
}
}
getInfraInfo(infraID: string) { getInfraInfo(infraID: string) {
this.infraDetailStore.dispatch( this.infraDetailStore.dispatch(
new InfraDetailStore.Read( new InfraDetailStore.Read(

View File

@ -1,4 +1,4 @@
import { Component, OnInit, AfterViewInit, AfterContentInit, Input } from '@angular/core'; import { Component, OnInit, AfterViewInit, AfterContentInit, Input, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { Infra } from 'packages/infra/model'; import { Infra } from 'packages/infra/model';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
@ -11,14 +11,16 @@ import { Probe } from 'packages/probe/model';
import * as ProbeDetailStore from 'packages/probe/store/detail'; import * as ProbeDetailStore from 'packages/probe/store/detail';
import { DetailSelector as ProbeDetailSelector } from 'packages/probe/store'; import { DetailSelector as ProbeDetailSelector } from 'packages/probe/store';
import { Target } from '../../model'; import { Target } from '../../model';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'of-target-list', selector: 'of-target-list',
templateUrl: './list.component.html', templateUrl: './list.component.html',
}) })
export class ListComponent implements OnInit, AfterContentInit { export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
infrasSubscription$: Subscription;
infras$ = this.infraListStore.pipe(select(ListSelector.select('page'))); infras$ = this.infraListStore.pipe(select(ListSelector.select('page')));
infras: Infra[]; infras: Infra[];
probe: Probe; probe: Probe;
@ -33,8 +35,7 @@ export class ListComponent implements OnInit, AfterContentInit {
} }
ngOnInit() { ngOnInit() {
this.infrasSubscription$ = this.infras$.subscribe(
this.infras$.subscribe(
(page: Page) => { (page: Page) => {
if (!page) { if (!page) {
return; return;
@ -56,6 +57,12 @@ export class ListComponent implements OnInit, AfterContentInit {
}); });
} }
ngOnDestroy() {
if (this.infrasSubscription$) {
this.infrasSubscription$.unsubscribe();
}
}
getInfras(probe) { getInfras(probe) {
const pageParams: PageParams = { const pageParams: PageParams = {
pageNo: '0', pageNo: '0',