Skip to content

Commit a8c0c48

Browse files
author
Scott Prue
committed
Merge branch 'master' into v1.5.0
2 parents 2b57b69 + ce064dc commit a8c0c48

File tree

15 files changed

+230
-104
lines changed

15 files changed

+230
-104
lines changed

docs/api/connect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const fbWrapped = firebaseConnect([
3333
// pass todos list from redux as this.props.todosList
3434
export default connect(({ firebase }) => ({
3535
todosList: dataToJS(firebase, 'todos'),
36-
profile: pathToJS(firebase, 'profile'), // pass profile data as this.props.proifle
36+
profile: pathToJS(firebase, 'profile'), // pass profile data as this.props.profile
3737
auth: pathToJS(firebase, 'auth') // pass auth data as this.props.auth
3838
}))(fbWrapped)
3939
```

docs/roadmap.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Current Minor Version (`v1.4.0`)
44

5-
**NOTE**: `v1.4.0` is still in pre-release, please check the [releases page](https://github.com/prescottprue/react-redux-firebase/releases) for the most up to date release information
6-
75
#### Features
86
* `react-native` support (including [complete example](https://github.com/prescottprue/react-redux-firebase/tree/v1.4.0-beta/examples/complete/react-native) app as well as a [create your own recipe](/docs/recipes/react-native.md))
97
* Server Side Rendering Support - [#72](https://github.com/prescottprue/react-redux-firebase/issues/72)
@@ -33,6 +31,9 @@
3331

3432

3533
## Next Minor Version (`v1.5.0`)
34+
35+
**NOTE**: `v1.5.0` is still in pre-release, please check the [releases page](https://github.com/prescottprue/react-redux-firebase/releases) for the most up to date release information
36+
3637
* Use `prop-types` package instead of `React.PropTypes` - [#122](https://github.com/prescottprue/react-redux-firebase/pull/122) - thanks [@petetnt](https://github.com/petetnt)
3738
* New Features for Population - [#132](https://github.com/prescottprue/react-redux-firebase/pull/132) - thanks [@javamonn](https://github.com/javamonn)
3839
* Lodash supported path syntax for `populates.child`
@@ -67,7 +68,7 @@
6768
**NOTE:** The changes are unconfirmed and will most likely change
6869

6970
#### Progress
70-
* [`v2.0.0-alpha`](https://github.com/prescottprue/react-redux-firebase/tree/v2.0.0-alpha) has been started, view [the branch](https://github.com/prescottprue/react-redux-firebase/tree/v2.0.0-alpha)
71+
* [`v2.0.0-alpha`](https://github.com/prescottprue/react-redux-firebase/tree/v2.0.0-alpha) has been started, view [the branch](https://github.com/prescottprue/react-redux-firebase/tree/v2.0.0-alpha)
7172

7273
#### Breaking Changes
7374
* Remove usage of `Immutable.js` and Immutable Maps (no more need for `pathToJS()` & `dataToJS()` to load data from redux)

examples/snippets/populates/App.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ import {
99
pathToJS,
1010
dataToJS
1111
} from 'react-redux-firebase'
12-
import TodoItem from './TodoItem'
1312

1413
const populates = [
1514
{ child: 'owner', root: 'users' },
1615
// or if you want a param of the populate child such as user's display name
1716
// { child: 'owner', root: 'users', childParam: 'displayName' }
1817
]
1918

19+
// gather projects and matching owners from firebase and place into redux
2020
@firebaseConnect([
21-
{ path: '/projects', populates },
21+
{ path: 'projects', populates },
2222
])
23+
// projects with owner populated from redux into component props
2324
@connect(
24-
({firebase}) => ({
25-
projects: populatedDataToJS(firebase, '/projects', populates),
25+
({ firebase }) => ({
26+
projects: populatedDataToJS(firebase, 'projects', populates),
2627
})
2728
)
2829
export default class App extends Component {
@@ -43,10 +44,10 @@ export default class App extends Component {
4344
? 'Loading'
4445
: (isEmpty(projects))
4546
? 'Todo list is empty'
46-
: map(projects, (todo, id) => (
47+
: map(projects, (project, id) => (
4748
<div>
4849
Name: {project.name}
49-
Owner: { owner.displayName || owner }
50+
Owner: { project.owner.displayName }
5051
</div>
5152
))
5253
return (
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# State Based Query Example
2+
3+
This example shows using data from redux state to be used in queries. A good example of this is querying based on the current user's UID.
4+
5+
**Note** Example does not use routing, which is what will commonly be used when creating a full application. For how to build with routing, please view [the routing recipes section of the docs.](/docs/recipes/routing.md/)
6+
7+
## What It Does
8+
9+
1. Top level component uses `firebaseConnect` function to set a listener for the `projects` path on firebase. When the listener updates it also goes and gets the object from the `users` path that matches the owner from each project. This will be used in the next step, but for now the data has been loaded into redux.
10+
```js
11+
const populates = [
12+
{ child: 'owner', root: 'users' },
13+
]
14+
15+
@firebaseConnect([
16+
{ path: 'projects', populates },
17+
])
18+
```
19+
20+
1. Next is the `@connect` function which allows us to grab from redux state and pass that data in as props to the component. In this case we are going to get projects with the owner parameter on each project replaced with the matching user:
21+
22+
```js
23+
@connect(
24+
({firebase}) => ({
25+
projects: populatedDataToJS(firebase, 'projects', populates),
26+
})
27+
)
28+
```
29+
30+
1. `isLoaded` can be used as usual to wait for data to be loaded. The projects list has the owner parameter "populated" from users.
Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,33 @@
11
import react, { Component } from 'react'
22
import PropTypes from 'prop-types'
33
import { connect } from 'react-redux'
4-
import {
5-
firebaseConnect,
6-
isLoaded,
7-
isEmpty,
8-
pathToJS,
9-
dataToJS
10-
} from 'react-redux-firebase'
11-
12-
import logo from './logo.svg'
13-
import TodoItem from './TodoItem'
14-
import './App.css'
4+
import { isLoaded, isEmpty, pathToJS } from 'react-redux-firebase'
5+
import TodosView from './Todos'
6+
import LoginView from './Todos'
157

168
class App extends Component {
179
static propTypes = {
18-
todos: PropTypes.object
10+
auth: PropTypes.object
1911
}
2012

2113
render () {
22-
const { todos } = this.props
14+
const { auth } = this.props
15+
16+
// handle initial loading of auth
17+
if (!isLoaded(auth)) {
18+
return <div>Loading...</div>
19+
}
2320

24-
const todosList = (!isLoaded(todos))
25-
? 'Loading'
26-
: (isEmpty(todos))
27-
? 'Todo list is empty'
28-
: Object.keys(todos).map((key) => (
29-
<TodoItem key={key} id={key} todo={todos[key]} />
30-
))
31-
return (
32-
<div className='App'>
33-
<div className='App-header'>
34-
<h2>react-redux-firebase Auth Based Query Demo</h2>
35-
<img src={logo} className='App-logo' alt='logo' />
36-
</div>
37-
<div className='App-todos'>
38-
<h4>
39-
Loaded From
40-
<span className='App-Url'>
41-
<a href='https://react-redux-firebase.firebaseio.com/'>
42-
react-redux-firebase.firebaseio.com
43-
</a>
44-
</span>
45-
</h4>
46-
<h4>Todos List</h4>
47-
{todosList}
48-
</div>
49-
</div>
50-
)
21+
if (isEmpty(auth)) {
22+
return <LoginView />
23+
}
24+
25+
return <TodosView auth={auth} />
5126
}
5227
}
5328

54-
const authWrappedComponent = connect(
29+
export default connect(
5530
({ firebase }) => ({
5631
auth: pathToJS(firebase, 'auth')
5732
})
5833
)(App)
59-
60-
const fbWrappedComponent = firebaseConnect(
61-
({ auth }) => ([
62-
`/todos#orderByChild=uid&equalTo=${auth ? auth.uid : ''}`
63-
/* object notation equivalent
64-
{
65-
path: '/todos',
66-
queryParams: ['orderByChild=uid', `equalTo=${auth ? auth.uid : ''}`]
67-
}
68-
*/
69-
])
70-
)(authWrappedComponent)
71-
72-
export default connect(
73-
({ firebase }) => ({
74-
todos: dataToJS(firebase, 'todos')
75-
})
76-
)(fbWrappedComponent)

