@kaspernj/api-maker 1.0.282 → 1.0.284
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/base-model.mjs +3 -2
- package/src/collection.mjs +3 -1
- package/src/resize-observer.jsx +42 -0
package/package.json
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -420,8 +420,9 @@ export default class BaseModel {
|
|
|
420
420
|
return this._identifierKey
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
isAssociationLoaded (associationName)
|
|
424
|
-
|
|
423
|
+
isAssociationLoaded = (associationName) => this.isAssociationLoadedUnderscore(inflection.underscore(associationName))
|
|
424
|
+
isAssociationLoadedUnderscore (associationNameUnderscore) {
|
|
425
|
+
if (associationNameUnderscore in this.relationshipsCache) return true
|
|
425
426
|
return false
|
|
426
427
|
}
|
|
427
428
|
|
package/src/collection.mjs
CHANGED
|
@@ -110,7 +110,9 @@ export default class ApiMakerCollection {
|
|
|
110
110
|
|
|
111
111
|
return digg(model.relationships, reflectionNameUnderscore)
|
|
112
112
|
} else {
|
|
113
|
-
|
|
113
|
+
const relationshipsLoaded = uniqunize(Object.keys(model.relationships).concat(Object.keys(model.relationshipsCache)))
|
|
114
|
+
|
|
115
|
+
throw new Error(`${reflectionName} hasnt been loaded yet on ${model.modelClassData().name}. Loaded was: ${relationshipsLoaded.join(", ")}`)
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import PropTypes from "prop-types"
|
|
2
|
+
import PropTypesExact from "prop-types-exact"
|
|
3
|
+
|
|
4
|
+
export default class ApiMakerResizeObserver extends React.PureComponent {
|
|
5
|
+
static propTypes = PropTypesExact({
|
|
6
|
+
element: PropTypes.instanceOf(Element),
|
|
7
|
+
onResize: PropTypes.func.isRequired
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
componentDidMount() {
|
|
11
|
+
if (this.props.element) this.startObserve()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
componentDidUpdate(prevProps) {
|
|
15
|
+
if (!prevProps.element && this.props.element) {
|
|
16
|
+
this.startObserve()
|
|
17
|
+
} else if (prevProps.element && !this.props.element) {
|
|
18
|
+
this.endObserve()
|
|
19
|
+
} else if (prevProps.element != this.props.element) {
|
|
20
|
+
this.endObserve()
|
|
21
|
+
this.startObserve()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
if (this.observer) this.endObserve()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
startObserve() {
|
|
30
|
+
this.observer = new ResizeObserver(this.props.onResize)
|
|
31
|
+
this.observer.observe(this.props.element)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
endObserve() {
|
|
35
|
+
this.observer.disconnect()
|
|
36
|
+
this.observer = null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
render() {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
}
|