@kaspernj/api-maker 1.0.142 → 1.0.143
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 +2 -2
- package/src/config.js +9 -3
- package/src/model-load-wrapper.jsx +9 -2
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
]
|
|
17
17
|
},
|
|
18
18
|
"name": "@kaspernj/api-maker",
|
|
19
|
-
"version": "1.0.
|
|
19
|
+
"version": "1.0.143",
|
|
20
20
|
"description": "",
|
|
21
21
|
"main": "index.js",
|
|
22
22
|
"repository": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"eslint-plugin-jest": "^26.0.0",
|
|
72
72
|
"eslint-plugin-react": "^7.23.2",
|
|
73
73
|
"i18n-on-steroids": "^1.0.2",
|
|
74
|
-
"jest": "^
|
|
74
|
+
"jest": "^28.0.3",
|
|
75
75
|
"jsdom": "^19.0.0"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/config.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
class ApiMakerConfig {
|
|
2
|
+
constructor() {
|
|
3
|
+
if (!global.apiMakerConfigGlobal) global.apiMakerConfigGlobal = {}
|
|
4
|
+
|
|
5
|
+
this.global = global.apiMakerConfigGlobal
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
getCurrenciesCollection() {
|
|
3
|
-
if (!this.
|
|
9
|
+
if (!this.global.currenciesCollection) throw new Error("Currencies collection hasn't been set")
|
|
4
10
|
|
|
5
|
-
return this.
|
|
11
|
+
return this.global.currenciesCollection
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
setCurrenciesCollection(newCurrenciesCollection) {
|
|
9
|
-
this.
|
|
15
|
+
this.global.currenciesCollection = newCurrenciesCollection
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
|
|
@@ -36,11 +36,18 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
36
36
|
this.setState({model})
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
loadNewModel() {
|
|
39
|
+
async loadNewModel() {
|
|
40
40
|
const params = Params.parse()
|
|
41
41
|
const paramKey = ModelClass.modelName().paramKey()
|
|
42
42
|
const modelDataFromParams = params[paramKey] || {}
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
let defaults = {}
|
|
45
|
+
|
|
46
|
+
if (args.newIfNoId?.defaults) {
|
|
47
|
+
defaults = await args.newIfNoId.defaults()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const modelData = Object.assign(defaults, args.newAttributes, modelDataFromParams)
|
|
44
51
|
const model = new ModelClass(modelData)
|
|
45
52
|
|
|
46
53
|
this.setState({model})
|