From 49ec48c9e946edec32e67bf70b21a34b306bbb13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsef=20Farkas?= Date: Thu, 10 Aug 2017 23:58:06 +0200 Subject: [PATCH] Fixing invalid keymap list propagation (#384) Fixes #382 --- .../components/popover/popover.component.ts | 14 ++++++++-- .../tab/keymap/keymap-tab.component.ts | 28 +++++++++---------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/shared/src/components/popover/popover.component.ts b/shared/src/components/popover/popover.component.ts index 7715734d..522f2169 100644 --- a/shared/src/components/popover/popover.component.ts +++ b/shared/src/components/popover/popover.component.ts @@ -5,6 +5,9 @@ import { animate, keyframes, state, style, transition, trigger } from '@angular/ import { Store } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; +import 'rxjs/add/operator/combineLatest'; +import 'rxjs/add/operator/map'; import { ClientRect } from '../../dom'; @@ -90,11 +93,14 @@ export class PopoverComponent implements OnChanges { private leftPosition: number = 0; private animationState: string; + private readonly currentKeymap$ = new BehaviorSubject(undefined); + constructor(store: Store) { this.animationState = 'closed'; this.keymaps$ = store.let(getKeymaps()) - .map((keymaps: Keymap[]) => - keymaps.filter((keymap: Keymap) => this.currentKeymap.abbreviation !== keymap.abbreviation) + .combineLatest(this.currentKeymap$) + .map(([keymaps, currentKeymap]: [Keymap[], Keymap]) => + keymaps.filter((keymap: Keymap) => currentKeymap.abbreviation !== keymap.abbreviation) ); } @@ -130,6 +136,10 @@ export class PopoverComponent implements OnChanges { this.animationState = 'closed'; } } + + if (change.currentKeymap) { + this.currentKeymap$.next(this.currentKeymap); + } } onCancelClick(): void { diff --git a/shared/src/components/popover/tab/keymap/keymap-tab.component.ts b/shared/src/components/popover/tab/keymap/keymap-tab.component.ts index 5ed5d7d2..51552d1d 100644 --- a/shared/src/components/popover/tab/keymap/keymap-tab.component.ts +++ b/shared/src/components/popover/tab/keymap/keymap-tab.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { Select2OptionData } from 'ng2-select2/ng2-select2'; @@ -12,7 +12,7 @@ import { Tab } from '../tab'; styleUrls: ['./keymap-tab.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class KeymapTabComponent extends Tab implements OnInit, OnChanges { +export class KeymapTabComponent extends Tab implements OnChanges { @Input() defaultKeyAction: KeyAction; @Input() keymaps: Keymap[]; @@ -24,20 +24,20 @@ export class KeymapTabComponent extends Tab implements OnInit, OnChanges { this.keymapOptions = []; } - ngOnInit() { - this.keymapOptions = this.keymaps - .map((keymap: Keymap): Select2OptionData => { - return { - id: keymap.abbreviation, - text: keymap.name - }; - }); - if (this.keymaps.length > 0) { - this.selectedKeymap = this.keymaps[0]; + ngOnChanges(changes: SimpleChanges) { + if (changes.keymaps) { + this.keymapOptions = this.keymaps + .map((keymap: Keymap): Select2OptionData => { + return { + id: keymap.abbreviation, + text: keymap.name + }; + }); + if (this.keymaps.length > 0) { + this.selectedKeymap = this.keymaps[0]; + } } - } - ngOnChanges() { this.fromKeyAction(this.defaultKeyAction); this.validAction.emit(true); }