-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Population of list with items containing a child param that is Firebase list (`key: true`) using `populatedDataToJS` (#42) * `populatedDataToJS` supports childParam option (#48) * `populatedDataToJS` returns null for empty lists instead of `undefined` (#50) * Unit tests added to cover all cases within `populatedDataToJS`
- Loading branch information
1 parent
366c4ff
commit 8811cda
Showing
8 changed files
with
261 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
example/** | ||
examples/** | ||
coverage/** | ||
node_modules/** | ||
*.spec.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { PropTypes, Component } from 'react' | ||
import { map } from 'lodash' | ||
import TodoItem from './TodoItem' | ||
|
||
// redux/firebase | ||
import { connect } from 'react-redux' | ||
import { firebaseConnect, helpers } from 'react-redux-firebase' | ||
const { populatedDataToJS, isLoaded, pathToJS, dataToJS } = helpers | ||
const populates = [ | ||
{ child: 'owner', root: 'users' }, | ||
// or if you want a param of the populate child such as user's display name | ||
// { child: 'owner', root: 'users', childParam: 'displayName' } | ||
] | ||
|
||
@firebaseConnect([ | ||
{ path: '/projects', populates }, | ||
]) | ||
@connect( | ||
({firebase}) => ({ | ||
projects: populatedDataToJS(firebase, '/projects', populates), | ||
}) | ||
) | ||
export default class App extends Component { | ||
static propTypes = { | ||
projects: PropTypes.shape({ | ||
name: PropTypes.string, | ||
owner: PropTypes.object // string if using childParam: 'displayName' | ||
}), | ||
firebase: PropTypes.shape({ | ||
set: PropTypes.func.isRequired, | ||
remove: PropTypes.func.isRequired | ||
}) | ||
} | ||
render () { | ||
const { firebase, projects } = this.props | ||
|
||
const projectsList = (!isLoaded(projects)) | ||
? 'Loading' | ||
: (isEmpty(projects)) | ||
? 'Todo list is empty' | ||
: map(projects, (todo, id) => ( | ||
<div> | ||
Name: {project.name} | ||
Owner: { owner.displayName || owner } | ||
</div> | ||
)) | ||
return ( | ||
<div> | ||
<h2>react-redux-firebase populate snippet</h2> | ||
<div> | ||
<h4>Projects List</h4> | ||
{projectsList} | ||
</div> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.