Skip to content

Commit

Permalink
fix: fixed issue where firebaseDocumentStoreUpdateFunction() repeated
Browse files Browse the repository at this point in the history
- fixed issue where firebaseDocumentStoreUpdateFunction() calls were called twice sometimes
  • Loading branch information
dereekb committed Aug 30, 2022
1 parent 2c5a31b commit c5e76c5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/dbx-firebase/src/lib/model/store/store.document.crud.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ModelFirebaseCreateFunction, ModelFirebaseDeleteFunction, ModelFirebaseUpdateFunction, OnCallCreateModelResult, TargetModelParams, InferredTargetModelParams, ModelFirebaseCrudFunction } from '@dereekb/firebase';
import { lazyFrom, LoadingState, loadingStateFromObs } from '@dereekb/rxjs';
import { firstValue, PartialOnKeys } from '@dereekb/util';
import { first, from, Observable, switchMap } from 'rxjs';
import { shareReplay, exhaustMap, first, from, Observable } from 'rxjs';
import { DbxFirebaseDocumentStore } from './store.document';

// MARK: Create
Expand Down Expand Up @@ -41,7 +41,7 @@ export type DbxfirebaseDocumentStoreCrudFunction<I, O = void> = (input: I) => Ob
* @returns
*/
export function firebaseDocumentStoreCrudFunction<I, O = void>(fn: ModelFirebaseCrudFunction<I, O>): DbxfirebaseDocumentStoreCrudFunction<I, O> {
return (params: I) => loadingStateFromObs(from(fn(params)));
return (params: I) => loadingStateFromObs(from(fn(params)).pipe(shareReplay(1)));
}

// MARK: Targeted Functions
Expand Down Expand Up @@ -71,12 +71,13 @@ export function firebaseDocumentStoreUpdateFunction<I extends DbxFirebaseDocumen
loadingStateFromObs(
store.key$.pipe(
first(),
switchMap((key) =>
exhaustMap((key) =>
fn({
...params,
key // inject key into the parameters.
} as I)
)
),
shareReplay(1)
)
);
}
Expand All @@ -96,15 +97,16 @@ export function firebaseDocumentStoreDeleteFunction<I extends DbxFirebaseDocumen
loadingStateFromObs(
store.key$.pipe(
first(),
switchMap((key) =>
exhaustMap((key) =>
fn({
...params,
key // inject key into the parameters.
} as I).then((result) => {
store.clearRefs();
return result;
})
)
),
shareReplay(1)
)
);
}

0 comments on commit c5e76c5

Please sign in to comment.