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 DetailStore from 'packages/notification/store/detail';
import { Store, select } from '@ngrx/store';
@ -10,14 +10,16 @@ import { Member } from 'packages/member/model';
import { PagesComponent } from 'app/pages/pages.component';
import { Notification } from 'packages/notification/model';
import { Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'of-notification-menu',
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')));
notifications: Notification[];
@ -32,7 +34,7 @@ export class AppNotificationComponent implements OnInit, AfterContentInit {
}
ngOnInit() {
this.notification$.subscribe(
this.notificationSubscription$ = this.notification$.subscribe(
(page: Page) => {
if (page !== null) {
this.notifications = page.content;
@ -62,6 +64,12 @@ export class AppNotificationComponent implements OnInit, AfterContentInit {
);
}
ngOnDestroy() {
if (this.notificationSubscription$) {
this.notificationSubscription$.unsubscribe();
}
}
getUnconfirmedCount() {
if (this.notifications === null || this.notifications.length === 0) {
return;

View File

@ -1,5 +1,5 @@
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 { Store, select } from '@ngrx/store';
import { AuthSelector } from 'packages/member/store';
@ -10,6 +10,7 @@ import { NoAuthProbeSelector } from '../../store';
import { NoAuthProbe } from '../../model';
import { ConfirmationService, Message } from 'primeng/primeng';
import { MessageService } from 'primeng/components/common/messageservice';
import { Subscription } from 'rxjs/Subscription';
class NoauthProbeDesc {
host: {
@ -41,7 +42,8 @@ class NoauthProbeResult {
templateUrl: './list.component.html',
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: NoauthProbeResult[];
msgs: Message[];
@ -56,7 +58,7 @@ export class ListComponent implements OnInit, AfterContentInit {
}
ngOnInit() {
this.noAuthProbes$.subscribe(
this.noAuthProbesSubscription$ = this.noAuthProbes$.subscribe(
(result: NoAuthProbe[]) => {
if (result) {
this.arrangeData(result);
@ -76,6 +78,10 @@ export class ListComponent implements OnInit, AfterContentInit {
);
}
ngOnDestroy() {
this.noAuthProbesSubscription$.unsubscribe();
}
arrangeData(list) {
if (!list || list.length === 0) {
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 { Store, select } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
@ -9,13 +9,15 @@ import { ReadAllByMemberSelector, ReadSelector } from '../../store';
import { AuthSelector } from 'packages/member/store';
import { Member } from '../../../member/model';
import { PageParams, Page } from 'app/commons/model';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'of-notification',
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')));
notifications: Notification[];
readSuccess$ = this.detailStore.pipe(select(ReadSelector.select('notification')));
@ -31,7 +33,7 @@ export class NotificationComponent implements OnInit, AfterContentInit {
) { }
ngOnInit() {
this.notification$.subscribe(
this.notificationSubscription$ = this.notification$.subscribe(
(page: Page) => {
if (page !== null) {
console.log(page);
@ -60,6 +62,12 @@ export class NotificationComponent implements OnInit, AfterContentInit {
this.getNotifications(this.currPage);
}
ngOnDestroy() {
if (this.notificationSubscription$) {
this.notificationSubscription$.unsubscribe();
}
}
// updateData(noti: Notification) {
// for (let i = 0; i < this.notifications.length; 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 { ConfirmationService } from 'primeng/primeng';
import { Store, select } from '@ngrx/store';
@ -6,14 +6,16 @@ import { RPCClientError } from '@loafer/ng-rpc/protocol';
import * as DetailStore from '../../store/detail';
import { sensorSelector } from '../../store';
import { Sensor } from '../../model';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'of-sensor-detail',
templateUrl: './detail.component.html',
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: Sensor;
@ -25,7 +27,7 @@ export class DetailComponent implements OnInit, AfterContentInit {
) { }
ngOnInit() {
this.sensor$.subscribe(
this.sensorSubscription$ = this.sensor$.subscribe(
(sensor: Sensor) => {
console.log(sensor);
this.sensor = sensor;
@ -45,6 +47,12 @@ export class DetailComponent implements OnInit, AfterContentInit {
);
}
ngOnDestroy() {
if (this.sensorSubscription$) {
this.sensorSubscription$.unsubscribe();
}
}
onStartOrStop() { }
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 { Sensor } from '../../model';
import { Store, select } from '@ngrx/store';
@ -16,6 +16,7 @@ import { SelectItem } from 'primeng/primeng';
import { Infra } from 'packages/infra/model';
import * as InfraDetailStore from 'packages/infra/store/detail';
import { DetailSelector as InfraDetailSelector } from 'packages/infra/store';
import { Subscription } from 'rxjs/Subscription';
@Component({
@ -23,8 +24,9 @@ import { DetailSelector as InfraDetailSelector } from 'packages/infra/store';
templateUrl: './list.component.html',
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')));
PAGE_SIZE = '99999';
totalLength = 0;
@ -61,7 +63,7 @@ export class ListComponent implements OnInit, AfterContentInit {
}
});
this.sensorList$.subscribe(
this.sensorsSubscription$ = this.sensorList$.subscribe(
(page: Page) => {
if (page != null) {
this.sensors = page.content;
@ -74,6 +76,12 @@ export class ListComponent implements OnInit, AfterContentInit {
);
}
ngOnDestroy() {
if (this.sensorsSubscription$) {
this.sensorsSubscription$.unsubscribe();
}
}
getInfraInfo(infraID: string) {
this.infraDetailStore.dispatch(
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 { Infra } from 'packages/infra/model';
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 { DetailSelector as ProbeDetailSelector } from 'packages/probe/store';
import { Target } from '../../model';
import { Subscription } from 'rxjs/Subscription';
@Component({
selector: 'of-target-list',
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: Infra[];
probe: Probe;
@ -33,8 +35,7 @@ export class ListComponent implements OnInit, AfterContentInit {
}
ngOnInit() {
this.infras$.subscribe(
this.infrasSubscription$ = this.infras$.subscribe(
(page: Page) => {
if (!page) {
return;
@ -56,6 +57,12 @@ export class ListComponent implements OnInit, AfterContentInit {
});
}
ngOnDestroy() {
if (this.infrasSubscription$) {
this.infrasSubscription$.unsubscribe();
}
}
getInfras(probe) {
const pageParams: PageParams = {
pageNo: '0',