You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information [on using recompose visit the docs](https://github.com/acdlite/recompose/blob/master/docs/API.md)
218
217
219
-
## storeAs {#populate}
218
+
### storeAs {#storeAs}
219
+
220
+
By default the results of queries are stored in redux under the path of the query. If you would like to change where the query results are stored in redux, use `storeAs`.
220
221
221
-
`storeAs` is not yet supported for the Firestore integration, but will be coming soon.
222
+
#### Examples
223
+
1. Querying the same path with different query parameters
myProjects:state.firestore.data[myProjectsReduxName], // use storeAs path to gather from redux
243
+
}))
244
+
)
245
+
```
222
246
223
247
## Populate {#populate}
224
248
225
-
Populate is not yet supported for the Firestore integration, but will be coming soon.
249
+
Populate is not yet supported for the Firestore integration, but will be coming soon. Progress can be tracked [within issue #48](https://github.com/prescottprue/redux-firestore/issues/48).
@@ -32,7 +34,8 @@ const Todos = ({ firebase, todos }) => (
32
34
exportdefaultcompose(
33
35
withFirebase,
34
36
connect((state) => ({
35
-
todos:state.firebase.data.todos
37
+
todos:state.firebase.data[todosPath],
38
+
// todos: state.firebase.ordered[todosPath] // for ordered data (array)
36
39
}))
37
40
)(Todos)
38
41
```
@@ -79,44 +82,6 @@ export default compose(
79
82
80
83
By default the results of queries are stored in redux under the path of the query. If you would like to change where the query results are stored in redux, use [`storeAs` (more below)](#storeAs).
81
84
82
-
#### Ordered vs Data (by key)
83
-
84
-
##### data {#data}
85
-
86
-
In order to get data from state by key, use `data`.
87
-
88
-
###### Examples
89
-
1. Get an object of projects by key
90
-
91
-
```js
92
-
compose(
93
-
firebaseConnect(props=> [
94
-
{ path:'projects' }
95
-
]),
96
-
connect((state, props) => ({
97
-
projects:state.firebase.data.projects,
98
-
}))
99
-
)
100
-
```
101
-
102
-
##### ordered {#ordered}
103
-
104
-
In order to get ordered data, use `ordered`
105
-
106
-
###### Examples
107
-
1. Get list of projects ordered by key
108
-
109
-
```js
110
-
compose(
111
-
firebaseConnect(props=> [
112
-
{ path:'projects', queryParams: ['orderByKey'] }
113
-
]),
114
-
connect((state, props) => ({
115
-
projects:state.firebase.ordered.projects,
116
-
}))
117
-
)
118
-
```
119
-
120
85
#### Waiting For Data To Load {#loading}
121
86
122
87
The `isLoaded` utility is helpful in checking to see if data has loaded. Check loaded state by passing it a list of props:
@@ -139,13 +104,9 @@ const Todos = ({ firebase, todos }) => {
139
104
return (
140
105
<div>
141
106
<h1>Todos</h1>
142
-
<ul>
143
-
{
144
-
Object.keys(todos).map((key, id) =>
145
-
<TodoItem key={key} id={id} todo={todos[key]}/>
146
-
)
147
-
}
148
-
</ul>
107
+
<div>
108
+
{JSON.stringify(todos, null, 2)}
109
+
</div>
149
110
</div>
150
111
)
151
112
}
@@ -154,11 +115,9 @@ export default compose(
154
115
firebaseConnect((props) => [
155
116
{ path:'todos' } // string equivalent 'todos'
156
117
]),
157
-
connect(
158
-
(state) => ({
159
-
todos:state.firebase.data.todos,
160
-
})
161
-
)
118
+
connect((state) => ({
119
+
todos:state.firebase.data.todos,
120
+
}))
162
121
)(Todos)
163
122
```
164
123
@@ -167,7 +126,7 @@ export default compose(
167
126
Using [`recompose`](https://github.com/acdlite/recompose) is a nice way to keep your react code clean and functional. Useful Higher Order Components are offered such as `branch` (similar to the `if` statements from the last example) making for much cleaner construction of your own HOCs:
168
127
169
128
```js
170
-
import { some } from'lodash'
129
+
import { get, some } from'lodash'
171
130
importLoadingSpinnerfrom'components/LoadingSpinner'// or wherever your spinner component is
172
131
import { isLoaded } from'react-redux-firebase'
173
132
import {
@@ -177,13 +136,27 @@ import {
177
136
renderComponent
178
137
} from'recompose'
179
138
180
-
// HOC that shows loading spinner component while condition is true
// show loading spinner while projects are loading
177
+
spinnerWhileLoading(['projects']),
178
+
// render empty message if projects are not found
179
+
renderIfEmpty(['projects'], EmptyMessage)
180
+
)
181
+
```
182
+
183
+
#### Formats
184
+
Two portions of redux state contain data resulting from queries. `state.firebase.ordered` contains array formatted data while `state.firebase.data` contains data store by key
185
+
186
+
##### data {#data}
187
+
188
+
In order to get data from state by key, use `data`.
189
+
190
+
###### Examples
191
+
1. Get an object of projects by key
192
+
193
+
```js
194
+
compose(
195
+
firebaseConnect(props=> [
196
+
{ path:'projects' }
197
+
]),
198
+
connect((state, props) => ({
199
+
projects:state.firebase.data.projects,
200
+
}))
201
+
)
202
+
```
203
+
204
+
##### ordered {#ordered}
205
+
206
+
In order to get ordered data, use `ordered`
207
+
208
+
###### Examples
209
+
1. Get list of projects ordered by key
210
+
211
+
```js
212
+
compose(
213
+
firebaseConnect(props=> [
214
+
{ path:'projects', queryParams: ['orderByKey'] }
215
+
]),
216
+
connect((state, props) => ({
217
+
projects:state.firebase.ordered.projects,
218
+
}))
200
219
)
201
220
```
202
221
@@ -484,7 +503,7 @@ compose(
484
503
485
504
#### Why?
486
505
487
-
Data is stored in redux under the path of the query for convince. This means that two different queries to the same path (i.e. `todos`) will both place data into `state.data.todos` even if their query parameters are different.
506
+
Data is stored in redux under the path of the query for convenience. This means that two different queries to the same path (i.e. `todos`) will both place data into `state.data.todos` even if their query parameters are different.
0 commit comments