@arrai-innovations/reactive-helpers 1.0.5 → 1.1.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/listFilter.js +2 -14
- package/use/listInstance.js +7 -5
- package/use/listRelated.js +4 -1
- package/use/listSort.js +4 -10
- package/use/listSubscription.js +4 -1
- package/use/paginatedListInstance.js +1 -5
package/package.json
CHANGED
package/use/listFilter.js
CHANGED
|
@@ -44,20 +44,8 @@ export function useListFilter({
|
|
|
44
44
|
state.searching = toRef(textSearchIndex.state, "searching");
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
state.
|
|
48
|
-
|
|
49
|
-
return parentState.order;
|
|
50
|
-
}
|
|
51
|
-
return parentState.order.filter((id) => state.objects[id]);
|
|
52
|
-
});
|
|
53
|
-
state.objectsInOrder = computed(() => {
|
|
54
|
-
if (!parentState.order) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
const order = state.order;
|
|
58
|
-
const objects = state.objects;
|
|
59
|
-
return order.map((key) => objects[key]).filter(identity);
|
|
60
|
-
});
|
|
47
|
+
state.objectsInOrder = computed(() => parentState.order.map((id) => state.objects[id]).filter(identity));
|
|
48
|
+
state.order = computed(() => state.objectsInOrder.map((object) => `${object.id}`));
|
|
61
49
|
|
|
62
50
|
watchEffect(() => {
|
|
63
51
|
const allowedValuesEmpty = !state.allowedValues || isEmpty(state.allowedValues);
|
package/use/listInstance.js
CHANGED
|
@@ -41,7 +41,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
41
41
|
loading: undefined,
|
|
42
42
|
errored: false,
|
|
43
43
|
error: null,
|
|
44
|
-
|
|
44
|
+
order: [],
|
|
45
45
|
});
|
|
46
46
|
assignReactiveObject(state.listInstanceCrud, defaultCrud);
|
|
47
47
|
if (crudArgs) {
|
|
@@ -99,7 +99,8 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
99
99
|
throw new ListError(`addListObject: list already has object for id: ${inspect(object.id)}`, "duplicate-id");
|
|
100
100
|
}
|
|
101
101
|
state.objects[object.id] = {};
|
|
102
|
-
|
|
102
|
+
// objects keys are always strings.
|
|
103
|
+
state.order.push(`${object.id}`);
|
|
103
104
|
assignReactiveObject(state.objects[object.id], object);
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -123,12 +124,13 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
123
124
|
"missing-object"
|
|
124
125
|
);
|
|
125
126
|
}
|
|
126
|
-
|
|
127
|
+
// objects keys are always strings.
|
|
128
|
+
state.order.splice(state.order.indexOf(`${objectId}`), 1);
|
|
127
129
|
delete state.objects[objectId];
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
function clearList() {
|
|
131
|
-
state.
|
|
133
|
+
state.order.splice(0);
|
|
132
134
|
for (const item in state.objects) {
|
|
133
135
|
delete state.objects[item];
|
|
134
136
|
}
|
|
@@ -145,7 +147,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
|
|
|
145
147
|
const es = effectScope();
|
|
146
148
|
|
|
147
149
|
es.run(() => {
|
|
148
|
-
state.objectsInOrder = computed(() => state.
|
|
150
|
+
state.objectsInOrder = computed(() => state.order.map((id) => state.objects[id]));
|
|
149
151
|
});
|
|
150
152
|
|
|
151
153
|
const returnedObject = {
|
package/use/listRelated.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, effectScope, onScopeDispose, reactive, toRefs, watch } from "vue";
|
|
1
|
+
import { computed, effectScope, onScopeDispose, reactive, toRef, toRefs, watch } from "vue";
|
|
2
2
|
import { get, isArray, isEmpty, isUndefined } from "lodash";
|
|
3
3
|
import { keyDiff } from "../utils/keyDiff";
|
|
4
4
|
|
|
@@ -108,6 +108,9 @@ export function useListRelated({
|
|
|
108
108
|
const es = effectScope();
|
|
109
109
|
|
|
110
110
|
es.run(() => {
|
|
111
|
+
state.order = toRef(parentState, "order");
|
|
112
|
+
state.objectsInOrder = computed(() => state.order.map((id) => state.objects[id]));
|
|
113
|
+
|
|
111
114
|
watch(() => Object.keys(parentState.objects), parentStateObjectsWatch, { immediate: true });
|
|
112
115
|
watch(
|
|
113
116
|
[
|
package/use/listSort.js
CHANGED
|
@@ -105,9 +105,7 @@ export function useListSort({ parentState, orderByRules, sortThrottleWait = defa
|
|
|
105
105
|
|
|
106
106
|
function sortWatch() {
|
|
107
107
|
if (!state.orderByRules || !state.orderByRules.length) {
|
|
108
|
-
const serverOrderObjectsInOrder = parentState.
|
|
109
|
-
.map((e) => parentState.objects[e])
|
|
110
|
-
.filter(identity);
|
|
108
|
+
const serverOrderObjectsInOrder = parentState.order.map((e) => parentState.objects[e]).filter(identity);
|
|
111
109
|
assignReactiveObject(
|
|
112
110
|
state.order,
|
|
113
111
|
serverOrderObjectsInOrder.map((e) => String(e.id))
|
|
@@ -168,13 +166,9 @@ export function useListSort({ parentState, orderByRules, sortThrottleWait = defa
|
|
|
168
166
|
immediate: true,
|
|
169
167
|
});
|
|
170
168
|
|
|
171
|
-
watch(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
{
|
|
175
|
-
deep: true,
|
|
176
|
-
}
|
|
177
|
-
);
|
|
169
|
+
watch([toRef(state, "orderByDesc"), () => state.sortCriteria, () => parentState.order], throttledSortWatch, {
|
|
170
|
+
deep: true,
|
|
171
|
+
});
|
|
178
172
|
onScopeDispose(() => {
|
|
179
173
|
Object.keys(state.sortCriteriaWatches).forEach((key) => {
|
|
180
174
|
removeSortCriteria(key);
|
package/use/listSubscription.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { effectScope, onScopeDispose, reactive } from "vue";
|
|
1
|
+
import { effectScope, onScopeDispose, reactive, toRef } from "vue";
|
|
2
2
|
import { useListInstance } from "./listInstance";
|
|
3
3
|
import { cloneDeep, isEmpty, isObject } from "lodash";
|
|
4
4
|
import { assignReactiveObject } from "../utils/assignReactiveObject";
|
|
@@ -128,6 +128,9 @@ export function useListSubscription({ listInstance, crudArgs, defaultListArgs, d
|
|
|
128
128
|
const es = effectScope();
|
|
129
129
|
|
|
130
130
|
es.run(() => {
|
|
131
|
+
state.objects = toRef(listInstance.state, "objects");
|
|
132
|
+
state.order = toRef(listInstance.state, "order");
|
|
133
|
+
state.objectsInOrder = toRef(listInstance.state, "objectsInOrder");
|
|
131
134
|
onScopeDispose(async () => {
|
|
132
135
|
await unsubscribe();
|
|
133
136
|
});
|
|
@@ -5,10 +5,9 @@ export function usePagedListInstance({ crudArgs, defaultListArgs = {}, defaultRe
|
|
|
5
5
|
|
|
6
6
|
listInstance.state.totalRecords = 0;
|
|
7
7
|
listInstance.state.totalPages = 0;
|
|
8
|
-
listInstance.state.page = 0;
|
|
9
8
|
listInstance.state.perPage = 0;
|
|
10
9
|
|
|
11
|
-
listInstance.pageCallback = (newObjects, { totalRecords, totalPages,
|
|
10
|
+
listInstance.pageCallback = (newObjects, { totalRecords, totalPages, perPage }) => {
|
|
12
11
|
// display one page at a time, clear the list
|
|
13
12
|
listInstance.clearList();
|
|
14
13
|
|
|
@@ -19,9 +18,6 @@ export function usePagedListInstance({ crudArgs, defaultListArgs = {}, defaultRe
|
|
|
19
18
|
if (totalPages !== undefined) {
|
|
20
19
|
listInstance.state.totalPages = totalPages;
|
|
21
20
|
}
|
|
22
|
-
if (page !== undefined) {
|
|
23
|
-
listInstance.state.page = page;
|
|
24
|
-
}
|
|
25
21
|
if (perPage !== undefined) {
|
|
26
22
|
listInstance.state.perPage = perPage;
|
|
27
23
|
}
|