Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Notes added to docs about storeAs and keyProp.
  • Loading branch information
Scott Prue committed Jul 10, 2017
commit 0607cfbcd5fdb6298c512c9d7b0f91e3b700d938
33 changes: 33 additions & 0 deletions docs/populate.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,39 @@ ASDF123: {
}
```

##### Keep Object's Key

Often when populating, you will want to keep the key that was originally there (before being replaced by populated value). This is supported through the use of `keyProp`:

##### Example Query
```javascript
const populates = [
{ child: 'owner', root: 'users', keyProp: 'key' }
]
@firebaseConnect([
{ path: '/todos', populates }
// '/todos#populate=owner:users' // equivalent string notation
])
@connect(
({ firebase }) => ({
todos: populatedDataToJS(firebase, 'todos', populates),
})
)
```

##### Example Result

```javascript
ASDF123: {
text: 'Some Todo Item',
owner: {
key: 'Iq5b0qK2NtgggT6U3bU6iZRGyma2',
displayName: 'Scott Prue',
email: '[email protected]'
}
}
```

### Object's Parameter

There is also the option to load a parameter from within a population object. An example of this could be populating the owner parameter with the displayName property of the user with a matching ID:
Expand Down
25 changes: 24 additions & 1 deletion docs/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

When listening to paths, it is possible to modify the query with any of [Firebase's included query methods](https://firebase.google.com/docs/reference/js/firebase.database.Query). Below are examples using Firebase query methods as well as other methods that are included (such as 'populate').

`firebaseConnect` is a Higher Order Component (wraps a provided component) that attaches listeners to relevant paths on Firebase when mounting, and removes them when unmounting.

**storeAs**

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. If you would like to store your query somewhere else in redux, use `storeAs`:

```js
@firebaseConnect([
{
path: 'todos',
storeAs: 'myTodos', // place in redux under "myTodos"
queryParams: ['orderByChild=createdBy', 'equalTo=123someuid'],
}
{
path: 'todos',
queryParams: ['limitToFirst=20'],
}
])
@connect(({ firebase }) => ({
myTodos: dataToJS(firebase, 'myTodos'), // state.firebase.data.myTodos due to storeAs
allTodos: dataToJS(firebase, 'todos') // state.firebase.data.todos since no storeAs
}))
```

## once
To load a firebase location once instead of binding, the once option can be used:

Expand Down Expand Up @@ -29,7 +53,6 @@ Ordering a list of todos by the text parameter of the todo item (placing them in
])
```


## orderByKey
Order a list by the key of each item. Since push keys contain time, this is also a way of ordering by when items were created.

Expand Down