Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jj committed Feb 19, 2019
2 parents 87ded49 + 60ee626 commit 7b1a8ca
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MetadataResolver } from '../../domain/model';
import { LockEditor, UnlockEditor } from '../../../wizard/action/wizard.action';

import * as fromWizard from '../../../wizard/reducer';
import { withLatestFrom, map, distinctUntilChanged, filter } from 'rxjs/operators';
import { withLatestFrom, map, distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
import { UpdateChanges } from '../action/entity.action';
import { FormControl } from '@angular/forms';

Expand Down Expand Up @@ -81,25 +81,30 @@ export class ResolverEditStepComponent implements OnDestroy {
this.changes$,
this.definition$
),
map(([schema, resolver, model, changes, definition]) => ({
model: {
...model,
...resolver,
...changes
},
definition
})),
map(([schema, resolver, model, changes, definition]) => {
return ({
model: {
...model,
...resolver,
...changes
},
definition
});
}),
filter(({ model, definition }) => definition && model),
map(({ model, definition }) => definition.formatter(model))
);

this.valueChangeEmitted$.pipe(
takeUntil(this.ngUnsubscribe),
map(changes => changes.value),
withLatestFrom(this.definition$, this.store.select(fromResolver.getSelectedResolver)),
filter(([changes, definition]) => definition && changes),
map(([changes, definition, resolver]) => definition.parser({ ...resolver, ...changes }))
withLatestFrom(this.definition$, this.store.select(fromResolver.getSelectedResolver), this.changes$),
filter(([valueChange, definition, resolver]) => definition && resolver),
map(([valueChange, definition, resolver, changes]) => definition.parser({ ...resolver, ...changes, ...valueChange }))
)
.subscribe(changes => this.store.dispatch(new UpdateChanges(changes)));
.subscribe(changes => {
this.store.dispatch(new UpdateChanges(changes));
});

this.statusChangeEmitted$
.pipe(distinctUntilChanged())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component, OnDestroy, Inject } from '@angular/core';
import { Subscription, Observable } from 'rxjs';
import { Subscription, Observable, Subject } from 'rxjs';
import { Store } from '@ngrx/store';

import { ActivatedRoute } from '@angular/router';
import { map, distinctUntilChanged, skipWhile } from 'rxjs/operators';
import { map, distinctUntilChanged, skipWhile, takeUntil } from 'rxjs/operators';
import { SelectResolver } from '../action/collection.action';
import * as fromResolvers from '../reducer';
import { MetadataResolver } from '../../domain/model';
Expand All @@ -19,6 +19,7 @@ import { Wizard } from '../../../wizard/model';
})

export class ResolverSelectComponent implements OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();
actionsSubscription: Subscription;

resolver$: Observable<MetadataResolver>;
Expand All @@ -28,13 +29,14 @@ export class ResolverSelectComponent implements OnDestroy {
private route: ActivatedRoute,
@Inject(METADATA_SOURCE_EDITOR) private sourceWizard: Wizard<MetadataResolver>
) {
this.actionsSubscription = this.route.params.pipe(
this.route.params.pipe(
takeUntil(this.ngUnsubscribe),
map(params => new SelectResolver(params.id))
).subscribe(store);

this.resolver$ = this.store.select(fromResolvers.getSelectedResolver).pipe(skipWhile(p => !p));

this.resolver$.subscribe(resolver => this.setDefinition(resolver));
this.resolver$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(resolver => this.setDefinition(resolver));
}

setDefinition(resolver: MetadataResolver): void {
Expand All @@ -44,7 +46,8 @@ export class ResolverSelectComponent implements OnDestroy {
}

ngOnDestroy() {
this.actionsSubscription.unsubscribe();
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
this.store.dispatch(new Clear());
this.store.dispatch(new ClearWizard());
}
Expand Down

0 comments on commit 7b1a8ca

Please sign in to comment.