-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #909 from eisbuk/enhancement/react-redux-firebase-…
…firestore-updates Enhancement/react redux firebase firestore updates
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/react-redux-firebase-firestore/src/hooks/useUpdateSubscription.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
|
||
import { CollectionSubscription } from "../types"; | ||
|
||
import { getFirestoreListeners } from "../selectors"; | ||
|
||
import { updateSubscription } from "../thunks/subscribe"; | ||
|
||
import { getCollectionPath, getConstraintForColl } from "../utils/utils"; | ||
|
||
const useUpdateSubscription = ( | ||
subscription: CollectionSubscription, | ||
deps: any[] | ||
): void => { | ||
const dispatch = useDispatch(); | ||
const collection = subscription.collection; | ||
|
||
const listeners = useSelector(getFirestoreListeners); | ||
|
||
useEffect(() => { | ||
const listener = listeners[collection]; | ||
|
||
if (!subscription.meta || !listener) return; | ||
|
||
const meta = { ...listener.meta, ...subscription.meta }; | ||
|
||
dispatch( | ||
updateSubscription({ | ||
storeAs: collection, | ||
collPath: getCollectionPath(subscription.collection, meta), | ||
constraint: getConstraintForColl(subscription.collection, meta), | ||
meta, | ||
}) | ||
); | ||
}, deps); | ||
}; | ||
|
||
export default useUpdateSubscription; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { createFirestoreReducer } from "./reducer"; | ||
import useFirestoreSubscribe from "./hooks/useFirestoreSubscribe"; | ||
import usePaginateFirestore from "./hooks/usePaginateFirestore"; | ||
export { createFirestoreReducer } from "./reducer"; | ||
|
||
export { createFirestoreReducer, useFirestoreSubscribe, usePaginateFirestore }; | ||
export { default as useFirestoreSubscribe } from "./hooks/useFirestoreSubscribe"; | ||
export { default as usePaginateFirestore } from "./hooks/usePaginateFirestore"; | ||
export { default as useUpdateSubscription } from "./hooks/useUpdateSubscription"; | ||
|
||
export * from "./types"; | ||
export * from "./actions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters