@arrai-innovations/reactive-helpers 1.1.1 → 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/tests/unit/use/listFilter.spec.js +8 -13
- package/use/listInstance.js +9 -12
- package/use/listSubscription.js +3 -3
- package/utils/getFakeId.js +15 -0
- package/utils/index.js +1 -0
package/package.json
CHANGED
|
@@ -296,7 +296,7 @@ describe("use/listFilter", () => {
|
|
|
296
296
|
name: "four",
|
|
297
297
|
},
|
|
298
298
|
});
|
|
299
|
-
const
|
|
299
|
+
const listFilterArgs = {
|
|
300
300
|
A: {
|
|
301
301
|
excludedValues: {
|
|
302
302
|
id: 1,
|
|
@@ -310,21 +310,16 @@ describe("use/listFilter", () => {
|
|
|
310
310
|
},
|
|
311
311
|
},
|
|
312
312
|
};
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
B: {
|
|
319
|
-
listInstanceB,
|
|
320
|
-
},
|
|
321
|
-
});
|
|
322
|
-
const listFilters = useListFilters(args, listInstances);
|
|
313
|
+
const listInstances = {
|
|
314
|
+
A: listInstanceA,
|
|
315
|
+
B: listInstanceB,
|
|
316
|
+
};
|
|
317
|
+
const listFilters = useListFilters(listFilterArgs, listInstances);
|
|
323
318
|
|
|
324
319
|
expect(listFilters.A.state.excludedValues).toEqual({ id: 1, name: "three" });
|
|
325
320
|
expect(listFilters.B.state.allowedValues).toEqual({ id: 2, name: "four" });
|
|
326
|
-
expect(unrefAndToRawDeep(listFilters.A.parentState)).toEqual(unrefAndToRawDeep(
|
|
327
|
-
expect(unrefAndToRawDeep(listFilters.B.parentState)).toEqual(unrefAndToRawDeep(
|
|
321
|
+
expect(unrefAndToRawDeep(listFilters.A.parentState)).toEqual(unrefAndToRawDeep(listFilterA.parentState));
|
|
322
|
+
expect(unrefAndToRawDeep(listFilters.B.parentState)).toEqual(unrefAndToRawDeep(listFilterB.parentState));
|
|
328
323
|
expect(unrefAndToRawDeep(listFilters.A.state)).toEqual(unrefAndToRawDeep(listFilterA.state));
|
|
329
324
|
expect(unrefAndToRawDeep(listFilters.B.state)).toEqual(unrefAndToRawDeep(listFilterB.state));
|
|
330
325
|
});
|
package/use/listInstance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { isEmpty } from "lodash";
|
|
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 {
|
|
@@ -11,14 +12,14 @@ export class ListError extends Error {
|
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const defaultCrud =
|
|
15
|
+
const defaultCrud = {
|
|
15
16
|
args: {},
|
|
16
17
|
list: undefined,
|
|
17
|
-
}
|
|
18
|
+
};
|
|
18
19
|
|
|
19
20
|
export function setListInstanceCrud({ list, args = {} } = {}) {
|
|
20
21
|
defaultCrud.list = list;
|
|
21
|
-
|
|
22
|
+
Object.assign(defaultCrud.args, args);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export function useListInstances(listInstanceArgs) {
|
|
@@ -43,7 +44,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
43
44
|
error: null,
|
|
44
45
|
order: [],
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
+
Object.assign(state.listInstanceCrud, cloneDeep(defaultCrud));
|
|
47
48
|
if (crudArgs) {
|
|
48
49
|
assignReactiveObject(state.listInstanceCrud.args, crudArgs);
|
|
49
50
|
}
|
|
@@ -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
|
};
|
package/use/listSubscription.js
CHANGED
|
@@ -11,9 +11,9 @@ export class ListSubscriptionError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const defaultCrud =
|
|
14
|
+
const defaultCrud = {
|
|
15
15
|
subscribe: undefined,
|
|
16
|
-
}
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
export function setListSubscriptionCrud({ subscribe }) {
|
|
19
19
|
defaultCrud.subscribe = subscribe;
|
|
@@ -36,7 +36,7 @@ export function useListSubscription({ listInstance, crudArgs, defaultListArgs, d
|
|
|
36
36
|
listSubscriptionCrud: {},
|
|
37
37
|
intendToSubscribe: false,
|
|
38
38
|
});
|
|
39
|
-
assignReactiveObject(state.listSubscriptionCrud, defaultCrud);
|
|
39
|
+
assignReactiveObject(state.listSubscriptionCrud, cloneDeep(defaultCrud));
|
|
40
40
|
|
|
41
41
|
async function subscribe({ listArgs, retrieveArgs } = {}) {
|
|
42
42
|
if (!listArgs) {
|
|
@@ -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
|
+
}
|