(mapPropsToRequestsToProps, defaults, options)
| 68 | } |
| 69 | |
| 70 | function connect(mapPropsToRequestsToProps, defaults, options) { |
| 71 | const finalMapPropsToRequestsToProps = mapPropsToRequestsToProps || defaultMapPropsToRequestsToProps |
| 72 | const dependsOnProps = finalMapPropsToRequestsToProps.length >= 1 |
| 73 | |
| 74 | warning(finalMapPropsToRequestsToProps.length < 2, 'Passing context to `mapPropsToRequestsToProps` is no longer supported.') |
| 75 | |
| 76 | let topFetch |
| 77 | let topRequest |
| 78 | if (typeof window !== 'undefined') { |
| 79 | if (window.fetch) { topFetch = window.fetch.bind(window) } |
| 80 | if (window.Request) { topRequest = window.Request.bind(window) } |
| 81 | } else if (typeof global !== 'undefined') { |
| 82 | if (global.fetch) { topFetch = global.fetch.bind(global) } |
| 83 | if (global.Request) { topRequest = global.Request.bind(global) } |
| 84 | } else if (typeof self !== 'undefined') { |
| 85 | if (self.fetch) { topFetch = self.fetch.bind(self) } |
| 86 | if (self.Request) { topRequest = self.Request.bind(self) } |
| 87 | } |
| 88 | |
| 89 | defaults = Object.assign({ |
| 90 | buildRequest, |
| 91 | credentials: 'same-origin', |
| 92 | fetch: topFetch, |
| 93 | force: false, |
| 94 | handleResponse, |
| 95 | method: 'GET', |
| 96 | redirect: 'follow', |
| 97 | mode: 'cors', |
| 98 | refreshing: false, |
| 99 | refreshInterval: 0, |
| 100 | Request: topRequest |
| 101 | }, defaults) |
| 102 | |
| 103 | checkTypes(defaults) |
| 104 | |
| 105 | options = Object.assign({ |
| 106 | withRef: false |
| 107 | }, options) |
| 108 | |
| 109 | // Helps track hot reloading. |
| 110 | const version = nextVersion++ |
| 111 | |
| 112 | function coerceMappings(rawMappings) { |
| 113 | invariant( |
| 114 | isPlainObject(rawMappings), |
| 115 | '`mapPropsToRequestsToProps` must return an object. Instead received %s.', |
| 116 | rawMappings |
| 117 | ) |
| 118 | |
| 119 | const mappings = {} |
| 120 | Object.keys(rawMappings).forEach(prop => { |
| 121 | mappings[prop] = coerceMapping(prop, rawMappings[prop]) |
| 122 | }) |
| 123 | return mappings |
| 124 | } |
| 125 | |
| 126 | function coerceMapping(prop, mapping, parent) { |
| 127 | if (Function.prototype.isPrototypeOf(mapping)) { |
searching dependent graphs…