Skip to content

Commit

Permalink
Version v1.2.2 (#45)
Browse files Browse the repository at this point in the history
* Undefined `populatedDataToJS` children handled
* Docs updated with exposure of `auth()`
* Fixes of small errors in docs (spacing/typos)
  • Loading branch information
prescottprue committed Jan 28, 2017
1 parent fc0cce8 commit b8695b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 6 additions & 2 deletions docs/api/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ _Basic_
import { connect } from 'react-redux'
import { firebaseConnect, helpers } from 'react-redux-firebase'
const { dataToJS } = helpers
const populates = [{ child: 'owner', root: 'users' }]

const fbWrapped = firebaseConnect(['/todos'])(App)
const fbWrapped = firebaseConnect([
{ path: '/todos', populates } // load "todos" and matching "users" to redux
])(App)

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

Expand Down
9 changes: 5 additions & 4 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { pathToJS } = helpers
})
)
```
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()`.

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


## `login(credentials)`
## login(credentials)

##### Parameters

Expand Down Expand Up @@ -116,7 +117,7 @@ this.props.firebase.login({
this.props.firebase.login('someJWTAuthToken')
```

## `createUser(credentials, profile)`
## createUser(credentials, profile)

Similar to Firebase's `ref.createUser(credentials)` but with support for automatic profile setup (based on your userProfile config).

Expand Down Expand Up @@ -149,7 +150,7 @@ createNewUser({
##### Returns
[**Promise**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) with `userData`

## `logout()`
## logout()
Logout from Firebase and delete all data from the store (`state.firebase.data` and `state.firebase.auth` are set to `null`).

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

## `resetPassword(credentials)`
## resetPassword(credentials)
Calls Firebase's `ref.resetPassword(credentials)` then adds the output into redux state under `state.firebase.authError`

##### Examples
Expand Down
10 changes: 7 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,24 @@ export const buildChildList = (data, list, populate) =>
* const populates = [{ child: 'owner', root: 'users' }]
*
* const fbWrapped = firebaseConnect([
* { path: '/todos', populates } // load "todos" and matching "users" to redux
* { path: '/todos', populates } // load "todos" and matching "users" to redux
* ])(App)
*
* export default connect(({ firebase }) => ({
* // this.props.todos loaded from state.firebase.data.todos
* // each todo has child 'owner' populated from matching uid in 'users' root
* todos: populatedDataToJS(firebase, 'todos', populates)
* // for loading un-populated todos use dataToJS(firebase, 'todos')
* todos: populatedDataToJS(firebase, 'todos', populates),
* }))(fbWrapped)
*/
export const populatedDataToJS = (data, path, populates, notSetValue) => {
if (!data) {
return notSetValue
}

// Handle undefined child
if (!dataToJS(data, path, notSetValue)) {
return undefined
}
const populateObjs = getPopulateObjs(populates)
// reduce array of populates to object of combined populated data
return reduce(
Expand Down

0 comments on commit b8695b2

Please sign in to comment.