@arrai-innovations/reactive-helpers 1.0.2 → 1.0.3

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.
@@ -1,9 +1,8 @@
1
1
  version: 2.1
2
2
  orbs:
3
- eslint: arrai/eslint@7.3.0
3
+ eslint: arrai/eslint@7.4.0
4
4
  prettier: arrai/prettier@5.1.1
5
- utils: arrai/utils@1.9.0
6
- npm: arrai/npm@2.3.2
5
+ npm: arrai/npm@2.4.1
7
6
  github: arrai/github@1.1.0
8
7
  workflows:
9
8
  test:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrai-innovations/reactive-helpers",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
5
5
  "main": "index.js",
6
6
  "directories": {
package/use/index.js CHANGED
@@ -5,4 +5,5 @@ export * from "./listSort.js";
5
5
  export * from "./listSubscription.js";
6
6
  export * from "./objectInstance.js";
7
7
  export * from "./objectSubscription.js";
8
+ export * from "./paginatedListInstance.js";
8
9
  export * from "./search.js";
@@ -48,6 +48,16 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
48
48
  assignReactiveObject(state.listInstanceCrud.args, crudArgs);
49
49
  }
50
50
 
51
+ const defaultPageCallback = (newObjects) => {
52
+ newObjects.forEach((newObject) => {
53
+ if (newObject.id in state.objects) {
54
+ updateListObject(newObject);
55
+ } else {
56
+ addListObject(newObject);
57
+ }
58
+ });
59
+ };
60
+
51
61
  async function list({ listArgs, retrieveArgs } = {}) {
52
62
  if (state.loading) {
53
63
  throw new ListError("already loading.");
@@ -66,15 +76,7 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
66
76
  crudArgs: state.listInstanceCrud.args,
67
77
  retrieveArgs,
68
78
  listArgs,
69
- pageCallback: (newObjects) => {
70
- newObjects.forEach((newObject) => {
71
- if (newObject.id in state.objects) {
72
- updateListObject(newObject);
73
- } else {
74
- addListObject(newObject);
75
- }
76
- });
77
- },
79
+ pageCallback: returnedObject.pageCallback,
78
80
  })
79
81
  .then(() => {
80
82
  return Promise.resolve(true);
@@ -125,6 +127,13 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
125
127
  delete state.objects[objectId];
126
128
  }
127
129
 
130
+ function clearList() {
131
+ state.addedOrder.splice(0);
132
+ for (const item in state.objects) {
133
+ delete state.objects[item];
134
+ }
135
+ }
136
+
128
137
  function getFakeId() {
129
138
  let fakeId;
130
139
  do {
@@ -139,13 +148,17 @@ export function useListInstance({ crudArgs, defaultListArgs = {}, defaultRetriev
139
148
  state.objectsInOrder = computed(() => state.addedOrder.map((id) => state.objects[id]));
140
149
  });
141
150
 
142
- return {
151
+ const returnedObject = {
143
152
  state,
144
153
  list,
145
154
  addListObject,
146
155
  updateListObject,
147
156
  deleteListObject,
157
+ clearList,
148
158
  effectScope: es,
149
159
  getFakeId,
160
+ defaultPageCallback,
161
+ pageCallback: defaultPageCallback,
150
162
  };
163
+ return returnedObject;
151
164
  }
@@ -0,0 +1,19 @@
1
+ import { useListInstance } from "./listInstance";
2
+
3
+ export function usePagedListInstance({ crudArgs, defaultListArgs = {}, defaultRetrieveArgs = {} }) {
4
+ const listInstance = useListInstance({ crudArgs, defaultListArgs, defaultRetrieveArgs });
5
+
6
+ listInstance.state.count = 0;
7
+
8
+ listInstance.pageCallback = (newObjects, count) => {
9
+ // display one page at a time, clear the list
10
+ listInstance.clearList();
11
+
12
+ listInstance.defaultPageCallback(newObjects);
13
+ if (count !== undefined) {
14
+ listInstance.state.count = count;
15
+ }
16
+ };
17
+
18
+ return listInstance;
19
+ }