Skip to content

Commit 366c4ff

Browse files
prescottprueScott Prue
authored and
Scott Prue
committed
Version v1.2.2 (prescottprue#45)
* Undefined `populatedDataToJS` children handled * Docs updated with exposure of `auth()` * Fixes of small errors in docs (spacing/typos)
1 parent fc0cce8 commit 366c4ff

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

docs/api/helpers.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,17 @@ _Basic_
130130
import { connect } from 'react-redux'
131131
import { firebaseConnect, helpers } from 'react-redux-firebase'
132132
const { dataToJS } = helpers
133+
const populates = [{ child: 'owner', root: 'users' }]
133134

134-
const fbWrapped = firebaseConnect(['/todos'])(App)
135+
const fbWrapped = firebaseConnect([
136+
{ path: '/todos', populates } // load "todos" and matching "users" to redux
137+
])(App)
135138

136139
export default connect(({ firebase }) => ({
137140
// this.props.todos loaded from state.firebase.data.todos
138141
// each todo has child 'owner' populated from matching uid in 'users' root
139-
todos: populatedDataToJS(firebase, 'todos', [{ child: 'owner', root: 'users' }])
142+
// for loading un-populated todos use dataToJS(firebase, 'todos')
143+
todos: populatedDataToJS(firebase, 'todos', populates),
140144
}))(fbWrapped)
141145
```
142146

docs/auth.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { pathToJS } = helpers
1515
})
1616
)
1717
```
18+
If you need access to methods that are not available at the top level, you can access Firebase's Full Auth API using `this.props.firebase.auth()` or `getFirebase().auth()`.
1819

1920
#### NOTE
2021
All examples below assume you have wrapped your component using `firebaseConnect`. This will make `this.props.firebase` available within your component:
@@ -48,7 +49,7 @@ export default firebaseConnect()(SomeComponent)
4849
```
4950

5051

51-
## `login(credentials)`
52+
## login(credentials)
5253

5354
##### Parameters
5455

@@ -116,7 +117,7 @@ this.props.firebase.login({
116117
this.props.firebase.login('someJWTAuthToken')
117118
```
118119

119-
## `createUser(credentials, profile)`
120+
## createUser(credentials, profile)
120121

121122
Similar to Firebase's `ref.createUser(credentials)` but with support for automatic profile setup (based on your userProfile config).
122123
@@ -149,7 +150,7 @@ createNewUser({
149150
##### Returns
150151
[**Promise**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with `userData`
151152

152-
## `logout()`
153+
## logout()
153154
Logout from Firebase and delete all data from the store (`state.firebase.data` and `state.firebase.auth` are set to `null`).
154155

155156
##### Examples
@@ -159,7 +160,7 @@ Logout from Firebase and delete all data from the store (`state.firebase.data` a
159160
firebase.logout()
160161
```
161162

162-
## `resetPassword(credentials)`
163+
## resetPassword(credentials)
163164
Calls Firebase's `ref.resetPassword(credentials)` then adds the output into redux state under `state.firebase.authError`
164165
165166
##### Examples

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
55
"main": "dist/index.js",
66
"module": "src/index.js",

src/helpers.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,24 @@ export const buildChildList = (data, list, populate) =>
214214
* const populates = [{ child: 'owner', root: 'users' }]
215215
*
216216
* const fbWrapped = firebaseConnect([
217-
* { path: '/todos', populates } // load "todos" and matching "users" to redux
217+
* { path: '/todos', populates } // load "todos" and matching "users" to redux
218218
* ])(App)
219219
*
220220
* export default connect(({ firebase }) => ({
221221
* // this.props.todos loaded from state.firebase.data.todos
222222
* // each todo has child 'owner' populated from matching uid in 'users' root
223-
* todos: populatedDataToJS(firebase, 'todos', populates)
223+
* // for loading un-populated todos use dataToJS(firebase, 'todos')
224+
* todos: populatedDataToJS(firebase, 'todos', populates),
224225
* }))(fbWrapped)
225226
*/
226227
export const populatedDataToJS = (data, path, populates, notSetValue) => {
227228
if (!data) {
228229
return notSetValue
229230
}
230-
231+
// Handle undefined child
232+
if (!dataToJS(data, path, notSetValue)) {
233+
return undefined
234+
}
231235
const populateObjs = getPopulateObjs(populates)
232236
// reduce array of populates to object of combined populated data
233237
return reduce(

0 commit comments

Comments
 (0)