Skip to content

Commit aecc6b9

Browse files
committed
feat(docs): note added about order of query params - #302
1 parent db2f1ff commit aecc6b9

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

docs/api/enhancer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ along side applyMiddleware.
5353
- `config.profileParamsToPopulate` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Parameters within
5454
profile object to populate. As of `v2.0.0` data is only loaded for population, not actually automatically populated
5555
(allows access to both unpopulated and populated profile data).
56-
- `config.autoPopulateProfile` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** **NOTE**: Not yet enabled for v2.0.0. Whether or not to
56+
- `config.autoPopulateProfile` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** **NOTE**: Now enabled for v2.0.0. Whether or not to
5757
automatically populate profile with data loaded through profileParamsToPopulate config. (default: `true`)
5858
- `config.setProfilePopulateResults` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to
5959
call SET actions for data that results from populating profile to redux under

docs/queries.md

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ firebaseConnect([
151151

152152
## Query Params
153153

154+
**Note:** `orderByChild`, `orderByValue`, and `orderByPriority` enable automatic parsing of query params that follow them for convince. This means that the order of query params can affect which query is created. For example:
155+
156+
```js
157+
// Works since limitToFirst and startAt are parsed into numbers
158+
queryParams: [`limitToFirst=${limitToFirst}`, `startAt=${startAt}`, 'orderByValue'],
159+
160+
// COULD CAUSE UNEXPECTED BEHAVIOR!!! Values passed to limitToFirst and startAt will remain as strings (i.e not parsed)
161+
queryParams: ['orderByValue', `limitToFirst=${limitToFirst}`, `startAt=${startAt}`],
162+
```
163+
164+
If you would like to prevent parsing yourself (i.e. keep limit values as strings), you can pass [`notParsed`](#notParsed) as a queryParam:
165+
166+
```js
167+
// limitToFirst and startAt remain as strings and are NOT automatically parsed
168+
queryParams: ['notParsed', `limitToFirst=${limitToFirst}`, `startAt=${startAt}`, 'orderByValue'],
169+
```
170+
171+
More on [`notParsed` below](#notParsed)
172+
154173
## orderByChild
155174
To order the query by a child within each object, use orderByChild.
156175

@@ -161,8 +180,8 @@ Ordering a list of todos by the text parameter of the todo item (placing them in
161180

162181
```javascript
163182
firebaseConnect([
164-
'/todos#orderByChild=text'
165-
// { path: '/todos', queryParams: [ 'orderByChild=text' ]} // object notation
183+
{ path: '/todos', queryParams: [ 'orderByChild=text' ]}
184+
'/todos#orderByChild=text' // string notation
166185
])
167186
```
168187

@@ -177,8 +196,8 @@ Ordering a list of todos based on their key (puts them in order of when they wer
177196

178197
```javascript
179198
firebaseConnect([
180-
'/todos#orderByKey'
181-
// { path: '/todos', queryParams: [ 'orderByKey' ]} // object notation
199+
{ path: '/todos', queryParams: [ 'orderByKey' ]}
200+
// '/todos#orderByKey' // string notation
182201
])
183202
```
184203

@@ -192,8 +211,8 @@ Ordering a list of score's based on score's value
192211

193212
```javascript
194213
firebaseConnect([
195-
`scores#orderByValue`
196-
// { path: '/scores', queryParams: [ 'orderByValue' ] } // object notation
214+
{ path: '/scores', queryParams: [ 'orderByValue' ] }
215+
// `scores#orderByValue` // string notation
197216
])
198217
```
199218

@@ -207,8 +226,8 @@ Ordering a list based on priorities
207226

208227
```javascript
209228
firebaseConnect([
210-
`scores#orderByPriority`
211-
// { path: '/scores', queryParams: [ 'orderByPriority' ] } // object notation
229+
{ path: '/scores', queryParams: [ 'orderByPriority' ] }
230+
// `scores#orderByPriority` // string notation
212231
])
213232
```
214233

@@ -222,16 +241,16 @@ Limit query results to the first n number of results.
222241

223242
```javascript
224243
firebaseConnect([
225-
'/todos#limitToFirst'
226-
// { path: '/todos', queryParams: [ 'limitToFirst=1' ] } // object notation
244+
{ path: '/todos', queryParams: [ 'limitToFirst=1' ] }
245+
// '/todos#limitToFirst' // string notation
227246
])
228247
```
229248
2. Displaying only the first 10 todo items
230249

231250
```javascript
232251
firebaseConnect([
233-
'/todos#limitToFirst=10'
234-
// { path: '/todos', queryParams: [ 'orderByChild=createdBy', 'equalTo=123' ] } // object notation
252+
{ path: '/todos', queryParams: [ 'orderByChild=createdBy', 'equalTo=123' ] }
253+
// '/todos#limitToFirst=10' // string notation
235254
])
236255
```
237256

@@ -245,16 +264,16 @@ Limit query results to the last n number of results
245264

246265
```javascript
247266
firebaseConnect([
248-
'/todos#limitToLast'
249-
// { path: '/todos', queryParams: [ 'limitToLast' ] } // object notation
267+
{ path: '/todos', queryParams: [ 'limitToLast' ] }
268+
// '/todos#limitToLast' // string notation
250269
])
251270
```
252271
2. Only the **last 10** todo items
253272

254273
```javascript
255274
firebaseConnect([
256-
'/todos#limitToLast=10'
257-
// { path: '/todos', queryParams: [ 'limitToLast=10' ] } // object notation
275+
{ path: '/todos', queryParams: [ 'limitToLast=10' ] }
276+
// '/todos#limitToLast=10' // string notation
258277
])
259278
```
260279

@@ -269,22 +288,22 @@ Start query at a specific location by providing the specific number or value
269288
1. Starting at the fifth item
270289
```js
271290
firebaseConnect([
272-
'todos#startAt=5&limitToFirst=2'
273-
// { path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=2' ] } // object notation
291+
{ path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=2' ] }
292+
// 'todos#startAt=5&limitToFirst=2' // string notation
274293
])
275294
```
276295
2. Paginate results
277296
```js
278297
firebaseConnect([
279-
'todos#startAt=5&limitToFirst=10'
280-
// { path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=10' ] } // object notation
298+
{ path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=10' ] }
299+
// 'todos#startAt=5&limitToFirst=10' // string notation
281300
])
282301
```
283302
3. Non-number values
284303
```js
285304
firebaseConnect([
286-
'todos#startAt=val1&limitToFirst=10'
287-
// { path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=10' ] } // object notation
305+
{ path: '/todos', queryParams: [ 'startAt=5', 'limitToFirst=10' ] }
306+
// 'todos#startAt=val1&limitToFirst=10' // string notation
288307
])(SomeComponent)
289308
```
290309

@@ -298,8 +317,8 @@ End query at a specific location by providing the specific number or value
298317
1. Usage with startAt
299318
```js
300319
firebaseConnect([
301-
'todos#orderByChild=added&startAt=1&endAt=5'
302-
// { path: '/todos', queryParams: [ 'orderByChild=added', 'startAt=1', 'endAt=5' ] } // object notation
320+
{ path: '/todos', queryParams: [ 'orderByChild=added', 'startAt=1', 'endAt=5' ] }
321+
// 'todos#orderByChild=added&startAt=1&endAt=5' // string notation
303322
])
304323
```
305324

@@ -314,18 +333,18 @@ The following are internally parsed:
314333
* `boolean`
315334
* `number`
316335

317-
This means the actual value will be parsed instead of the string containing the value. If you do not want this to happen, look at the `notParsed` query parameter below.
336+
This means the actual value will be parsed instead of the string containing the value. If you do not want this to happen, look at the [`notParsed` query parameter below](#notParsed).
318337

319338
#### Examples
320339
1. Order by child parameter
321340
```js
322341
firebaseConnect([
323-
'todos#orderByChild=createdBy&equalTo=ASD123',
324-
// { path: '/todos', queryParams: [ 'orderByChild=createdBy', 'equalTo=ASD123' ] } // object notation
342+
{ path: '/todos', queryParams: [ 'orderByChild=createdBy', 'equalTo=ASD123' ] }
343+
// 'todos#orderByChild=createdBy&equalTo=ASD123', // string notation
325344
])
326345
```
327346

328-
## notParsed
347+
## notParsed {#notParsed}
329348

330349
Can be used to keep internal parsing from happening. Useful when attempting to search a number string using `equalTo`
331350

@@ -363,23 +382,3 @@ compose(
363382
}))
364383
)
365384
```
366-
367-
## storeAs {#storeAs}
368-
369-
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`:
370-
371-
#### Examples
372-
1. Querying the same path with different query parameters
373-
374-
```js
375-
compose(
376-
firebaseConnect(props => [
377-
{ path: 'projects' }
378-
{ path: 'projects', storeAs: 'myProjects', queryParams: ['orderByChild=uid', '123'] }
379-
]),
380-
connect(({ firebase }, props) => ({
381-
projects: populatedDataToJS(firebase, 'projects'),
382-
myProjects: populatedDataToJS(firebase, 'myProjects'), // use storeAs path to gather from redux
383-
}))
384-
)
385-
```

0 commit comments

Comments
 (0)