| 195 | |
| 196 | return function wrapWithConnect(WrappedComponent) { |
| 197 | class RefetchConnect extends Component { |
| 198 | constructor(props) { |
| 199 | super(props) |
| 200 | this.version = version |
| 201 | |
| 202 | // To avoid undefined data at mount, pre-populated pending PromiseStates |
| 203 | // TODO: de-dupe with update code |
| 204 | const mappings = finalMapPropsToRequestsToProps(omitChildren(props)) || {} |
| 205 | const initDate = Object.keys(mappings).reduce((data, prop) => { |
| 206 | const mapping = mappings[prop] |
| 207 | if (Function.prototype.isPrototypeOf(mapping)) { |
| 208 | data[prop] = (...args) => { |
| 209 | this.refetchDataFromMappings(mapping(...args)) |
| 210 | } |
| 211 | } else { |
| 212 | data[prop] = PromiseState.create(mapping.meta) |
| 213 | } |
| 214 | return data |
| 215 | }, {}) |
| 216 | |
| 217 | this.state = { |
| 218 | mappings: {}, |
| 219 | startedAts: {}, |
| 220 | data: initDate, |
| 221 | refreshTimeouts: {} |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | componentDidMount() { |
| 226 | this.refetchDataFromProps() |
| 227 | } |
| 228 | |
| 229 | componentDidUpdate(prevProps) { |
| 230 | if (dependsOnProps && !shallowEqual(omitChildren(this.props), omitChildren(prevProps))) { |
| 231 | this.refetchDataFromProps() |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | shouldComponentUpdate(nextProps, nextState) { |
| 236 | return this.state.data !== nextState.data || !shallowEqual(this.props, nextProps) |
| 237 | } |
| 238 | |
| 239 | componentWillUnmount() { |
| 240 | this.clearAllRefreshTimeouts() |
| 241 | this._unmounted = true |
| 242 | } |
| 243 | |
| 244 | render() { |
| 245 | const ref = options.withRef ? 'wrappedInstance' : null |
| 246 | return ( |
| 247 | <WrappedComponent { ...this.state.data } { ...this.props } ref={ref}/> |
| 248 | ) |
| 249 | } |
| 250 | |
| 251 | getWrappedInstance() { |
| 252 | invariant(options.withRef, |
| 253 | 'To access the wrapped instance, you need to specify { withRef: true } in .options().' |
| 254 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…