Skip to content

Commit dcfffdd

Browse files
akofmansimenbrekken
authored andcommitted
Properly unsubscribe listeners (#22)
* Properly unsubscribe listeners * Replace omitBy with omit
1 parent a804e2d commit dcfffdd

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/connect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, createElement } from 'react'
22
import invariant from 'invariant'
3-
import { isFunction, isPlainObject, isString, keys, pickBy, omitBy, reduce } from 'lodash'
3+
import { isFunction, isPlainObject, isString, keys, pickBy, omit, reduce } from 'lodash'
44
import firebase from 'firebase/app'
55
import 'firebase/database'
66
import { firebaseAppShape } from './PropTypes'
@@ -120,11 +120,11 @@ export default (mapFirebaseToProps = defaultMapFirebaseToProps) => {
120120
const subscription = listeners[key]
121121
subscription.unsubscribe()
122122

123-
return omitBy(listeners, key)
123+
return omit(listeners, key)
124124
}, this.listeners)
125125

126126
this.setState(prevState => ({
127-
subscriptionsState: omitBy(prevState.subscriptionsState, subscriptionKeys),
127+
subscriptionsState: omit(prevState.subscriptionsState, subscriptionKeys),
128128
}))
129129
}
130130

src/tests/connect-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ test('Should unsubscribe when component unmounts', assert => {
154154
const firebaseApp = createMockApp(mockDatabase)
155155
const { container } = renderStub(mapFirebaseToProps, firebaseApp)
156156

157+
assert.notEqual(container.listeners.baz, undefined)
157158
unmountComponentAtNode(findDOMNode(container).parentNode)
159+
assert.equal(container.listeners.baz, undefined)
158160

159161
assert.end()
160162
})

0 commit comments

Comments
 (0)