Skip to content

Commit d865f88

Browse files
committed
Update populate docs with more clear example. Fixed typo in roles recipe.
1 parent 85bff50 commit d865f88

File tree

3 files changed

+63
-41
lines changed

3 files changed

+63
-41
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ npm install --save react-redux-firebase
4545

4646
The above install command will install the `@latest` tag. You may also use the following tags when installing to get different versions:
4747

48-
* `@next` - Next upcoming release. currently points to active progress with `v1.5.0-*` pre-releases
48+
* `@next` - Next upcoming release. Currently points to active progress with `v1.5.0-*` pre-releases
4949
* `@canary` - Most possible up to date code. Currently points to active progress with `v2.0.0-*` pre-releases. *Warning:* Syntax is different than current stable version.
5050

5151
Other versions docs are available using the dropdown on the above docs link. For quick access:
5252
* [Version `1.5.0` Docs](http://docs.react-redux-firebase.com/history/v1.5.0/)
5353
* [Version `2.0.0` Docs](http://docs.react-redux-firebase.com/history/v2.0.0/)
5454

55-
**Note:** Be aware of changes when using version that are tagged `@latest`. Please report any issues you encounter, and try to keep an eye on the [releases page](https://github.com/prescottprue/react-redux-firebase/releases) for relevant release info.
55+
Be aware of changes when using version that are tagged `@latest`. Please report any issues you encounter, and try to keep an eye on the [releases page](https://github.com/prescottprue/react-redux-firebase/releases) for updates.
5656

5757
## Use
5858

59-
**NOTE:** If you are just starting a new project, you might want to use [`v2.0.0`](http://docs.react-redux-firebase.com/history/v2.0.0/#use) has an even easier syntax. For clarity on the transition, view the [`v1` -> `v2` migration guide](http://docs.react-redux-firebase.com/history/v2.0.0/docs/v2-migration-guide.html)
59+
**Note:** If you are just starting a new project, you may want to use [`v2.0.0`](http://docs.react-redux-firebase.com/history/v2.0.0/#use) since it is has an even easier syntax. For clarity on the transition, view the [`v1` -> `v2` migration guide](http://docs.react-redux-firebase.com/history/v2.0.0/docs/v2-migration-guide.html)
6060

6161
Include `reactReduxFirebase` in your store compose function and `firebaseStateReducer` in your reducers:
6262

@@ -277,7 +277,7 @@ The [examples folder](/examples) contains full applications that can be copied/a
277277
* [populate functionality](http://react-redux-firebase.com/docs/populate) (similar to mongoDB or SQL JOIN)
278278
* `react-native` support ([web/js](http://react-redux-firebase.com/docs/recipes/react-native.html) or native modules through [`react-native-firebase`](http://docs.react-redux-firebase.com/history/v2.0.0/docs/recipes/react-native.html#native-modules))
279279
* tons of [integrations](#integrations)
280-
* [`profileDecorator`](http://react-redux-firebase.com/docs/config) - change format of profile stored on Firebase
280+
* [`profileFactory`](http://react-redux-firebase.com/docs/config) - change format of profile stored on Firebase
281281
* [`getFirebase`](http://react-redux-firebase.com/docs/thunks) - access to firebase instance that fires actions when methods are called
282282
* [access to firebase's `storage`](http://react-redux-firebase.com/docs/storage) method`
283283
* `uniqueSet` method helper for only setting if location doesn't already exist

docs/populate.md

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,62 @@
22

33
Populate allows you to replace IDs within your data with other data from Firebase. This is very useful when trying to keep your data flat. Some would call it a _join_, but it was modeled after [the mongo populate method](http://mongoosejs.com/docs/populate.html).
44

5+
Initial data from populate is placed into redux in a normalized pattern [following defined redux practice of normalizing](http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html). `populatedDataToJS` helper used in the `connect` function then builds populated data out of normalized data within redux (**NOTE:** This does not apply if you are using `v1.1.5` or earlier).
6+
7+
A basic implementation can look like so:
8+
```javascript
9+
const populates = [
10+
{ child: 'owner', root: 'users' } // replace owner with user object
11+
]
12+
13+
@firebaseConnect([
14+
// passing populates parameter also creates all necessary child queries
15+
{ path: 'todos', populates }
16+
])
17+
@connect(({ firebase }) => ({
18+
// populate original from data within separate paths redux
19+
todos: populatedDataToJS(firebase, 'todos', populates),
20+
// dataToJS(firebase, 'todos') for unpopulated todos
21+
}))
22+
```
23+
24+
## Some Things To Note
25+
26+
* Population happens in two parts:
27+
1. `firebaseConnect` - based on populate settings, queries are created for associated keys to be replaced. Query results are stored in redux under the value of `root` in the populate settings.
28+
2. `connect` - Combine original data at path with all populate data (in redux from queries created by passing populate settings to `firebaseConnect`)
29+
* Populate creates a query for each key that is being replaced
30+
* Results of populate queries are placed under their root
31+
32+
## Examples
33+
534
List of todo items where todo item can contain an owner parameter which is a user's UID like so:
635

736
```json
8-
{ text: 'Some Todo Item', owner: "Iq5b0qK2NtgggT6U3bU6iZRGyma2" }
37+
{ "text": "Some Todo Item", "owner": "Iq5b0qK2NtgggT6U3bU6iZRGyma2" }
938
```
1039

11-
Populate allows you to replace the owner parameter with another value on Firebase under that key. That value you can be a string \(number and boolean treated as string\), or an object
12-
13-
Initial data from populate is placed into redux in a normalized pattern [following defined redux practice of normalizing](http://redux.js.org/docs/recipes/reducers/NormalizingStateShape.html). `populatedDataToJS` helper used in the `connect` function then builds populated data out of normalized data within redux (**NOTE:** This does not apply if you are using `v1.1.5` or earlier).
1440

1541
##### Example Data
16-
```javascript
17-
todos: {
18-
ASDF123: {
19-
text: 'Some Todo Item',
20-
owner: "Iq5b0qK2NtgggT6U3bU6iZRGyma2"
42+
```json
43+
"todos": {
44+
"ASDF123": {
45+
"text": "Some Todo Item",
46+
"owner": "Iq5b0qK2NtgggT6U3bU6iZRGyma2"
2147
}
48+
},
49+
"displayNames": {
50+
"Iq5b0qK2NtgggT6U3bU6iZRGyma2": "Morty Smith",
51+
"6Ra53mf3U9Qmdwah6rXBMgY8smu1": "Rick Sanchez"
2252
}
23-
displayNames: {
24-
Iq5b0qK2NtgggT6U3bU6iZRGyma2: 'Scott Prue',
25-
6Ra53mf3U9Qmdwah6rXBMgY8smu1: 'Rick Sanchez'
26-
}
27-
users: {
28-
Iq5b0qK2NtgggT6U3bU6iZRGyma2: {
29-
displayName: 'Scott Prue',
30-
53+
"users": {
54+
"Iq5b0qK2NtgggT6U3bU6iZRGyma2": {
55+
"displayName": "Morty Smith",
56+
"email": "[email protected]"
3157
},
32-
6Ra53mf3U9Qmdwah6rXBMgY8smu1: {
33-
displayName: 'Rick Sanchez',
34-
58+
"6Ra53mf3U9Qmdwah6rXBMgY8smu1": {
59+
"displayName": "Rick Sanchez",
60+
"email": "[email protected]"
3561
}
3662
}
3763
```
@@ -59,7 +85,7 @@ const populates = [
5985
```javascript
6086
ASDF123: {
6187
text: 'Some Todo Item',
62-
owner: 'Scott Prue'
88+
owner: 'Morty Smith'
6389
}
6490
```
6591

@@ -88,8 +114,8 @@ const populates = [
88114
ASDF123: {
89115
text: 'Some Todo Item',
90116
owner: {
91-
displayName: 'Scott Prue',
92-
117+
displayName: 'Morty Smith',
118+
93119
}
94120
}
95121
```
@@ -104,25 +130,20 @@ const populates = [
104130
{ child: 'owner', root: 'users', childParam: 'email' }
105131
]
106132
@firebaseConnect([
107-
{
108-
path: '/todos',
109-
populates
110-
}
133+
{ path: '/todos', populates }
111134
// '/todos#populate=owner:users:email' // equivalent string notation
112135
])
113-
@connect(
114-
({ firebase }) => ({
115-
todos: populatedDataToJS(firebase, 'todos', populates),
116-
})
117-
)
136+
@connect(({ firebase }) => ({
137+
todos: populatedDataToJS(firebase, 'todos', populates),
138+
}))
118139
```
119140

120141
##### Example Result
121142

122143
```javascript
123144
ASDF123: {
124145
text: 'Some Todo Item',
125-
146+
126147
}
127148
```
128149

@@ -192,7 +213,7 @@ const config = {
192213
```
193214

194215
##### Example Result
195-
```js
216+
```javascript
196217
{
197218
users: {
198219
$uid: {

docs/recipes/roles.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ import CircularProgress from 'material-ui/CircularProgress';
120120
* @param {Component} componentToWrap - Component to wrap
121121
* @return {Component} wrappedComponent
122122
*/
123-
export const UserIsAdmin = UserAuthWrapper({ // eslint-disable-line new-cap
123+
export const UserIsAdmin = UserAuthWrapper({
124124
authSelector: ({ firebase }) => {
125125
const user = pathToJS(firebase, 'profile');
126126
if (user) {
@@ -160,11 +160,12 @@ import CircularProgress from 'material-ui/CircularProgress';
160160
* @param {Component} componentToWrap - Component to wrap
161161
* @return {Component} wrappedComponent
162162
*/
163-
export const UserHasPermission = permission => UserAuthWrapper({ // eslint-disable-line new-cap
163+
export const UserHasPermission = permission => UserAuthWrapper({
164164
authSelector: ({ firebase }) => {
165165
const user = pathToJS(firebase, 'profile');
166166
if (user) {
167-
return { ...pathToJS(firebase, 'auth'), { user } }; // attach profile for use in predicate
167+
// attach profile for use in predicate
168+
return { ...pathToJS(firebase, 'auth'), user };
168169
}
169170
return pathToJS(firebase, 'auth');
170171
},

0 commit comments

Comments
 (0)