@kaspernj/api-maker 1.0.323 → 1.0.325

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.323",
19
+ "version": "1.0.325",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -1,6 +1,7 @@
1
1
  import Collection from "./collection.mjs"
2
2
  import debounce from "debounce"
3
3
  import {digg} from "diggerize"
4
+ import * as inflection from "inflection"
4
5
  import ModelEvents from "./model-events.mjs"
5
6
  import PropTypes from "prop-types"
6
7
  import PropTypesExact from "prop-types-exact"
@@ -45,21 +46,23 @@ const useCollection = (
45
46
 
46
47
  if (!queryName) queryName = digg(modelClass.modelClassData(), "collectionKey")
47
48
 
48
- const setModels = s.useState("models")
49
- const setOverallCount = s.useState("overallCount")
50
- const setQuery = s.useState("query")
51
- const setQueryName = s.useState("queryName", queryName)
52
- const setQueryPerKey = s.useState("queryPerKey", `${s.s.queryName}_per`)
53
- const setQueryQName = s.useState("queryQName", `${s.s.queryName}_q`)
54
- const setQuerySName = s.useState("querySName", `${s.s.queryName}_s`)
55
- const setQueryPageName = s.useState("queryPageName", `${s.s.queryName}_page`)
56
- const setQParams = s.useState("qParams")
57
- const setResult = s.useState("result")
58
- const setSearchParams = s.useState("searchParams")
59
- const setShowNoRecordsAvailableContent = s.useState("showNoRecordsAvailableContent", false)
60
- const setShowNoRecordsFoundContent = s.useState("showNoRecordsFoundContent", false)
49
+ s.useStates({
50
+ models: undefined,
51
+ overallCount: undefined,
52
+ query: undefined,
53
+ queryName,
54
+ queryPerKey: `${queryName}_per`,
55
+ queryQName: `${queryName}_q`,
56
+ querySName: `${queryName}_s`,
57
+ queryPageName: `${queryName}_page`,
58
+ qParams: undefined,
59
+ result: undefined,
60
+ searchParams: undefined,
61
+ showNoRecordsAvailableContent: false,
62
+ showNoRecordsFoundContent: false
63
+ })
64
+
61
65
  const queryParams = useQueryParams()
62
- const modelIds = s.s.models?.map((model) => model.id())
63
66
 
64
67
  let modelIdsCacheString
65
68
 
@@ -68,7 +71,7 @@ const useCollection = (
68
71
  } else if (s.s.models.length === 0) {
69
72
  modelIdsCacheString = "no-models"
70
73
  } else {
71
- modelIdsCacheString = modelIds?.join("---")
74
+ modelIdsCacheString = s.s.models.map((model) => model.cacheKey())?.join("---")
72
75
  }
73
76
 
74
77
  s.updateMeta({queryParams})
@@ -77,9 +80,11 @@ const useCollection = (
77
80
  const baseQuery = s.p.collection || s.p.modelClass.all()
78
81
  const overallCount = await baseQuery.count()
79
82
 
80
- setOverallCount(overallCount)
81
- setShowNoRecordsAvailableContent(showNoRecordsAvailableContent({overallCount}))
82
- setShowNoRecordsFoundContent(showNoRecordsFoundContent({overallCount}))
83
+ s.set({
84
+ overallCount,
85
+ showNoRecordsAvailableContent: showNoRecordsAvailableContent({overallCount}),
86
+ showNoRecordsFoundContent: showNoRecordsFoundContent({overallCount})
87
+ })
83
88
  }, [])
84
89
 
85
90
  const hasQParams = useCallback(() => {
@@ -106,8 +111,10 @@ const useCollection = (
106
111
  }
107
112
  }
108
113
 
109
- setQParams(qParamsToSet)
110
- setSearchParams(searchParams)
114
+ s.set({
115
+ qParams: qParamsToSet,
116
+ searchParams
117
+ })
111
118
  }, [])
112
119
 
113
120
  const loadModels = useCallback(async () => {
@@ -159,16 +166,20 @@ const useCollection = (
159
166
  })
160
167
  }
161
168
 
162
- setQuery(query)
163
- setResult(result)
164
- setModels(result.models())
165
- setShowNoRecordsAvailableContent(showNoRecordsAvailableContent({models}))
166
- setShowNoRecordsFoundContent(showNoRecordsFoundContent({models}))
169
+ s.set({
170
+ models: result.models(),
171
+ query,
172
+ result,
173
+ showNoRecordsAvailableContent: showNoRecordsAvailableContent({models}),
174
+ showNoRecordsFoundContent: showNoRecordsFoundContent({models})
175
+ })
167
176
  }, [])
168
177
 
169
178
  const loadModelsDebounce = useCallback(debounce(loadModels), [])
170
179
  const onModelDestroyed = useCallback((args) => {
171
- setModels(s.s.models.filter((model) => model.id() != args.model.id()))
180
+ s.set({
181
+ models: s.s.models.filter((model) => model.id() != args.model.id())
182
+ })
172
183
  }, [])
173
184
 
174
185
  const onModelUpdated = useCallback((args) => {