Skip to content

Commit

Permalink
v0.6.0-alpha.3
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
prescottprue authored Nov 8, 2018
2 parents 0cb3e7e + 15eac10 commit 59afff1
Show file tree
Hide file tree
Showing 17 changed files with 574 additions and 282 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
],
"plugins": [
"lodash",
"transform-runtime",
"transform-object-rest-spread",
"transform-object-assign",
"transform-object-assign"
],
"env": {
"es": {
Expand All @@ -28,7 +29,6 @@
},
"test": {
"plugins": [
"transform-runtime",
"transform-async-to-generator",
["module-resolver", {
"root": ["./src"]
Expand Down
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rules:
no-confusing-arrow: 0
no-case-declarations: 0
arrow-parens: [2, "as-needed"]
prefer-default-export: 0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ es
*.log
coverage
.idea
.DS_Store
91 changes: 81 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const enhance = compose(
props.store.firestore.add('todos', { ...newTodo, owner: 'Anonymous' }),
}),
lifecycle({
componentWillMount(props) {
componentDidMount(props) {
props.loadData()
}
}),
Expand Down Expand Up @@ -142,7 +142,7 @@ class Todos extends Component {
store: PropTypes.object.isRequired
}

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

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

```js
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import {
compose,
withHandlers,
lifecycle,
withContext,
getContext
} from 'recompose'

const withFirestore = compose(
const withStore = compose(
withContext({ store: PropTypes.object }, () => {}),
getContext({ store: PropTypes.object }),
)
Expand All @@ -477,6 +477,82 @@ const enhance = compose(
export default enhance(SomeComponent)
```

### Population
Population, made popular in [react-redux-firebase](http://react-redux-firebase.com/docs/recipes/populate.html), also works with firestore.


#### Automatic Listeners
```js
import { connect } from 'react-redux'
import { firestoreConnect, populate } from 'react-redux-firebase'
import {
compose,
withHandlers,
lifecycle,
withContext,
getContext
} from 'recompose'

const populates = [{ child: 'createdBy', root: 'users' }]
const collection = 'projects'

const withPopulatedProjects = compose(
firestoreConnect((props) => [
{
collection,
populates
}
]),
connect((state, props) => ({
projects: populate(state.firestore, collection, populates)
}))
)
```

#### Manually using setListeners
```js
import { withFirestore, populate } from 'react-redux-firebase'
import { connect } from 'react-redux'
import { compose, lifecycle } from 'recompose'

const collection = 'projects'
const populates = [{ child: 'createdBy', root: 'users' }]

const enhance = compose(
withFirestore,
lifecycle({
componentDidMount() {
this.props.firestore.setListener({ collection, populates })
}
}),
connect(({ firestore }) => ({ // state.firestore
todos: firestore.ordered.todos,
}))
)
```

#### Manually using get
```js
import { withFirestore, populate } from 'react-redux-firebase'
import { connect } from 'react-redux'
import { compose, lifecycle } from 'recompose'

const collection = 'projects'
const populates = [{ child: 'createdBy', root: 'users' }]

const enhance = compose(
withFirestore,
lifecycle({
componentDidMount() {
this.props.store.firestore.get({ collection, populates })
}
}),
connect(({ firestore }) => ({ // state.firestore
todos: firestore.ordered.todos,
}))
)
```

## Config Options
Optional configuration options for redux-firestore, provided to reduxFirestore enhancer as optional second argument. Combine any of them together in an object.

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

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.

#### oneListenerPerPath
Default: `false`

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

#### preserveOnDelete
Default: `null`

Expand Down
9 changes: 9 additions & 0 deletions examples/basic/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": "./src"
},
"exclude": [
"node_modules",
"public",
]
}
17 changes: 17 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"utils/*": [
"utils/*",
]
}
},
"exclude": [
"node_modules",
"dist",
"es",
"lib",
"coverage"
]
}
Loading

0 comments on commit 59afff1

Please sign in to comment.