@arrai-innovations/reactive-helpers 14.1.0 → 16.0.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/config/listCrud.js +19 -4
- package/config/objectCrud.js +2 -2
- package/docs/README.md +1 -0
- package/docs/config/listCrud.md +70 -6
- package/docs/config/objectCrud.md +13 -3
- package/docs/use/list.md +54 -0
- package/docs/use/listInstance.md +31 -4
- package/docs/use/listSubscription.md +3 -1
- package/docs/use/loadingError.md +16 -6
- package/docs/use/object.md +4 -4
- package/docs/use/objectCalculated.md +4 -4
- package/docs/use/objectInstance.md +59 -17
- package/docs/use/objectRelated.md +4 -4
- package/docs/use/objectSubscription.md +2 -2
- package/docs/utils/classes.md +1 -1
- package/docs/utils/keepAliveTry.md +51 -0
- package/index.js +1 -0
- package/package.json +2 -1
- package/tests/unit/config/listCrud.spec.js +3 -1
- package/tests/unit/use/listCalculated.spec.js +4 -4
- package/tests/unit/use/listFilter.spec.js +11 -9
- package/tests/unit/use/listInstance.spec.js +385 -22
- package/tests/unit/use/listRelated.spec.js +5 -5
- package/tests/unit/use/listSearch.spec.js +14 -11
- package/tests/unit/use/listSort.spec.js +8 -0
- package/tests/unit/use/listSubscription.spec.js +64 -0
- package/tsconfig.json +2 -2
- package/typedoc.json +0 -1
- package/use/cancellableIntent.js +21 -2
- package/use/list.js +28 -3
- package/use/listInstance.js +39 -4
- package/use/listKeys.js +1 -0
- package/use/listSubscription.js +18 -8
- package/use/loadingError.js +5 -1
- package/use/objectCalculated.js +42 -38
- package/use/objectInstance.js +9 -9
- package/use/paginatedListInstance.js +6 -3
- package/utils/keepAliveTry.js +28 -0
|
@@ -225,7 +225,7 @@ A function to be used instead of the default crud retrieve function.
|
|
|
225
225
|
|
|
226
226
|
###### crud.subscribe()
|
|
227
227
|
|
|
228
|
-
> **subscribe**: (`SubscribeArgs`) => `void`
|
|
228
|
+
> **subscribe**: (`SubscribeArgs`) => `void` & `object`
|
|
229
229
|
|
|
230
230
|
A function to be used instead of the default crud subscribe function.
|
|
231
231
|
|
|
@@ -235,7 +235,7 @@ A function to be used instead of the default crud subscribe function.
|
|
|
235
235
|
|
|
236
236
|
###### Returns
|
|
237
237
|
|
|
238
|
-
`void`
|
|
238
|
+
`void` & `object`
|
|
239
239
|
|
|
240
240
|
###### crud.update()
|
|
241
241
|
|
package/docs/utils/classes.md
CHANGED
|
@@ -59,7 +59,7 @@ Normalize various ways of specifying CSS classes into an object for use in Vue.j
|
|
|
59
59
|
|
|
60
60
|
#### Parameters
|
|
61
61
|
|
|
62
|
-
• ...**classes**: (`string` \| `string`[] \| `string`[][] \| `
|
|
62
|
+
• ...**classes**: (`string` \| `string`[] \| `object` \| `string`[][] \| `Ref`\<`string` \| `string`[] \| `string`[][]\>)[]
|
|
63
63
|
|
|
64
64
|
A mixed array containing multiple ways of specifying CSS classes.
|
|
65
65
|
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[**@arrai-innovations/reactive-helpers**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@arrai-innovations/reactive-helpers](../README.md) / utils/keepAliveTry
|
|
6
|
+
|
|
7
|
+
# utils/keepAliveTry
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
### tryOnActivated()
|
|
12
|
+
|
|
13
|
+
> **tryOnActivated**(`fn`, `target`?): `void`
|
|
14
|
+
|
|
15
|
+
If there is an active component, set up an onActivated hook.
|
|
16
|
+
|
|
17
|
+
#### Parameters
|
|
18
|
+
|
|
19
|
+
• **fn**: `Function`
|
|
20
|
+
|
|
21
|
+
The function to call.
|
|
22
|
+
|
|
23
|
+
• **target?**: `any`
|
|
24
|
+
|
|
25
|
+
The target to call the function on.
|
|
26
|
+
|
|
27
|
+
#### Returns
|
|
28
|
+
|
|
29
|
+
`void`
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### tryOnDeactivated()
|
|
34
|
+
|
|
35
|
+
> **tryOnDeactivated**(`fn`, `target`?): `void`
|
|
36
|
+
|
|
37
|
+
If there is an active component, set up an onDeactivated hook.
|
|
38
|
+
|
|
39
|
+
#### Parameters
|
|
40
|
+
|
|
41
|
+
• **fn**: `Function`
|
|
42
|
+
|
|
43
|
+
The function to call.
|
|
44
|
+
|
|
45
|
+
• **target?**: `any`
|
|
46
|
+
|
|
47
|
+
The target to call the function on.
|
|
48
|
+
|
|
49
|
+
#### Returns
|
|
50
|
+
|
|
51
|
+
`void`
|
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export * from "./utils/compact.js";
|
|
|
28
28
|
export * from "./utils/deleteKey.js";
|
|
29
29
|
export * from "./utils/flattenPaths.js";
|
|
30
30
|
export * from "./utils/getFakePk.js";
|
|
31
|
+
export * from "./utils/keepAliveTry.js";
|
|
31
32
|
export * from "./utils/keyDiff.js";
|
|
32
33
|
export * from "./utils/loadingCombine.js";
|
|
33
34
|
export * from "./utils/relatedCalculatedHelpers.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrai-innovations/reactive-helpers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"vue-deepunref": "^1.0.1"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
+
"@vueuse/core": "^11.2.0",
|
|
68
69
|
"lodash-es": "^4.17.21",
|
|
69
70
|
"vue": "^3.4.30"
|
|
70
71
|
}
|
|
@@ -30,7 +30,9 @@ describe("config/listCrud.js", () => {
|
|
|
30
30
|
*/
|
|
31
31
|
const retrievedCrud = reactive({});
|
|
32
32
|
expect(() => getListCrud(retrievedCrud)).not.toThrow();
|
|
33
|
-
expect(new Set(Object.keys(retrievedCrud))).toEqual(
|
|
33
|
+
expect(new Set(Object.keys(retrievedCrud))).toEqual(
|
|
34
|
+
new Set(["list", "bulkDelete", "executeAction", "subscribe", "args"])
|
|
35
|
+
);
|
|
34
36
|
expect(retrievedCrud.args).not.toBe(crud.args);
|
|
35
37
|
expect(retrievedCrud.args).toEqual(crud.args);
|
|
36
38
|
expect(retrievedCrud.list).toBe(crud.list);
|
|
@@ -15,8 +15,8 @@ describe("use/listCalculated", () => {
|
|
|
15
15
|
AwaitNot = watchesModule.AwaitNot;
|
|
16
16
|
});
|
|
17
17
|
it("should return a list of calculated items", async () => {
|
|
18
|
-
const mainListInstance = useListInstance({ props: { pkKey: "id" } });
|
|
19
|
-
const calculatedListInstance = useListInstance({ props: { pkKey: "id" } });
|
|
18
|
+
const mainListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
19
|
+
const calculatedListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
20
20
|
mainListInstance.addListObject({
|
|
21
21
|
id: "1",
|
|
22
22
|
name: "main",
|
|
@@ -77,8 +77,8 @@ describe("use/listCalculated", () => {
|
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
it("should allow calculated objects to return results based on related objects", async () => {
|
|
80
|
-
const mainListInstance = useListInstance({ props: { pkKey: "id" } });
|
|
81
|
-
const relatedListInstance = useListInstance({ props: { pkKey: "id" } });
|
|
80
|
+
const mainListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
81
|
+
const relatedListInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
82
82
|
mainListInstance.addListObject({
|
|
83
83
|
id: "1",
|
|
84
84
|
name: "main",
|
|
@@ -19,7 +19,7 @@ describe("use/listFilter", () => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it("should match an allowed filter function", async () => {
|
|
22
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
22
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
23
23
|
const filter = useListFilter({
|
|
24
24
|
parentState: list.state,
|
|
25
25
|
allowedFilter: (object) => object.id === 1 || object.id === 3,
|
|
@@ -65,7 +65,7 @@ describe("use/listFilter", () => {
|
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
it("should match an excluded filter function", async () => {
|
|
68
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
68
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
69
69
|
const filter = useListFilter({
|
|
70
70
|
parentState: list.state,
|
|
71
71
|
excludedFilter: (object) => object.id == 2 || object.id == 4,
|
|
@@ -111,7 +111,7 @@ describe("use/listFilter", () => {
|
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
it("no args: returns objects unfiltered", async () => {
|
|
114
|
-
const listInstance = useListInstance({ props: { pkKey: "id" } });
|
|
114
|
+
const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
115
115
|
const listItems = [
|
|
116
116
|
{ id: 4, name: "four", has_things: true },
|
|
117
117
|
{ id: 2, name: "two", has_things: true },
|
|
@@ -135,7 +135,7 @@ describe("use/listFilter", () => {
|
|
|
135
135
|
vi.resetAllMocks();
|
|
136
136
|
const orderByRules = [{ key: "name", desc: true, localeCompare: false }];
|
|
137
137
|
const sortThrottleWait = 0;
|
|
138
|
-
const listInstance = useListInstance({ props: { pkKey: "id" } });
|
|
138
|
+
const listInstance = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
139
139
|
const listItems = [
|
|
140
140
|
{ id: 4, name: "four", has_things: true },
|
|
141
141
|
{ id: 2, name: "two", has_things: true },
|
|
@@ -177,6 +177,7 @@ describe("use/listFilter", () => {
|
|
|
177
177
|
fields,
|
|
178
178
|
},
|
|
179
179
|
},
|
|
180
|
+
keepOldPages: false,
|
|
180
181
|
});
|
|
181
182
|
const listInstanceB = useListInstance({
|
|
182
183
|
props: {
|
|
@@ -186,6 +187,7 @@ describe("use/listFilter", () => {
|
|
|
186
187
|
fields,
|
|
187
188
|
},
|
|
188
189
|
},
|
|
190
|
+
keepOldPages: false,
|
|
189
191
|
});
|
|
190
192
|
const excludedFilter = (object) => object.id === 1 || object.name === "three";
|
|
191
193
|
const allowedFilter = (object) => object.id === 2 || object.name === "four";
|
|
@@ -223,7 +225,7 @@ describe("use/listFilter", () => {
|
|
|
223
225
|
});
|
|
224
226
|
describe("useListFilters updates index when", () => {
|
|
225
227
|
it("parentInstance.objects is updated", async () => {
|
|
226
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
228
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
227
229
|
const filter = useListFilter({
|
|
228
230
|
parentState: list.state,
|
|
229
231
|
allowedFilter: (object) => !!object.allowed?.every((e) => e),
|
|
@@ -264,8 +266,8 @@ describe("use/listFilter", () => {
|
|
|
264
266
|
});
|
|
265
267
|
});
|
|
266
268
|
it("parentInstance.relatedObjects is updated", async () => {
|
|
267
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
268
|
-
const relatedList = useListInstance({ props: { pkKey: "id" } });
|
|
269
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
270
|
+
const relatedList = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
269
271
|
const related = useListRelated({
|
|
270
272
|
parentState: list.state,
|
|
271
273
|
relatedObjectsRules: {
|
|
@@ -320,7 +322,7 @@ describe("use/listFilter", () => {
|
|
|
320
322
|
});
|
|
321
323
|
});
|
|
322
324
|
it("parentInstance.calculatedObjects is updated", async () => {
|
|
323
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
325
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
324
326
|
const calculated = useListCalculated({
|
|
325
327
|
parentState: list.state,
|
|
326
328
|
calculatedObjectsRules: reactive({
|
|
@@ -364,7 +366,7 @@ describe("use/listFilter", () => {
|
|
|
364
366
|
});
|
|
365
367
|
});
|
|
366
368
|
it("you can use nested useListFilters", async () => {
|
|
367
|
-
const list = useListInstance({ props: { pkKey: "id" } });
|
|
369
|
+
const list = useListInstance({ props: { pkKey: "id" }, keepOldPages: false });
|
|
368
370
|
|
|
369
371
|
function filter1AllowedFilter(object) {
|
|
370
372
|
return object.has_things && object.has_stuff;
|