Initialize library.
firestoreRedux.init(store, firebaseApp);
store (Object)
Redux Store. It is mandatory.firebaseApp (Object)
Firebase app. It is optional.readPollingConfig
Configurations for waiting query. This is ignored whenwaitTillSucceed
query criteria is nottrue
. Default is{ timeout: 30000, maxAttempts: 20 }
.
- Nothing
Reads data from the firestore for given collection/subcollection based on given query criteria.
const query = firestoreRedux.query(
collection
{
requesterId,
collection,
where,
orderBy,
startAt,
startAfter,
endAt,
endBefore,
limit,
once,
waitTillSucceed
}
);
-
collection (String)
Collection or subcollection ID. It cannot contain a slash. It is mandatory. -
queryCriteria (Object)
: Optional. If not provided, reads all documents of given collection/subcollection.requesterId (String)
Requester Id.where (Array)
List of where conditions. e.g.[['firstName', '==', 'Nirmal'], ['lastName', '==', 'Baldaniya']]
.orderBy (Array)
List of orderBy fields. e.g.[['lastSeen', 'asc'], ['age', 'desc']]
.startAt (Any)
The field values to start this query at, in order of the query's order by.startAfter (Any)
The field values to start this query after, in order of the query's order by.endAt (Any)
The field values to end this query at, in order of the query's order by.endBefore (Any)
The field values to end this query before, in order of the query's order by.limit (Number)
The maximum number of items in result.once (Boolean)
Whentrue
, does not subscribe for realtime changes. Default isfalse
.waitTillSucceed (Boolean)
When it'strue
, retries query based onreadPollingConfig
. Default isfalse
.
(Object)
query
which is instance of theQuery
class.- Later on it can be used to cancel query, load next page, or retry failed.
const queryId = query.id; // Get query Id. query.cancel(); // Cancel query. query.loadNextPage(); // Load next page. try { const docs = await query.result; // Resolved when first snapshot is retrived. } catch(error){ query.retry(); }
- Later on it can be used to cancel query, load next page, or retry failed.
Reads single document from firestore by document ID.
const query = firestoreRedux.getDocById(collection, docId, { requesterId });
collectionPath (String)
Collection or subcollection path. e.g.users
orboards/$boardId/cards
.docId (String)
Document ID.options (Object)
OptionsrequesterId (String)
Requester Id.once (Boolean)
true
When query is not realtime.waitTillSucceed (Boolean)
When it'strue
, retries query based onreadPollingConfig
.
(Object)
request
which is instance of theGetDocById
class.- Later on it can be used to cancel query or wait till query succeeds or failed.
const queryId = request.id; // Get query Id. request.cancel(); // Cancel query. try { const doc= await request.result; // Resolved when first snapshot is retrived. } catch(error){ query.retry(); }
- Later on it can be used to cancel query or wait till query succeeds or failed.
Cancels live query by it's id.
firestoreRedux.cancelQuery(id);
id (String)
Query Id. It is mandatory.
- Nothing
Cancels live queries by requester Id.
firestoreRedux.cancelQueryByRequester(requesterId);
requesterId
(String) Requester Id. It is mandatory.
- Nothing
Saves/updates documents of given collection to local as well as on remote.
firestoreRedux.save(collectionPath, docs, options);
collectionPath (String)
Collection / Subcollection path. if it's subcollection, it's/
sepereted path upto subcollection. e.g.boards/$boardId/cards
docs (Object|Array)
Single document or List of documents to be saved or updated.options (Object)
. Save options. e.g.{ localWrite: true, remoteWrite: true, queryId }
By defaultlocalWrite
&remoteWrite
both aretrue
. WhenqueryId
is provided, updates query result as well.
(Promise)
It will be resolved only when documents will be saved on remote successfully. On failed, it will be rejected.
Deletes documents of given collection from local as well as on remote.
firestoreRedux.delete(collectionPath, docIds, options);
collectionPath (String)
Collection / Subcollection path.docIds (String|Array)
Single doc Id or List of document Ids.options (Object)
. Save options. e.g.{ localWrite: true, remoteWrite: true, queryId }
By defaultlocalWrite
&remoteWrite
both aretrue
. WhenqueryId
is provided, removes docId from query result as well.
(Promise)
It will be resolved only when documents will be deleted from remote successfully. On failed, it will be rejected.
Gets single document of given document ID.
const doc = firestoreRedux.selectors.doc(state, collection, docId);
state (Object)
Redux state.collection (String)
Collection ID.docId (String)
Document Id
(Object)
e.g.{ id, firstName, lastName, profilePic }
Gets all documents of the given collection ID.
const docs = firestoreRedux.selectors.allDocs({state, collection});
state (Object)
Redux state.collection (String)
Collection ID.
(Array)
e.g.[ { id, firstName, lastName, profilePic },{ id, firstName, lastName, profilePic }, ... ]
Gets all documents of the given collection ID.
const docs = firestoreRedux.selectors.collection(state, collection);
state (Object)
Redux state.collection (String)
Collection ID.
(Object)
e.g.{ $docId1: $doc1, $docId2: $doc2, ... }
Gets documents of given collection, based the query result of given queryId.
const docs = firestoreRedux.selectors.docsByQuery({state, queryId});
state (Object)
Redux state.queryId (String)
Query ID, from whose documents will be returned.
(Array)
e.g.[ { id, firstName, lastName, profilePic },{ id, firstName, lastName, profilePic } ]
Gets query detail by it's ID.
const query = firestoreRedux.selectors.query(state, id);
state (Object)
Redux state.id (String)
Query ID
(Object)
e.g.{ id, requesterId, collection, request, result, status, error }
Gets query status by it's ID.
const status = firestoreRedux.selectors.queryStatus(state, id);
state (Object)
Redux state.id (String)
Query ID
(String)
Possible values:PENDING
,LIVE
,CLOSED
orFAILED
.
Gets query error detail by it's ID.
const error = firestoreRedux.selectors.queryError(state, id);
state (Object)
Redux state.id (String)
Query ID
(Object)
e.g.{ code, message }
Gets queries by requesterId.
const error = firestoreRedux.selectors.queriesByRequester({state, requesterId});
state (Object)
Redux state.requesterId (String)
Requester ID
(Array)
e.g.[$query1, $query2, ...]