Skip to content

Commit

Permalink
fix: languageKey subscription fix
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed Apr 20, 2018
1 parent dfa826d commit e48d15e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/app/shared/components/localized-description/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, OnInit } from '@angular/core';
import { Component, Input, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, OnInit, OnDestroy } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
Expand All @@ -17,7 +17,7 @@ import { DESCRIPTION_LANGUAGES, LanguageService } from 'app/shared/services';
styleUrls: ['./style.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class LocalizedDescriptionComponent implements AfterViewInit, OnInit {
export class LocalizedDescriptionComponent implements AfterViewInit, OnInit, OnDestroy {
@Input() descriptionSelector: any;
@Input() submitFv: (langKey: string, data) => void;
@Input() deleteFv: (langKey: string) => void;
Expand All @@ -30,14 +30,18 @@ export class LocalizedDescriptionComponent implements AfterViewInit, OnInit {
public langs = DESCRIPTION_LANGUAGES;
public selectedLanguage;

private _destroy$: Subject<boolean> = new Subject<boolean>();

constructor(
private _store: Store<State>,
private _cdr: ChangeDetectorRef
) {}

ngOnInit() {
this.descriptions$ = this._store.select(this.descriptionSelector);
this.languageKeys$ = this.descriptions$.map(desc => Object.keys(desc));
this.languageKeys$ = this._store
.select(this.descriptionSelector)
.takeUntil(this._destroy$)
.map(desc => Object.keys(desc));
}

ngAfterViewInit() {
Expand All @@ -50,6 +54,11 @@ export class LocalizedDescriptionComponent implements AfterViewInit, OnInit {
);
}

ngOnDestroy() {
this._destroy$.next(true);
this._destroy$.unsubscribe();
}

getLanguageFormDescriptor(languageKey: string) {
return {
submit: {
Expand Down

0 comments on commit e48d15e

Please sign in to comment.