Skip to content

Commit 8f2c395

Browse files
author
Simen Brekken
committed
Remove pure option
Adhering with the updated react-redux API which [favors composition](reduxjs/react-redux#507)
1 parent e954cec commit 8f2c395

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm install --save react-firebase
1313

1414
## Usage
1515

16-
### `connect([mapFirebaseToProps], [options])`
16+
### `connect([mapFirebaseToProps])`
1717

1818
Connects a React component to a Firebase App reference.
1919

@@ -23,9 +23,6 @@ It does not modify the component class passed to it. Instead, it *returns* a new
2323

2424
* [`mapFirebaseToProps(props, ref, firebaseApp): subscriptions`] \(*Object or Function*): Its result, or the argument itself must be a plain object. Each value must either be a path to a location in your database, a query object or a function. If you omit it, the default implementation just injects `firebaseApp` into your component’s props.
2525

26-
* [`options`] *(Object)* If specified, further customizes the behavior of the connector.
27-
* [`pure = true`] *(Boolean)*: If true, implements `shouldComponentUpdate`, preventing unnecessary updates, assuming that the component is a “pure” component and does not rely on any input or state other than its props and subscriptions. *Defaults to `true`.*
28-
2926
#### Returns
3027

3128
A React component class that injects subscriptions and actions into your component according to the specified options.

src/connect.js

+9-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import firebase from 'firebase'
22
import invariant from 'invariant'
3-
import shallowCompare from 'react/lib/shallowCompare'
43
import { Component, createElement } from 'react'
54
import { isFunction, isPlainObject, isString, keys, pickBy, omitBy, reduce } from 'lodash'
65
import { firebaseAppShape } from './PropTypes'
@@ -21,12 +20,7 @@ const mapSubscriptionsToQueries = subscriptions => (
2120

2221
const defaultMapFirebaseToProps = (props, ref, firebaseApp) => ({ firebaseApp })
2322

24-
export default (
25-
mapFirebaseToProps = defaultMapFirebaseToProps,
26-
options = {}
27-
) => {
28-
const { pure = true } = options
29-
23+
export default (mapFirebaseToProps = defaultMapFirebaseToProps) => {
3024
const mapFirebase = (
3125
isFunction(mapFirebaseToProps) ? mapFirebaseToProps : () => mapFirebaseToProps
3226
)
@@ -70,17 +64,14 @@ export default (
7064
componentWillReceiveProps(nextProps) {
7165
const subscriptions = computeSubscriptions(this.props, this.ref, this.firebaseApp)
7266
const nextSubscriptions = computeSubscriptions(nextProps, this.ref, this.firebaseApp)
73-
74-
if (!pure || !shallowCompare(subscriptions, nextSubscriptions)) {
75-
const addedSubscriptions = pickBy(nextSubscriptions, (path, key) => !subscriptions[key])
76-
const removedSubscriptions = pickBy(subscriptions, (path, key) => !nextSubscriptions[key])
77-
const changedSubscriptions = pickBy(nextSubscriptions, (path, key) => (
78-
subscriptions[key] && subscriptions[key] !== path
79-
))
80-
81-
this.unsubscribe({ ...removedSubscriptions, ...changedSubscriptions })
82-
this.subscribe({ ...addedSubscriptions, ...changedSubscriptions })
83-
}
67+
const addedSubscriptions = pickBy(nextSubscriptions, (path, key) => !subscriptions[key])
68+
const removedSubscriptions = pickBy(subscriptions, (path, key) => !nextSubscriptions[key])
69+
const changedSubscriptions = pickBy(nextSubscriptions, (path, key) => (
70+
subscriptions[key] && subscriptions[key] !== path
71+
))
72+
73+
this.unsubscribe({ ...removedSubscriptions, ...changedSubscriptions })
74+
this.subscribe({ ...addedSubscriptions, ...changedSubscriptions })
8475
}
8576

8677
componentWillUnmount() {

src/tests/connect-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,3 @@ test('Should pass props, ref and firebase to mapFirebaseToProps', assert => {
186186
})
187187

188188
test('Should update subscriptions when props change')
189-
test('Should not re-render if options.pure is true')
190-
test('Should re-render if options.pure is false')

0 commit comments

Comments
 (0)