Skip to content

Commit 59afff1

Browse files
authored
v0.6.0-alpha.3
* fix(reducers): correctly update state for docs with keys that contain a dot when using storeAs - @compojoom * feat(query): consolidate oneListenerPerPath and allowMultipleListeners logic - @alexmattson * feat(query): initial support for populate - #48, [RRF 362](prescottprue/react-redux-firebase#362)
2 parents 0cb3e7e + 15eac10 commit 59afff1

17 files changed

+574
-282
lines changed

.babelrc

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
],
1111
"plugins": [
1212
"lodash",
13+
"transform-runtime",
1314
"transform-object-rest-spread",
14-
"transform-object-assign",
15+
"transform-object-assign"
1516
],
1617
"env": {
1718
"es": {
@@ -28,7 +29,6 @@
2829
},
2930
"test": {
3031
"plugins": [
31-
"transform-runtime",
3232
"transform-async-to-generator",
3333
["module-resolver", {
3434
"root": ["./src"]

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ rules:
2020
no-confusing-arrow: 0
2121
no-case-declarations: 0
2222
arrow-parens: [2, "as-needed"]
23+
prefer-default-export: 0

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ es
55
*.log
66
coverage
77
.idea
8+
.DS_Store

README.md

+81-10
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const enhance = compose(
114114
props.store.firestore.add('todos', { ...newTodo, owner: 'Anonymous' }),
115115
}),
116116
lifecycle({
117-
componentWillMount(props) {
117+
componentDidMount(props) {
118118
props.loadData()
119119
}
120120
}),
@@ -142,7 +142,7 @@ class Todos extends Component {
142142
store: PropTypes.object.isRequired
143143
}
144144

145-
componentWillMount () {
145+
componentDidMount () {
146146
const { firestore } = this.context.store
147147
firestore.get('todos')
148148
}
@@ -251,7 +251,7 @@ After setting a listener/multiple listeners, you can unset them with the followi
251251
```js
252252
store.firestore.unsetListener({ collection: 'cities' }),
253253
// of for any number of listeners at once :
254-
store.firestore.unsetListeners([query1Options, query2Options]),
254+
store.firestore.unsetListeners([query1Options, query2Options]),
255255
// here query1Options as in { collection: 'cities' } for example
256256
```
257257

@@ -447,16 +447,16 @@ Storing data under a different path within redux is as easy as passing the `stor
447447
Other Firebase statics (such as [FieldValue](https://firebase.google.com/docs/reference/js/firebase.firestore.FieldValue)) are available through the firestore instance:
448448

449449
```js
450+
import PropTypes from 'prop-types'
450451
import { connect } from 'react-redux'
451452
import {
452453
compose,
453454
withHandlers,
454-
lifecycle,
455455
withContext,
456456
getContext
457457
} from 'recompose'
458458

459-
const withFirestore = compose(
459+
const withStore = compose(
460460
withContext({ store: PropTypes.object }, () => {}),
461461
getContext({ store: PropTypes.object }),
462462
)
@@ -477,6 +477,82 @@ const enhance = compose(
477477
export default enhance(SomeComponent)
478478
```
479479

480+
### Population
481+
Population, made popular in [react-redux-firebase](http://react-redux-firebase.com/docs/recipes/populate.html), also works with firestore.
482+
483+
484+
#### Automatic Listeners
485+
```js
486+
import { connect } from 'react-redux'
487+
import { firestoreConnect, populate } from 'react-redux-firebase'
488+
import {
489+
compose,
490+
withHandlers,
491+
lifecycle,
492+
withContext,
493+
getContext
494+
} from 'recompose'
495+
496+
const populates = [{ child: 'createdBy', root: 'users' }]
497+
const collection = 'projects'
498+
499+
const withPopulatedProjects = compose(
500+
firestoreConnect((props) => [
501+
{
502+
collection,
503+
populates
504+
}
505+
]),
506+
connect((state, props) => ({
507+
projects: populate(state.firestore, collection, populates)
508+
}))
509+
)
510+
```
511+
512+
#### Manually using setListeners
513+
```js
514+
import { withFirestore, populate } from 'react-redux-firebase'
515+
import { connect } from 'react-redux'
516+
import { compose, lifecycle } from 'recompose'
517+
518+
const collection = 'projects'
519+
const populates = [{ child: 'createdBy', root: 'users' }]
520+
521+
const enhance = compose(
522+
withFirestore,
523+
lifecycle({
524+
componentDidMount() {
525+
this.props.firestore.setListener({ collection, populates })
526+
}
527+
}),
528+
connect(({ firestore }) => ({ // state.firestore
529+
todos: firestore.ordered.todos,
530+
}))
531+
)
532+
```
533+
534+
#### Manually using get
535+
```js
536+
import { withFirestore, populate } from 'react-redux-firebase'
537+
import { connect } from 'react-redux'
538+
import { compose, lifecycle } from 'recompose'
539+
540+
const collection = 'projects'
541+
const populates = [{ child: 'createdBy', root: 'users' }]
542+
543+
const enhance = compose(
544+
withFirestore,
545+
lifecycle({
546+
componentDidMount() {
547+
this.props.store.firestore.get({ collection, populates })
548+
}
549+
}),
550+
connect(({ firestore }) => ({ // state.firestore
551+
todos: firestore.ordered.todos,
552+
}))
553+
)
554+
```
555+
480556
## Config Options
481557
Optional configuration options for redux-firestore, provided to reduxFirestore enhancer as optional second argument. Combine any of them together in an object.
482558

@@ -495,11 +571,6 @@ Default: `false`
495571

496572
Whether or not to allow multiple listeners to be attached for the same query. If a function is passed the arguments it receives are `listenerToAttach`, `currentListeners`, and the function should return a boolean.
497573

498-
#### oneListenerPerPath
499-
Default: `false`
500-
501-
If set to true redux-firestore will attach a listener on the same path just once & will count how many the listener was set. When you try to unset the listener, it won't unset until you have less than 1 listeners on this path
502-
503574
#### preserveOnDelete
504575
Default: `null`
505576

examples/basic/jsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./src"
4+
},
5+
"exclude": [
6+
"node_modules",
7+
"public",
8+
]
9+
}

jsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./src",
4+
"paths": {
5+
"utils/*": [
6+
"utils/*",
7+
]
8+
}
9+
},
10+
"exclude": [
11+
"node_modules",
12+
"dist",
13+
"es",
14+
"lib",
15+
"coverage"
16+
]
17+
}

0 commit comments

Comments
 (0)