MCPcopy
hub / github.com/heroku/react-refetch / connect

Function connect

src/components/connect.js:70–451  ·  view source on GitHub ↗
(mapPropsToRequestsToProps, defaults, options)

Source from the content-addressed store, hash-verified

68}
69
70function 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)) {

Callers 10

UserWidgetFunc.tsxFile · 0.90
UserWidgetComp.tsxFile · 0.90
ContainerClass · 0.85
connect.spec.jsFile · 0.85
WithPropsClass · 0.85
ConnectContainerClass · 0.85
InnerComponentClass · 0.85
makeContainerFunction · 0.85
OriginalClass · 0.85
connectImplFunction · 0.85

Calls 4

checkTypesFunction · 0.85
getDisplayNameFunction · 0.85
refetchDataFromPropsMethod · 0.80

Tested by 1

makeContainerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…