@kaspernj/api-maker 1.0.197 → 1.0.200
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
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
const {digg} = require("diggerize")
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const propTypesValidator = (expectedClassName, args = {}) => (props, propName, componentName) => {
|
|
4
4
|
const prop = digg(props, propName)
|
|
5
|
+
|
|
6
|
+
if (!prop) {
|
|
7
|
+
if (args.required) {
|
|
8
|
+
return new Error(`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is \`${typeof prop}\`.`)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
const className = digg(prop, "constructor", "name")
|
|
6
15
|
|
|
7
16
|
if (className != expectedClassName) {
|
|
@@ -9,4 +18,12 @@ const instanceOfClassName = (expectedClassName) => (props, propName, componentNa
|
|
|
9
18
|
}
|
|
10
19
|
}
|
|
11
20
|
|
|
21
|
+
const instanceOfClassName = (expectedClassName) => {
|
|
22
|
+
const validator = propTypesValidator(expectedClassName)
|
|
23
|
+
|
|
24
|
+
validator.isRequired = propTypesValidator(expectedClassName, {required: true})
|
|
25
|
+
|
|
26
|
+
return validator
|
|
27
|
+
}
|
|
28
|
+
|
|
12
29
|
module.exports = instanceOfClassName
|
|
@@ -12,10 +12,14 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
componentDidMount() {
|
|
15
|
+
this.loadModel()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
loadModel = async () => {
|
|
15
19
|
if (args.newIfNoId && !this.getModelId()) {
|
|
16
|
-
this.loadNewModel()
|
|
20
|
+
return await this.loadNewModel()
|
|
17
21
|
} else if (!args.optional || this.getModelId()) {
|
|
18
|
-
this.loadExistingModel()
|
|
22
|
+
return await this.loadExistingModel()
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -23,7 +27,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
23
27
|
return this.props.match.params[this.paramsVariableName] || this.props.match.params.id
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
async
|
|
30
|
+
loadExistingModel = async () => {
|
|
27
31
|
const {modelId} = digs(this.state, "modelId")
|
|
28
32
|
const query = await ModelClass.ransack({id_eq: modelId})
|
|
29
33
|
|
|
@@ -57,6 +61,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
render() {
|
|
64
|
+
const {onUpdated, reloadModel} = digs(this, "onUpdated", "reloadModel")
|
|
60
65
|
const {model, modelId} = digs(this.state, "model", "modelId")
|
|
61
66
|
const wrappedComponentProps = {}
|
|
62
67
|
|
|
@@ -65,13 +70,17 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
65
70
|
|
|
66
71
|
return (
|
|
67
72
|
<>
|
|
73
|
+
{args.events &&
|
|
74
|
+
<EventEmitterListener event="reloadModel" events={args.events} onCalled={reloadModel} />
|
|
75
|
+
}
|
|
68
76
|
{model && args.eventUpdated &&
|
|
69
|
-
<EventUpdated model={model} onUpdated={
|
|
77
|
+
<EventUpdated model={model} onUpdated={onUpdated} />
|
|
70
78
|
}
|
|
71
79
|
<WrappedComponent {...wrappedComponentProps} {...this.props} />
|
|
72
80
|
</>
|
|
73
81
|
)
|
|
74
82
|
}
|
|
75
83
|
|
|
76
|
-
|
|
84
|
+
reloadModel = () => this.loadModel()
|
|
85
|
+
onUpdated = this.loadExistingModel
|
|
77
86
|
}
|