@kaspernj/api-maker 1.0.134 → 1.0.137

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
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.134",
19
+ "version": "1.0.137",
20
20
  "description": "",
21
21
  "main": "index.js",
22
22
  "repository": {
@@ -126,7 +126,7 @@ module.exports = class ApiMakerCommandsPool {
126
126
  const commandData = currentPool[parseInt(commandId, 10)]
127
127
  const responseType = commandResponse.type
128
128
 
129
- if (commandResponseData) {
129
+ if (commandResponseData && typeof commandResponseData == "object") {
130
130
  const bugReportUrl = dig(commandResponseData, "bug_report_url")
131
131
 
132
132
  if (bugReportUrl) {
@@ -1,3 +1,4 @@
1
+ import EventUpdated from "./event-updated"
1
2
  import Params from "./params.cjs"
2
3
  import React from "react"
3
4
 
@@ -23,9 +24,10 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
23
24
  }
24
25
 
25
26
  async loadExistingModel() {
26
- const {modelId} = digs(this.shape, "modelId")
27
+ const {modelId} = digs(this.state, "modelId")
27
28
  const query = await ModelClass.ransack({id_eq: modelId})
28
29
 
30
+ if (args.abilities) query.abilities(args.abilities)
29
31
  if (args.preload) query.preload(args.preload)
30
32
  if (args.select) query.select(args.select)
31
33
 
@@ -37,7 +39,8 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
37
39
  loadNewModel() {
38
40
  const params = Params.parse()
39
41
  const paramKey = ModelClass.modelName().paramKey()
40
- const modelData = params[paramKey] || {}
42
+ const modelDataFromParams = params[paramKey] || {}
43
+ const modelData = Object.assign({}, args.newAttributes, modelDataFromParams)
41
44
  const model = new ModelClass(modelData)
42
45
 
43
46
  this.setState({model})
@@ -51,7 +54,14 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
51
54
  wrappedComponentProps[`${this.camelizedLower}Id`] = modelId
52
55
 
53
56
  return (
54
- <WrappedComponent {...wrappedComponentProps} {...this.props} />
57
+ <>
58
+ {model && args.eventUpdated &&
59
+ <EventUpdated model={model} onUpdated={digg(this, "onUpdated")} />
60
+ }
61
+ <WrappedComponent {...wrappedComponentProps} {...this.props} />
62
+ </>
55
63
  )
56
64
  }
65
+
66
+ onUpdated = ({model}) => this.setState({model})
57
67
  }
@@ -16,7 +16,13 @@ module.exports = class Serializer {
16
16
  }
17
17
 
18
18
  serializeArgument (arg) {
19
- if (typeof arg == "function" && arg.apiMakerType == "BaseModel") {
19
+ if (typeof arg == "object" && arg.constructor.apiMakerType == "BaseModel") {
20
+ return {
21
+ api_maker_type: "model",
22
+ model_class_name: digg(arg.modelClassData(), "name"),
23
+ model_id: arg.id()
24
+ }
25
+ } else if (typeof arg == "function" && arg.apiMakerType == "BaseModel") {
20
26
  return {
21
27
  api_maker_type: "resource",
22
28
  name: digg(arg.modelClassData(), "name")