examples/snippets/stateBasedQuery/README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,47 @@
22

33
This example shows using data from redux state to be used in queries. A good example of this is querying based on the current user's UID.
44

5-
## Auth Wrapping
6-
By wrapping component in connect function, you bring `auth` from redux state into a prop name "auth":
7-
8-
```js
9-
const authWrappedComponent = connect(
10-
({ firebase }) => ({
11-
auth: pathToJS(firebase, 'auth')
12-
})
13-
)(App)
14-
```
5+
**Note** Example does not use routing, which is what will commonly be used when creating a full application. For how to build with routing, please view [the routing recipes section of the docs.](/docs/recipes/routing.md/)
6+
7+
## What It Does
8+
9+
1. Top level component uses `connect` function to bring `auth` from redux state into a prop name "auth":
10+
```js
11+
const authWrappedComponent = connect(
12+
({ firebase }) => ({
13+
auth: pathToJS(firebase, 'auth')
14+
})
15+
)(App)
16+
```
17+
18+
1. That component then uses `isLoaded` and `isEmpty` to show different views based on auth state (logged in or not):
19+
20+
```js
21+
render () {
22+
const { auth } = this.props
23+
24+
// handle initial loading of auth
25+
if (!isLoaded(auth)) {
26+
return <div>Loading...</div>
27+
}
28+
29+
// auth is empty (i.e. not logged in)
30+
if (isEmpty(auth)) {
31+
return <LoginView />
32+
}
33+
34+
// auth passed down to TodosView
35+
return <TodosView auth={auth} />
36+
}
37+
```
38+
39+
1. Todos then uses `auth.uid` as part of a query for todos:
40+
41+
```js
42+
const fbWrappedComponent = firebaseConnect(({ auth }) => ([ // auth comes from props
43+
{
44+
path: 'todos',
45+
queryParams: ['orderByChild=uid', `equalTo=${auth}`]
46+
}
47+
]))(authWrappedComponent)
48+
```
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import react, { Component, PropTypes } from 'react'
2+
import { connect } from 'react-redux'
3+
import {
4+
firebaseConnect,
5+
isLoaded,
6+
isEmpty,
7+
pathToJS,
8+
dataToJS
9+
} from 'react-redux-firebase'
10+
11+
import logo from './logo.svg'
12+
import TodoItem from './TodoItem'
13+
14+
class Todos extends Component {
15+
static propTypes = {
16+
auth: PropTypes.shape({
17+
uid: PropTypes.string.isRequired
18+
}),
19+
todos: PropTypes.object
20+
}
21+
22+
render () {
23+
const { todos } = this.props
24+
25+
const todosList = (!isLoaded(todos))
26+
? 'Loading'
27+
: (isEmpty(todos))
28+
? 'Todo list is empty'
29+
: Object.keys(todos).map((key) => (
30+
<TodoItem key={key} id={key} todo={todos[key]} />
31+
))
32+
return (
33+
<div className='Todos'>
34+
{todosList}
35+
</div>
36+
)
37+
}
38+
}
39+
40+
const fbWrappedComponent = firebaseConnect(({ auth }) => ([ // auth comes from props
41+
{
42+
path: 'todos',
43+
queryParams: ['orderByChild=uid', `equalTo=${auth}`]
44+
}
45+
]))(authWrappedComponent)
46+
47+
export default connect(
48+
({ firebase }) => ({
49+
todos: dataToJS(firebase, 'todos')
50+
})
51+
)(fbWrappedComponent)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<!DOCTYPE html>
22
<html>
33
<head></head>
4-
<body><script src="./dist/app.bundle.js"></script></body>
4+
<body>
5+
<div id="app"></div>
6+
<script src="./dist/app.bundle.js"></script>
7+
</body>
58
</html>

