Skip to content

Commit 06f38f3

Browse files
committed
Refactor methods
1 parent 555ec8b commit 06f38f3

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

src/components/createConnect.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ export default function createConnect(React) {
110110
};
111111
}
112112

113-
recomputeStateProps() {
114-
const nextStateProps = computeStateProps(this.store, this.props);
113+
computeNextState(props = this.props) {
114+
return computeNextState(
115+
this.stateProps,
116+
this.dispatchProps,
117+
props
118+
);
119+
}
120+
121+
updateStateProps(props = this.props) {
122+
const nextStateProps = computeStateProps(this.store, props);
115123
if (shallowEqual(nextStateProps, this.stateProps)) {
116124
return false;
117125
}
@@ -120,8 +128,8 @@ export default function createConnect(React) {
120128
return true;
121129
}
122130

123-
recomputeDispatchProps() {
124-
const nextDispatchProps = computeDispatchProps(this.store, this.props);
131+
updateDispatchProps(props = this.props) {
132+
const nextDispatchProps = computeDispatchProps(this.store, props);
125133
if (shallowEqual(nextDispatchProps, this.dispatchProps)) {
126134
return false;
127135
}
@@ -130,25 +138,7 @@ export default function createConnect(React) {
130138
return true;
131139
}
132140

133-
computeNextState(props = this.props) {
134-
const propsHaveChanged = !shallowEqual(this.props, props);
135-
136-
if (shouldUpdateStateProps && propsHaveChanged) {
137-
this.stateProps = computeStateProps(this.store, props);
138-
}
139-
140-
if (shouldUpdateDispatchProps && propsHaveChanged) {
141-
this.dispatchProps = computeDispatchProps(this.store, props);
142-
}
143-
144-
return computeNextState(
145-
this.stateProps,
146-
this.dispatchProps,
147-
props
148-
);
149-
}
150-
151-
recomputeState(props = this.props) {
141+
updateState(props = this.props) {
152142
const nextState = this.computeNextState(props);
153143
if (!shallowEqual(nextState, this.state.props)) {
154144
this.setState({
@@ -181,7 +171,15 @@ export default function createConnect(React) {
181171

182172
componentWillReceiveProps(nextProps) {
183173
if (!shallowEqual(nextProps, this.props)) {
184-
this.recomputeState(nextProps);
174+
if (shouldUpdateStateProps) {
175+
this.updateStateProps(nextProps);
176+
}
177+
178+
if (shouldUpdateDispatchProps) {
179+
this.updateDispatchProps(nextProps);
180+
}
181+
182+
this.updateState(nextProps);
185183
}
186184
}
187185

@@ -190,8 +188,8 @@ export default function createConnect(React) {
190188
}
191189

192190
handleChange() {
193-
if (this.recomputeStateProps()) {
194-
this.recomputeState();
191+
if (this.updateStateProps()) {
192+
this.updateState();
195193
}
196194
}
197195

@@ -227,9 +225,9 @@ export default function createConnect(React) {
227225

228226
// Update the state and bindings.
229227
this.trySubscribe();
230-
this.recomputeStateProps();
231-
this.recomputeDispatchProps();
232-
this.recomputeState();
228+
this.updateStateProps();
229+
this.updateDispatchProps();
230+
this.updateState();
233231
};
234232
}
235233

0 commit comments

Comments
 (0)