Skip to content

Commit 63627ce

Browse files
author
Fabien JUIF
authored
Fix #50 / props and context to load function parameters (#51)
1 parent eb7262d commit 63627ce

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

build/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ exports.default = function (ComposedComponent) {
110110
value: function componentWillMount() {
111111
// Load from hoc argument
112112
if (isFunction(load)) {
113-
load();
113+
load(this.props, this.context);
114114
}
115115

116116
// Load from props
117117
if (this.omitLoadInProps(this.props)) {
118-
this.props[loadFunctionName]();
118+
this.props[loadFunctionName](this.props, this.context);
119119
}
120120
}
121121
}, {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hoc-react-loader",
3-
"version": "3.1.2",
3+
"version": "3.2.0",
44
"description": "Higher order component to call a load function from props at mount.",
55
"main": "build/index.js",
66
"peerDependencies": {

src/core.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ export default (
7676
componentWillMount() {
7777
// Load from hoc argument
7878
if (isFunction(load)) {
79-
load()
79+
load(this.props, this.context)
8080
}
8181

8282
// Load from props
8383
if (this.omitLoadInProps(this.props)) {
84-
this.props[loadFunctionName]()
84+
this.props[loadFunctionName](this.props, this.context)
8585
}
8686
}
8787

src/index.spec.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import blanket from 'blanket' // eslint-disable-line
1212
import loader from './index'
1313
import TailSpin from './TailSpin'
1414

15-
1615
const Component = () => <div />
1716
const LoadingIndicator = () => <div />
1817
const getWrapped = (config, props) => {
@@ -151,13 +150,16 @@ describe('react-loader', () => {
151150
// Mount
152151
const loadProp = spy(() => {})
153152
const loadParam = spy(() => {})
154-
const loaded = getWrapped({ load: loadParam }, { load: loadProp })
153+
const props = { prop1: 'prop1', load: loadProp }
154+
const loaded = getWrapped({ load: loadParam }, props)
155155

156156
// Load function is called
157157
// Graphic component isn't called
158158
// Loader should be Dots
159159
loadProp.should.have.been.called.once
160+
loadProp.should.have.been.called.with(props)
160161
loadParam.should.have.been.called.once
162+
loadParam.should.have.been.called.with(props)
161163
expect(loaded.find(Component).node).to.be.undefined
162164
loaded.find(TailSpin).node.should.exists
163165
})
@@ -166,12 +168,14 @@ describe('react-loader', () => {
166168
// Mount
167169
const loadProp = spy(() => {})
168170
const loadPropName = 'customLoadFunction'
169-
const loaded = getWrapped({ load: loadPropName }, { [loadPropName]: loadProp })
171+
const props = { prop1: 'prop1', [loadPropName]: loadProp }
172+
const loaded = getWrapped({ load: loadPropName }, props)
170173

171174
// Load function is called
172175
// Graphic component isn't called
173176
// Loader should be Dots
174177
loadProp.should.have.been.called.once
178+
loadProp.should.have.been.called.with(props)
175179
expect(loaded.find(Component).node).to.be.undefined
176180
loaded.find(TailSpin).node.should.exists
177181
})

0 commit comments

Comments
 (0)