refactor(nx): simplify DataPersistence methods

This commit is contained in:
Leigh Caplan 2018-06-11 09:48:55 -07:00 committed by Victor Savkin
parent 2fc57955cd
commit d38700ead7

View File

@ -237,9 +237,9 @@ export class DataPersistence<T> {
actionType: string, actionType: string,
opts: PessimisticUpdateOpts<T, A> opts: PessimisticUpdateOpts<T, A>
): Observable<any> { ): Observable<any> {
const nav = this.actions.ofType<A>(actionType); return this.actions
const pairs = nav.pipe(withLatestFrom(this.store)); .ofType<A>(actionType)
return pairs.pipe(pessimisticUpdate(opts)); .pipe(withLatestFrom(this.store), pessimisticUpdate(opts));
} }
/** /**
@ -292,9 +292,9 @@ export class DataPersistence<T> {
actionType: string, actionType: string,
opts: OptimisticUpdateOpts<T, A> opts: OptimisticUpdateOpts<T, A>
): Observable<any> { ): Observable<any> {
const nav = this.actions.ofType<A>(actionType); return this.actions
const pairs = nav.pipe(withLatestFrom(this.store)); .ofType<A>(actionType)
return pairs.pipe(optimisticUpdate(opts)); .pipe(withLatestFrom(this.store), optimisticUpdate(opts));
} }
/** /**
@ -368,10 +368,9 @@ export class DataPersistence<T> {
actionType: string, actionType: string,
opts: FetchOpts<T, A> opts: FetchOpts<T, A>
): Observable<any> { ): Observable<any> {
const nav = this.actions.ofType<A>(actionType); return this.actions
const allPairs = nav.pipe(withLatestFrom(this.store)); .ofType<A>(actionType)
.pipe(withLatestFrom(this.store), fetch(opts));
return allPairs.pipe(fetch(opts));
} }
/** /**
@ -411,9 +410,10 @@ export class DataPersistence<T> {
component: Type<any>, component: Type<any>,
opts: HandleNavigationOpts<T> opts: HandleNavigationOpts<T>
): Observable<any> { ): Observable<any> {
const nav = this.actions; return this.actions.pipe(
const pairs = nav.pipe(withLatestFrom(this.store)); withLatestFrom(this.store),
return pairs.pipe(navigation(component, opts)); navigation(component, opts)
);
} }
} }