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

Function coerceMapping

src/components/connect.js:126–163  ·  view source on GitHub ↗
(prop, mapping, parent)

Source from the content-addressed store, hash-verified

124 }
125
126 function coerceMapping(prop, mapping, parent) {
127 if (Function.prototype.isPrototypeOf(mapping)) {
128 return mapping
129 }
130
131 if (typeof mapping === 'string') {
132 mapping = { url: mapping }
133 }
134
135 invariant(isPlainObject(mapping), 'Request for `%s` must be either a string or a plain object. Instead received %s', prop, mapping)
136 invariant(mapping.hasOwnProperty('url') || mapping.hasOwnProperty('value'), 'Request object for `%s` must have `url` (or `value`) attribute.', prop)
137 invariant(!(mapping.hasOwnProperty('url') && mapping.hasOwnProperty('value')), 'Request object for `%s` must not have both `url` and `value` attributes.', prop)
138 invariant(!(mapping.hasOwnProperty('value') && typeof mapping.value === 'function' && !mapping.hasOwnProperty('comparison')), 'Request object with functional `value` must also declare `comparison`.', mapping.value, mapping.comparison)
139
140 checkTypes(mapping)
141
142 if (parent) {
143 mapping.parent = parent.parent || parent
144 }
145
146 mapping = assignDefaults(mapping, parent)
147
148 invariant(isPlainObject(mapping.meta), 'meta for `%s` must be a plain object. Instead received %s', prop, mapping.meta)
149
150 mapping.equals = function (that) {
151 that = that.parent || that
152
153 if (this.comparison !== undefined) {
154 return this.comparison === that.comparison
155 }
156
157 return [ 'value', 'url', 'method', 'headers', 'body' ].every((c) => {
158 return shallowEqual(this[c], that[c])
159 })
160 }.bind(mapping)
161
162 return mapping
163 }
164
165 function assignDefaults(mapping, parent) {
166 const rawHeaders = Object.assign({}, defaults.headers, mapping.headers)

Callers 3

coerceMappingsFunction · 0.85

Calls 4

isPlainObjectFunction · 0.85
checkTypesFunction · 0.85
assignDefaultsFunction · 0.85
shallowEqualFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…