Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 9 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@
}]
],
"plugins": [
["lodash", { "id": ["lodash", "recompose"]}],
["lodash", { "id": ["lodash"]}],
"add-module-exports",
"transform-object-rest-spread",
"transform-object-assign",
"transform-class-properties"
"transform-class-properties",
"transform-export-extensions"
],
"env": {
"es": {
"comments": false
"comments": false,
"plugins": [
]
},
"commonjs": {
"comments": false
"comments": false,
"plugins": [
]
},
"test": {
"plugins": [
"transform-runtime",
"transform-decorators-legacy",
"transform-async-to-generator"
]
}
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ coverage/**
node_modules/**
_book/**
_site/**
test/mocha.opts
48 changes: 40 additions & 8 deletions docs/api/withFirebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
## createWithFirebase

Function that creates a Higher Order Component that
automatically listens/unListens to provided firebase paths using
React's Lifecycle hooks.
which provides `firebase` and `dispatch` as a props to React Components.

**WARNING!!** This is an advanced feature, and should only be used when
needing to access a firebase instance created under a different store key.

**Parameters**

- `storeKey` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of redux store which contains
Firebase state (state.firebase) (optional, default `'store'`)
Firebase state (`state.firebase`) (optional, default `'store'`)

**Examples**

Expand All @@ -33,15 +33,20 @@ const withFirebase = createWithFirebase('anotherStore')
export default withFirebase(SomeComponent)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** HOC that accepts a watchArray and wraps a component
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Higher Order Component which accepts an array of
watchers config and wraps a React Component

## withFirebase

**Extends React.Component**

Higher Order Component that attaches firebase to props.
Firebase is gathered from store.firebase, which is attached to store by
the store enhancer (reactReduxFirebase) in ./enhancer.
Higher Order Component that provides `firebase` and
`dispatch` as a props to React Components. Firebase is gathered from
`store.firebase`, which is attached to store by the store enhancer
(`reactReduxFirebase`) during setup.
**NOTE**: This version of the Firebase library has extra methods, config,
and functionality which give it it's capabilities such as dispatching
actions.

**Examples**

Expand All @@ -60,4 +65,31 @@ const AddData = ({ firebase: { push } }) =>
export default withFirebase(AddData)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** That accepts a component to wrap and returns the wrapped component
_Within HOC Composition_

```javascript
import { compose } from 'redux' // can also come from recompose
import { withHandlers } from 'recompose'
import { withFirebase } from 'react-redux-firebase'

const AddTodo = ({ addTodo }) =>
<div>
<button onClick={addTodo}>
Add Sample Todo
</button>
</div>

export default compose(
withFirebase(AddTodo),
withHandlers({
addTodo: props => () =>
props.firestore.add(
{ collection: 'todos' },
{ done: false, text: 'Sample' }
)
})
)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Which accepts a component to wrap and returns the
wrapped component
69 changes: 49 additions & 20 deletions docs/api/withFirestore.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,90 @@
### Table of Contents

- [createWithFirestore](#createwithfirestore)
- [withFirebase](#withfirebase)
- [withFirestore](#withfirestore)

## createWithFirestore

Function that creates a Higher Order Component that
automatically listens/unListens to provided firebase paths using
React's Lifecycle hooks.
which provides `firebase`, `firestore`, and `dispatch` to React Components.

**WARNING!!** This is an advanced feature, and should only be used when
needing to access a firebase instance created under a different store key.

**Parameters**

- `storeKey` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of redux store which contains
Firebase state (state.firebase) (optional, default `'store'`)
Firebase state (`state.firebase`) (optional, default `'store'`)

**Examples**

_Basic_

```javascript
// this.props.firebase set on App component as firebase object with helpers
import { createWithFirebase } from 'react-redux-firebase'
import { createWithFirestore } from 'react-redux-firebase'

// create withFirebase that uses another redux store
const withFirebase = createWithFirebase('anotherStore')
// create withFirestore that uses another redux store
const withFirestore = createWithFirestore('anotherStore')

// use the withFirebase to wrap a component
export default withFirebase(SomeComponent)
// use the withFirestore to wrap a component
export default withFirestore(SomeComponent)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** HOC that accepts a watchArray and wraps a component
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Higher Order Component which accepts an array of
watchers config and wraps a React Component

## withFirebase
## withFirestore

**Extends React.Component**

Higher Order Component that attaches firebase to props.
Firebase is gathered from store.firebase, which is attached to store by
the store enhancer (reactReduxFirebase) in ./enhancer.
Higher Order Component that attaches `firestore`, `firebase`
and `dispatch` as props to React Components. Firebase instance is gathered
from `store.firestore`, which is attached to store by the store enhancer
(`reduxFirestore`) during setup of
[`redux-firestore`](https://github.com/prescottprue/redux-firestore)

**Examples**

_Basic_

```javascript
import { withFirebase } from 'react-redux-firebase'
import { withFirestore } from 'react-redux-firebase'

const AddTodo = ({ firestore: { add } }) =>
<div>
<button onClick={() => add('todos', { done: false, text: 'Sample' })}>
Add Sample Todo
</button>
</div>

export default withFirestore(AddTodo)
```

_Within HOC Composition_

```javascript
import { compose } from 'redux' // can also come from recompose
import { withHandlers } from 'recompose'
import { withFirestore } from 'react-redux-firebase'

const AddData = ({ firebase: { push } }) =>
const AddTodo = ({ addTodo }) =>
<div>
<button onClick={() => push('todos', { done: false, text: 'Sample' })}>
<button onClick={addTodo}>
Add Sample Todo
</button>
</div>

export default withFirebase(AddData)
export default compose(
withFirestore(AddTodo),
withHandlers({
addTodo: props => () =>
props.firestore.add(
{ collection: 'todos' },
{ done: false, text: 'Sample' }
)
})
)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** That accepts a component to wrap and returns the wrapped component
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Which accepts a component to wrap and returns the
wrapped component
Loading