Skip to content

Commit cdee7d5

Browse files
author
Scott Prue
committed
* fix(docs): cleanup firestore example to use correct query settings (collection instead of path) - prescottprue#523
* fix(deps): correclty cache node_modules in travis-ci config (using $HOME so that npm ci works)
1 parent 2164389 commit cdee7d5

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ addons:
1919

2020
cache:
2121
directories:
22-
- node_modules
22+
- $HOME/.npm
2323

2424
branches:
2525
only:

docs/firestore.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# Firestore
22

3+
The Firestore integration is build on [`redux-firestore`](https://github.com/prescottprue/redux-firestore). Auth, Storage, and RTDB interactions still go on within `react-redux-firebase`, while `redux-firestore` handles attaching listeners and updating state for Firestore.
4+
35
To begin using Firestore with `react-redux-firebase`, make sure you have the following:
46
* `v2.0.0` or higher of `react-redux-firebase`
57
* Install `redux-firestore` in your project using `npm i --save redux-firestore@latest`
68
* `firestore` imported with `import 'firebase/firestore'`
79
* `firestore` initialize with `firebase.firestore()`
810
* `reduxFirestore` enhancer added to store creator
9-
* `firestoreReducer` added to your reducers (will be combinable with main before v2.0.0 release)
11+
* `firestoreReducer` added to your reducers
1012

1113
Should look something similar to:
1214

1315
```js
1416
import { createStore, combineReducers, compose } from 'redux'
15-
import firebase from 'firebase'
16-
import 'firebase/firestore' // add this to use Firestore
17+
import firebase from 'firebase/app'
18+
import 'firebase/auth'
19+
import 'firebase/database'
20+
import 'firebase/firestore' // make sure you add this for firestore
1721
import { reactReduxFirebase, firebaseReducer } from 'react-redux-firebase'
1822
import { reduxFirestore, firestoreReducer } from 'redux-firestore'
1923

@@ -24,16 +28,19 @@ const rrfConfig = {
2428
}
2529

2630
// initialize firebase instance with config from console
27-
const firebaseConfig = {}
31+
const firebaseConfig = {
32+
// your firebase config here
33+
}
34+
2835
firebase.initializeApp(firebaseConfig)
2936

30-
// initialize Firestore
31-
firebase.firestore()
37+
// Initialize Firestore with timeshot settings
38+
firebase.firestore().settings({ timestampsInSnapshots: true })
3239

3340
// Add BOTH store enhancers when making store creator
3441
const createStoreWithFirebase = compose(
35-
reactReduxFirebase(firebase, rrfConfig),
36-
reduxFirestore(firebase)
42+
reduxFirestore(firebase),
43+
reactReduxFirebase(firebase, rrfConfig)
3744
)(createStore)
3845

3946
// Add firebase and firestore to reducers
@@ -120,7 +127,7 @@ class Todos extends Component {
120127
store: PropTypes.object.isRequired
121128
}
122129

123-
componentWillMount () {
130+
componentDidMount () {
124131
const { firebase } = this.context.store
125132
firebase.setListener('todos')
126133
// firebase.setListener({ collection: 'todos' }) // or object notation
@@ -199,7 +206,7 @@ const enhance = compose(
199206
loadData: props => path => props.firestore.get(path)
200207
}),
201208
lifecycle({
202-
componentWillMount() {
209+
componentDidMount() {
203210
this.props.loadData('todos')
204211
// this.props.firestore.get('todos') // equivalent without withHandlers
205212
}
@@ -230,11 +237,13 @@ const myProjectsReduxName = 'myProjects'
230237

231238
compose(
232239
firestoreConnect(props => [
233-
{ path: 'projects' },
240+
{ collection: 'projects' },
234241
{
235-
path: 'projects',
236-
storeAs: myProjectsReduxName,
237-
queryParams: ['orderByChild=uid', '123']
242+
collection: 'projects',
243+
where: [
244+
['uid', '==', '123']
245+
],
246+
storeAs: myProjectsReduxName
238247
}
239248
]),
240249
connect((state, props) => ({
@@ -247,7 +256,3 @@ compose(
247256
## Populate {#populate}
248257

249258
Populate is not yet supported for the Firestore integration, but will be coming soon. Progress can be tracked [within issue #48](https://github.com/prescottprue/redux-firestore/issues/48).
250-
251-
## More Info {#more}
252-
253-
The Firestore integration is build on [`redux-firestore`](https://github.com/prescottprue/redux-firestore).

0 commit comments

Comments
 (0)