@arrai-innovations/reactive-helpers 1.1.2 → 1.2.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -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 getFakeId() {
140
- let fakeId;
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.some((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
+ }
package/utils/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./assignReactiveObject";
2
+ export * from "./getFakeId";
2
3
  export * from "./keyDiff";
3
4
  export * from "./set";
4
5
  export * from "./unrefAndToRawDeep";