Fixing invalid keymap list propagation (#384)

Fixes #382
This commit is contained in:
József Farkas
2017-08-10 23:58:06 +02:00
committed by László Monda
parent 2735edb631
commit 49ec48c9e9
2 changed files with 26 additions and 16 deletions
@@ -5,6 +5,9 @@ import { animate, keyframes, state, style, transition, trigger } from '@angular/
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import 'rxjs/add/operator/combineLatest';
import 'rxjs/add/operator/map';
import { ClientRect } from '../../dom'; import { ClientRect } from '../../dom';
@@ -90,11 +93,14 @@ export class PopoverComponent implements OnChanges {
private leftPosition: number = 0; private leftPosition: number = 0;
private animationState: string; private animationState: string;
private readonly currentKeymap$ = new BehaviorSubject<Keymap>(undefined);
constructor(store: Store<AppState>) { constructor(store: Store<AppState>) {
this.animationState = 'closed'; this.animationState = 'closed';
this.keymaps$ = store.let(getKeymaps()) this.keymaps$ = store.let(getKeymaps())
.map((keymaps: Keymap[]) => .combineLatest(this.currentKeymap$)
keymaps.filter((keymap: Keymap) => this.currentKeymap.abbreviation !== keymap.abbreviation) .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'; this.animationState = 'closed';
} }
} }
if (change.currentKeymap) {
this.currentKeymap$.next(this.currentKeymap);
}
} }
onCancelClick(): void { onCancelClick(): void {
@@ -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'; import { Select2OptionData } from 'ng2-select2/ng2-select2';
@@ -12,7 +12,7 @@ import { Tab } from '../tab';
styleUrls: ['./keymap-tab.component.scss'], styleUrls: ['./keymap-tab.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class KeymapTabComponent extends Tab implements OnInit, OnChanges { export class KeymapTabComponent extends Tab implements OnChanges {
@Input() defaultKeyAction: KeyAction; @Input() defaultKeyAction: KeyAction;
@Input() keymaps: Keymap[]; @Input() keymaps: Keymap[];
@@ -24,20 +24,20 @@ export class KeymapTabComponent extends Tab implements OnInit, OnChanges {
this.keymapOptions = []; this.keymapOptions = [];
} }
ngOnInit() { ngOnChanges(changes: SimpleChanges) {
this.keymapOptions = this.keymaps if (changes.keymaps) {
.map((keymap: Keymap): Select2OptionData => { this.keymapOptions = this.keymaps
return { .map((keymap: Keymap): Select2OptionData => {
id: keymap.abbreviation, return {
text: keymap.name id: keymap.abbreviation,
}; text: keymap.name
}); };
if (this.keymaps.length > 0) { });
this.selectedKeymap = this.keymaps[0]; if (this.keymaps.length > 0) {
this.selectedKeymap = this.keymaps[0];
}
} }
}
ngOnChanges() {
this.fromKeyAction(this.defaultKeyAction); this.fromKeyAction(this.defaultKeyAction);
this.validAction.emit(true); this.validAction.emit(true);
} }