examples/snippets/webpack2/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
2-
"name": "babel6-webpack2-react-tree-shaking",
2+
"name": "react-redux-firebase-webpack2-example",
33
"version": "0.0.0",
44
"dependencies": {
5+
"react": "15.4.1",
6+
"react-dom": "15.4.1",
7+
"react-redux": "^5.0.5",
58
"react-redux-firebase": "^1.2.5"
69
},
710
"devDependencies": {
811
"babel-core": "6.18.2",
912
"babel-loader": "6.2.8",
1013
"babel-preset-es2015": "6.18.0",
1114
"babel-preset-react": "6.16.0",
12-
"babili": "0.0.9",
13-
"babili-webpack-plugin": "0.0.7",
1415
"http-server": "0.9.0",
15-
"react": "15.4.1",
16-
"react-dom": "15.4.1",
1716
"webpack": "^2.2.1"
1817
},
1918
"scripts": {
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
import React from 'react';
1+
import React, { Component } from 'react';
22
import ReactDOM from 'react-dom';
3+
import { Provider } from 'react-redux'
4+
import createStore from './store'
35
import { firebaseConnect } from 'react-redux-firebase';
46

5-
const App = React.createClass({
7+
const store = createStore()
8+
9+
class Page extends Component {
610
render() {
711
return (
812
<div>Hello World</div>
913
);
1014
}
11-
});
15+
}
16+
17+
const ConnectedPage = firebaseConnect()(Page)
18+
19+
const App = () => (
20+
<Provider store={store}>
21+
<ConnectedPage />
22+
</Provider>
23+
);
1224

1325
ReactDOM.render(<App/>, document.querySelector('#app'));

0 commit comments

Comments
 (0)