@kaspernj/api-maker 1.0.197 → 1.0.198
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/model-load-wrapper.jsx +14 -5
package/package.json
CHANGED
|
@@ -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
|
}
|