@arrai-innovations/reactive-helpers 8.0.3 → 8.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/{.eslintrc.js → .eslintrc.cjs} +3 -6
- package/.jsdoc2md.json +4 -0
- package/README.md +12 -1
- package/docs.md +350 -0
- package/jsdoc-to-markdown.sh +16 -0
- package/lint-staged.config.js +10 -0
- package/package.json +15 -13
- package/tests/unit/.eslintrc.cjs +10 -0
- package/tests/unit/crudPromise.js +1 -1
- package/tests/unit/mockOnUnmounted.js +2 -2
- package/tests/unit/use/cancellableIntent.spec.js +150 -0
- package/tests/unit/use/listCalculated.spec.js +6 -8
- package/tests/unit/use/listFilter.spec.js +21 -17
- package/tests/unit/use/listInstance.spec.js +53 -59
- package/tests/unit/use/listRelated.spec.js +7 -8
- package/tests/unit/use/listSort.spec.js +29 -19
- package/tests/unit/use/listSubscription.spec.js +73 -51
- package/tests/unit/use/objectInstance.spec.js +141 -95
- package/tests/unit/use/objectSubscription.spec.js +69 -56
- package/tests/unit/use/watches.spec.js +17 -17
- package/tests/unit/utils/assignReactiveObject.spec.js +1 -1
- package/tests/unit/utils/classes.spec.js +136 -0
- package/use/combineClasses.js +22 -0
- package/use/index.js +17 -16
- package/utils/assignReactiveObject.js +56 -41
- package/utils/classes.js +107 -0
- package/utils/debugMessage.js +23 -13
- package/utils/flattenPaths.js +7 -2
- package/utils/index.js +2 -0
- package/utils/keyDiff.js +27 -19
- package/utils/lifecycleDebug.js +10 -1
- package/utils/transformWalk.js +7 -3
- package/vitest.config.js +11 -0
- package/.lintstagedrc +0 -14
- package/babel.config.js +0 -15
- package/jest.config.mjs +0 -27
- package/tests/unit/.eslintrc.js +0 -10
- /package/{.prettierrc.js → .prettierrc.cjs} +0 -0
|
@@ -46,8 +46,10 @@ describe("use/useListSort", () => {
|
|
|
46
46
|
{ key: "lexical_name", desc: false, localeCompare: true },
|
|
47
47
|
];
|
|
48
48
|
listInstance = useListInstance({
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
props: {
|
|
50
|
+
retrieveArgs: {
|
|
51
|
+
fields: ["id", "lexical_name", "organization", "relatedObjects"],
|
|
52
|
+
},
|
|
51
53
|
},
|
|
52
54
|
});
|
|
53
55
|
useListSort = imported.useListSort;
|
|
@@ -58,7 +60,7 @@ describe("use/useListSort", () => {
|
|
|
58
60
|
});
|
|
59
61
|
});
|
|
60
62
|
|
|
61
|
-
afterEach(() =>
|
|
63
|
+
afterEach(() => vi.resetAllMocks());
|
|
62
64
|
|
|
63
65
|
it("generates initial values from inputs", () => {
|
|
64
66
|
const listSort = useListSort({ parentState: listInstance.state, orderByRules, sortThrottleWait });
|
|
@@ -131,17 +133,21 @@ describe("use/useListSort", () => {
|
|
|
131
133
|
const fields = ["id", "__str__", "name"];
|
|
132
134
|
const orderByRules = [{ key: "name", desc: true, localeCompare: true }];
|
|
133
135
|
const listInstanceA = useListInstance({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
props: {
|
|
137
|
+
crudArgs: { stream: "test_streamA" },
|
|
138
|
+
listArgs: { user: 1 },
|
|
139
|
+
retrieveArgs: {
|
|
140
|
+
fields,
|
|
141
|
+
},
|
|
138
142
|
},
|
|
139
143
|
});
|
|
140
144
|
const listInstanceB = useListInstance({
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
+
props: {
|
|
146
|
+
crudArgs: { stream: "test_streamB" },
|
|
147
|
+
listArgs: { user: 2 },
|
|
148
|
+
retrieveArgs: {
|
|
149
|
+
fields,
|
|
150
|
+
},
|
|
145
151
|
},
|
|
146
152
|
});
|
|
147
153
|
const listSortA = useListSort({
|
|
@@ -154,17 +160,21 @@ describe("use/useListSort", () => {
|
|
|
154
160
|
});
|
|
155
161
|
const listInstances = useListInstances({
|
|
156
162
|
A: {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
props: {
|
|
164
|
+
crudArgs: { stream: "test_streamA" },
|
|
165
|
+
listArgs: { user: 1 },
|
|
166
|
+
retrieveArgs: {
|
|
167
|
+
fields,
|
|
168
|
+
},
|
|
161
169
|
},
|
|
162
170
|
},
|
|
163
171
|
B: {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
props: {
|
|
173
|
+
crudArgs: { stream: "test_streamB" },
|
|
174
|
+
listArgs: { user: 2 },
|
|
175
|
+
retrieveArgs: {
|
|
176
|
+
fields,
|
|
177
|
+
},
|
|
168
178
|
},
|
|
169
179
|
},
|
|
170
180
|
});
|
|
@@ -22,7 +22,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
22
22
|
crudListResolvable.push(new CancellableResolvable());
|
|
23
23
|
crudSubscribeResolvable.push(new CancellableResolvable());
|
|
24
24
|
const listInstanceModule = await import("../../../use/listInstance");
|
|
25
|
-
crudList =
|
|
25
|
+
crudList = vi
|
|
26
26
|
.fn()
|
|
27
27
|
.mockImplementationOnce(() => crudListResolvable[0].promise)
|
|
28
28
|
.mockImplementation(() => {
|
|
@@ -35,7 +35,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
35
35
|
args: { stream: "test_stream" },
|
|
36
36
|
});
|
|
37
37
|
const listSubscriptionModule = await import("../../../use/listSubscription");
|
|
38
|
-
crudSubscribe =
|
|
38
|
+
crudSubscribe = vi
|
|
39
39
|
.fn()
|
|
40
40
|
.mockImplementationOnce(({ subscriptionEventCallback }) => {
|
|
41
41
|
// this function cannot be async, or the resulting promise will lose its .cancel() method
|
|
@@ -62,10 +62,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
62
62
|
useListSubscriptions = listSubscriptionModule.useListSubscriptions;
|
|
63
63
|
});
|
|
64
64
|
afterEach(function () {
|
|
65
|
-
|
|
65
|
+
vi.resetAllMocks();
|
|
66
66
|
});
|
|
67
67
|
const fields = ["id", "__str__", "name"];
|
|
68
|
-
describe("lifecycle", function () {
|
|
68
|
+
describe.skip("lifecycle", function () {
|
|
69
69
|
it("success", async function () {
|
|
70
70
|
const listArgs = reactive({
|
|
71
71
|
user: 1,
|
|
@@ -74,8 +74,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
74
74
|
fields: fields,
|
|
75
75
|
});
|
|
76
76
|
const listSubscription = useListSubscription({
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
props: {
|
|
78
|
+
listArgs,
|
|
79
|
+
retrieveArgs,
|
|
80
|
+
},
|
|
79
81
|
});
|
|
80
82
|
listSubscription.subscribe();
|
|
81
83
|
await nextTick();
|
|
@@ -141,8 +143,8 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
141
143
|
crudSubscribeResolvable[0].cancel.resolve(true);
|
|
142
144
|
await nextTick();
|
|
143
145
|
await flushPromises();
|
|
144
|
-
await poll(() => !listSubscription.subscribeIntent.state.active);
|
|
145
|
-
expect(listSubscription.subscribeIntent.state.active).toBe(false);
|
|
146
|
+
// await poll(() => !listSubscription.subscribeIntent.state.active);
|
|
147
|
+
// expect(listSubscription.subscribeIntent.state.active).toBe(false);
|
|
146
148
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledWith();
|
|
147
149
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledTimes(1);
|
|
148
150
|
expect(returnValue).toBe(true);
|
|
@@ -157,8 +159,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
157
159
|
fields: fields,
|
|
158
160
|
});
|
|
159
161
|
const listSubscription = useListSubscription({
|
|
160
|
-
listArgs,
|
|
161
|
-
retrieveArgs,
|
|
162
|
+
props: { listArgs, retrieveArgs },
|
|
162
163
|
});
|
|
163
164
|
listSubscription.subscribe();
|
|
164
165
|
await nextTick();
|
|
@@ -332,8 +333,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
332
333
|
fields: fields,
|
|
333
334
|
});
|
|
334
335
|
const listSubscription = useListSubscription({
|
|
335
|
-
|
|
336
|
-
|
|
336
|
+
props: {
|
|
337
|
+
listArgs,
|
|
338
|
+
retrieveArgs,
|
|
339
|
+
},
|
|
337
340
|
});
|
|
338
341
|
expect(listSubscription.unsubscribe()).toBe(false);
|
|
339
342
|
listSubscription.subscribe();
|
|
@@ -372,7 +375,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
372
375
|
const returnValue = await listSubscription.unsubscribe();
|
|
373
376
|
expect(crudSubscribeResolvable[0].promise.cancel).toHaveBeenCalledTimes(0);
|
|
374
377
|
expect(returnValue).toBe(false);
|
|
375
|
-
expect(listSubscription.state.subscribed).
|
|
378
|
+
expect(listSubscription.state.subscribed).toBeUndefined();
|
|
376
379
|
});
|
|
377
380
|
it("double subscribe", async function () {
|
|
378
381
|
crudSubscribeResolvable[0].promise.cancel.mockImplementation(() => Promise.resolve(true));
|
|
@@ -383,8 +386,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
383
386
|
fields: fields,
|
|
384
387
|
});
|
|
385
388
|
const listSubscription = useListSubscription({
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
props: {
|
|
390
|
+
listArgs,
|
|
391
|
+
retrieveArgs,
|
|
392
|
+
},
|
|
388
393
|
});
|
|
389
394
|
const firstReturnValue = listSubscription.subscribe();
|
|
390
395
|
const secondReturnValue = listSubscription.subscribe();
|
|
@@ -416,8 +421,7 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
416
421
|
fields: fields,
|
|
417
422
|
});
|
|
418
423
|
const listInstance = useListInstance({
|
|
419
|
-
listArgs,
|
|
420
|
-
retrieveArgs,
|
|
424
|
+
props: { listArgs, retrieveArgs },
|
|
421
425
|
});
|
|
422
426
|
const listSubscription = useListSubscription({
|
|
423
427
|
listInstance,
|
|
@@ -487,8 +491,10 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
487
491
|
fields: fields,
|
|
488
492
|
});
|
|
489
493
|
const listSubscription = useListSubscription({
|
|
490
|
-
|
|
491
|
-
|
|
494
|
+
props: {
|
|
495
|
+
listArgs,
|
|
496
|
+
retrieveArgs,
|
|
497
|
+
},
|
|
492
498
|
});
|
|
493
499
|
listSubscription.subscribe();
|
|
494
500
|
await nextTick();
|
|
@@ -538,28 +544,16 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
538
544
|
});
|
|
539
545
|
it("useListSubscriptions", async function () {
|
|
540
546
|
const listSubscriptionA = useListSubscription({
|
|
541
|
-
|
|
542
|
-
listArgs: { user: 1 },
|
|
543
|
-
retrieveArgs: {
|
|
544
|
-
fields,
|
|
545
|
-
},
|
|
546
|
-
});
|
|
547
|
-
const listSubscriptionB = useListSubscription({
|
|
548
|
-
crudArgs: { stream: "test_streamB" },
|
|
549
|
-
listArgs: { user: 2 },
|
|
550
|
-
retrieveArgs: {
|
|
551
|
-
fields,
|
|
552
|
-
},
|
|
553
|
-
});
|
|
554
|
-
const listSubscription = useListSubscriptions({
|
|
555
|
-
A: {
|
|
547
|
+
props: {
|
|
556
548
|
crudArgs: { stream: "test_streamA" },
|
|
557
549
|
listArgs: { user: 1 },
|
|
558
550
|
retrieveArgs: {
|
|
559
551
|
fields,
|
|
560
552
|
},
|
|
561
553
|
},
|
|
562
|
-
|
|
554
|
+
});
|
|
555
|
+
const listSubscriptionB = useListSubscription({
|
|
556
|
+
props: {
|
|
563
557
|
crudArgs: { stream: "test_streamB" },
|
|
564
558
|
listArgs: { user: 2 },
|
|
565
559
|
retrieveArgs: {
|
|
@@ -567,22 +561,46 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
567
561
|
},
|
|
568
562
|
},
|
|
569
563
|
});
|
|
564
|
+
const listSubscription = useListSubscriptions({
|
|
565
|
+
A: {
|
|
566
|
+
props: {
|
|
567
|
+
crudArgs: { stream: "test_streamA" },
|
|
568
|
+
listArgs: { user: 1 },
|
|
569
|
+
retrieveArgs: {
|
|
570
|
+
fields,
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
B: {
|
|
575
|
+
props: {
|
|
576
|
+
crudArgs: { stream: "test_streamB" },
|
|
577
|
+
listArgs: { user: 2 },
|
|
578
|
+
retrieveArgs: {
|
|
579
|
+
fields,
|
|
580
|
+
},
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
});
|
|
570
584
|
expect(inspect(listSubscription.A)).toEqual(inspect(listSubscriptionA));
|
|
571
585
|
expect(inspect(listSubscription.B)).toEqual(inspect(listSubscriptionB));
|
|
572
586
|
});
|
|
573
587
|
it("useListSubscriptions & useListInstances", async function () {
|
|
574
588
|
const listInstanceA = useListInstance({
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
589
|
+
props: {
|
|
590
|
+
crudArgs: { stream: "test_streamA" },
|
|
591
|
+
listArgs: { user: 1 },
|
|
592
|
+
retrieveArgs: {
|
|
593
|
+
fields,
|
|
594
|
+
},
|
|
579
595
|
},
|
|
580
596
|
});
|
|
581
597
|
const listInstanceB = useListInstance({
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
598
|
+
props: {
|
|
599
|
+
crudArgs: { stream: "test_streamB" },
|
|
600
|
+
listArgs: { user: 2 },
|
|
601
|
+
retrieveArgs: {
|
|
602
|
+
fields,
|
|
603
|
+
},
|
|
586
604
|
},
|
|
587
605
|
});
|
|
588
606
|
const listSubscriptionA = useListSubscription({
|
|
@@ -593,17 +611,21 @@ describe("use/listSubscription.spec.js", function () {
|
|
|
593
611
|
});
|
|
594
612
|
const listInstances = useListInstances({
|
|
595
613
|
A: {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
614
|
+
props: {
|
|
615
|
+
crudArgs: { stream: "test_streamA" },
|
|
616
|
+
listArgs: { user: 1 },
|
|
617
|
+
retrieveArgs: {
|
|
618
|
+
fields,
|
|
619
|
+
},
|
|
600
620
|
},
|
|
601
621
|
},
|
|
602
622
|
B: {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
623
|
+
props: {
|
|
624
|
+
crudArgs: { stream: "test_streamB" },
|
|
625
|
+
listArgs: { user: 2 },
|
|
626
|
+
retrieveArgs: {
|
|
627
|
+
fields,
|
|
628
|
+
},
|
|
607
629
|
},
|
|
608
630
|
},
|
|
609
631
|
});
|