@kaspernj/api-maker 1.0.303 → 1.0.304
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/use-model.mjs +7 -3
package/package.json
CHANGED
package/src/use-model.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import ModelEvents from "./model-events.mjs"
|
|
2
2
|
import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
3
3
|
|
|
4
|
-
const useModel = (match, modelClassArg, argsArg) => {
|
|
4
|
+
const useModel = (match, modelClassArg, argsArg = {}) => {
|
|
5
5
|
const queryParams = useQueryParams()
|
|
6
6
|
let args, modelClass
|
|
7
7
|
|
|
8
8
|
if (typeof argsArg == "function") {
|
|
9
9
|
args = argsArg({modelClass})
|
|
10
10
|
} else {
|
|
11
|
-
args
|
|
11
|
+
args = argsArg
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if (typeof modelClassArg == "object") {
|
|
@@ -29,10 +29,14 @@ const useModel = (match, modelClassArg, argsArg) => {
|
|
|
29
29
|
|
|
30
30
|
const modelId = getModelId()
|
|
31
31
|
const modelVariableName = inflection.camelize(modelClass.modelClassData().name, true)
|
|
32
|
-
const cacheArgs = [modelId
|
|
32
|
+
const cacheArgs = [modelId]
|
|
33
33
|
const [model, setModel] = useState(undefined)
|
|
34
34
|
const [notFound, setNotFound] = useState(undefined)
|
|
35
35
|
|
|
36
|
+
if (args.cacheArgs) {
|
|
37
|
+
cacheArgs.push(...args.cacheArgs)
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
const loadExistingModel = async () => {
|
|
37
41
|
const query = await modelClass.ransack({id_eq: modelId})
|
|
38
42
|
|