@arrai-innovations/reactive-helpers 1.1.2 → 1.2.0
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/use/listInstance.js +4 -7
- package/utils/getFakeId.js +15 -0
- package/utils/index.js +1 -0
package/package.json
CHANGED
package/use/listInstance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cloneDeep, isEmpty } from "lodash";
|
|
2
2
|
import { computed, effectScope, reactive, unref } from "vue";
|
|
3
3
|
import { assignReactiveObject } from "../utils/assignReactiveObject";
|
|
4
|
+
import { getFakeId } from "../utils/getFakeId";
|
|
4
5
|
import inspect from "browser-util-inspect";
|
|
5
6
|
|
|
6
7
|
export class ListError extends Error {
|
|
@@ -136,12 +137,8 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
do {
|
|
142
|
-
fakeId = Math.floor(Math.random() * Number.MIN_SAFE_INTEGER);
|
|
143
|
-
} while (fakeId in state.objects);
|
|
144
|
-
return fakeId;
|
|
140
|
+
function ourGetFakeId() {
|
|
141
|
+
return getFakeId(state.objects);
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
const es = effectScope();
|
|
@@ -158,7 +155,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
158
155
|
deleteListObject,
|
|
159
156
|
clearList,
|
|
160
157
|
effectScope: es,
|
|
161
|
-
getFakeId,
|
|
158
|
+
getFakeId: ourGetFakeId,
|
|
162
159
|
defaultPageCallback,
|
|
163
160
|
pageCallback: defaultPageCallback,
|
|
164
161
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isArray } from "lodash";
|
|
2
|
+
|
|
3
|
+
export function getFakeId(arrayOrObject) {
|
|
4
|
+
let fakeId;
|
|
5
|
+
let test;
|
|
6
|
+
if (isArray(arrayOrObject)) {
|
|
7
|
+
test = () => arrayOrObject.any((item) => item.id === fakeId);
|
|
8
|
+
} else {
|
|
9
|
+
test = () => fakeId in arrayOrObject;
|
|
10
|
+
}
|
|
11
|
+
do {
|
|
12
|
+
fakeId = Math.floor(Math.random() * Number.MIN_SAFE_INTEGER);
|
|
13
|
+
} while (test());
|
|
14
|
+
return fakeId;
|
|
15
|
+
}
|