@arrai-innovations/reactive-helpers 11.4.2 → 13.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/.husky/pre-commit +0 -1
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.prettierignore +1 -0
- package/README.md +11 -10
- package/config/listCrud.js +32 -1
- package/config/objectCrud.js +47 -1
- package/docs/README.md +43 -0
- package/docs/config/listCrud.md +97 -0
- package/docs/config/objectCrud.md +123 -0
- package/docs/use/cancellableIntent.md +163 -0
- package/docs/use/combineClasses.md +52 -0
- package/docs/use/list.md +285 -0
- package/docs/use/listCalculated.md +773 -0
- package/docs/use/listFilter.md +877 -0
- package/docs/use/listInstance.md +483 -0
- package/docs/use/listKeys.md +91 -0
- package/docs/use/listRelated.md +685 -0
- package/docs/use/listSearch.md +889 -0
- package/docs/use/listSort.md +1144 -0
- package/docs/use/listSubscription.md +379 -0
- package/docs/use/loadingError.md +21 -0
- package/docs/use/object.md +437 -0
- package/docs/use/objectCalculated.md +606 -0
- package/docs/use/objectInstance.md +486 -0
- package/docs/use/objectRelated.md +588 -0
- package/docs/use/objectSubscription.md +459 -0
- package/docs/use/paginatedListInstance.md +147 -0
- package/docs/use/search.md +311 -0
- package/docs/use/watchesRunning.md +80 -0
- package/docs/utils/assignReactiveObject.md +351 -0
- package/docs/utils/classes.md +100 -0
- package/docs/utils/compact.md +57 -0
- package/docs/utils/deleteKey.md +53 -0
- package/docs/utils/flattenPaths.md +45 -0
- package/docs/utils/getFakeId.md +34 -0
- package/docs/utils/keyDiff.md +101 -0
- package/docs/utils/loadingCombine.md +28 -0
- package/docs/utils/proxyRunning.md +33 -0
- package/docs/utils/relatedCalculatedHelpers.md +75 -0
- package/docs/utils/set.md +139 -0
- package/docs/utils/transformWalk.md +33 -0
- package/docs/utils/watches.md +441 -0
- package/eslint.config.js +125 -0
- package/index.js +34 -3
- package/lint-staged.config.js +5 -1
- package/makeTypeDoc.sh +25 -0
- package/package.json +27 -19
- package/tests/unit/config/listCrud.spec.js +5 -0
- package/tests/unit/config/objectCrud.spec.js +5 -0
- package/tests/unit/crudPromise.js +22 -3
- package/tests/unit/mockOnUnmounted.js +1 -1
- package/tests/unit/use/cancellableIntent.spec.js +2 -0
- package/tests/unit/use/listCalculated.spec.js +4 -3
- package/tests/unit/use/listFilter.spec.js +11 -7
- package/tests/unit/use/listInstance.spec.js +32 -14
- package/tests/unit/use/listRelated.spec.js +3 -2
- package/tests/unit/use/listSearch.spec.js +9 -7
- package/tests/unit/use/listSort.spec.js +29 -22
- package/tests/unit/use/listSubscription.spec.js +11 -5
- package/tests/unit/use/objectInstance.spec.js +15 -2
- package/tests/unit/use/objectSubscription.spec.js +31 -16
- package/tests/unit/use/search.spec.js +2 -2
- package/tests/unit/utils/assignReactiveObject.spec.js +21 -13
- package/tests/unit/utils/classes.spec.js +7 -6
- package/tests/unit/utils/watches.spec.js +4 -4
- package/tsconfig.json +19 -0
- package/typedoc-local-plugins/customize-output.js +13 -0
- package/typedoc.json +12 -0
- package/use/cancellableIntent.js +73 -2
- package/use/combineClasses.js +41 -31
- package/use/list.js +139 -5
- package/use/listCalculated.js +175 -10
- package/use/listFilter.js +175 -21
- package/use/listInstance.js +215 -94
- package/use/listRelated.js +260 -72
- package/use/listSearch.js +178 -57
- package/use/listSort.js +188 -21
- package/use/listSubscription.js +211 -63
- package/use/loadingError.js +43 -0
- package/use/object.js +187 -23
- package/use/objectCalculated.js +168 -16
- package/use/objectInstance.js +183 -102
- package/use/objectRelated.js +276 -84
- package/use/objectSubscription.js +169 -17
- package/use/paginatedListInstance.js +30 -1
- package/use/search.js +39 -23
- package/use/watchesRunning.js +41 -6
- package/utils/assignReactiveObject.js +139 -88
- package/utils/classes.js +57 -48
- package/utils/compact.js +28 -2
- package/utils/deleteKey.js +14 -1
- package/utils/flattenPaths.js +19 -9
- package/utils/getFakeId.js +11 -1
- package/utils/keyDiff.js +26 -35
- package/utils/loadingCombine.js +7 -4
- package/utils/proxyRunning.js +16 -8
- package/utils/relatedCalculatedHelpers.js +17 -0
- package/utils/set.js +66 -0
- package/utils/transformWalk.js +7 -6
- package/utils/watches.js +205 -71
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -25
- package/.jsdoc2md.json +0 -4
- package/config/index.js +0 -2
- package/docs.md +0 -1002
- package/jsdoc-to-markdown.sh +0 -16
- package/tests/unit/.eslintrc.cjs +0 -11
- package/tests/unit/config/index.spec.js +0 -18
- package/tests/unit/use/index.spec.js +0 -18
- package/tests/unit/utils/index.spec.js +0 -18
- package/use/index.js +0 -19
- package/utils/debugMessage.js +0 -209
- package/utils/debugWatch.js +0 -29
- package/utils/index.js +0 -16
- package/utils/lifecycleDebug.js +0 -126
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
[**@arrai-innovations/reactive-helpers**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@arrai-innovations/reactive-helpers](../README.md) / use/listSubscription
|
|
6
|
+
|
|
7
|
+
# use/listSubscription
|
|
8
|
+
|
|
9
|
+
## Classes
|
|
10
|
+
|
|
11
|
+
### ListSubscriptionError
|
|
12
|
+
|
|
13
|
+
Custom error class for list subscription errors.
|
|
14
|
+
|
|
15
|
+
#### Extends
|
|
16
|
+
|
|
17
|
+
- `Error`
|
|
18
|
+
|
|
19
|
+
#### Constructors
|
|
20
|
+
|
|
21
|
+
##### new ListSubscriptionError()
|
|
22
|
+
|
|
23
|
+
> **new ListSubscriptionError**(`message`, `code`): [`ListSubscriptionError`](listSubscription.md#listsubscriptionerror)
|
|
24
|
+
|
|
25
|
+
Creates a new ListSubscriptionError.
|
|
26
|
+
|
|
27
|
+
###### Parameters
|
|
28
|
+
|
|
29
|
+
• **message**: `string`
|
|
30
|
+
|
|
31
|
+
The error message.
|
|
32
|
+
|
|
33
|
+
• **code**: `string`
|
|
34
|
+
|
|
35
|
+
The error code.
|
|
36
|
+
|
|
37
|
+
###### Returns
|
|
38
|
+
|
|
39
|
+
[`ListSubscriptionError`](listSubscription.md#listsubscriptionerror)
|
|
40
|
+
|
|
41
|
+
###### Overrides
|
|
42
|
+
|
|
43
|
+
`Error.constructor`
|
|
44
|
+
|
|
45
|
+
#### Properties
|
|
46
|
+
|
|
47
|
+
##### code
|
|
48
|
+
|
|
49
|
+
> **code**: `string`
|
|
50
|
+
|
|
51
|
+
##### name
|
|
52
|
+
|
|
53
|
+
> **name**: `string`
|
|
54
|
+
|
|
55
|
+
###### Inherited from
|
|
56
|
+
|
|
57
|
+
`Error.name`
|
|
58
|
+
|
|
59
|
+
## Interfaces
|
|
60
|
+
|
|
61
|
+
### ListSubscriptionFunctions
|
|
62
|
+
|
|
63
|
+
#### Properties
|
|
64
|
+
|
|
65
|
+
##### clearError
|
|
66
|
+
|
|
67
|
+
> **clearError**: `Function`
|
|
68
|
+
|
|
69
|
+
Clear the subscription error and the underlying list instance error.
|
|
70
|
+
|
|
71
|
+
##### subscribe
|
|
72
|
+
|
|
73
|
+
> **subscribe**: `Function`
|
|
74
|
+
|
|
75
|
+
Trigger a subscription to the list.
|
|
76
|
+
|
|
77
|
+
##### unsubscribe
|
|
78
|
+
|
|
79
|
+
> **unsubscribe**: `Function`
|
|
80
|
+
|
|
81
|
+
Unsubscribe from the list.
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### ListSubscriptionProperties
|
|
86
|
+
|
|
87
|
+
#### Properties
|
|
88
|
+
|
|
89
|
+
##### effectScope
|
|
90
|
+
|
|
91
|
+
> **effectScope**: `EffectScope`
|
|
92
|
+
|
|
93
|
+
The effect scope of the list subscription.
|
|
94
|
+
|
|
95
|
+
##### listInstance
|
|
96
|
+
|
|
97
|
+
> **listInstance**: [`ListInstance`](listInstance.md#listinstance)
|
|
98
|
+
|
|
99
|
+
The list instance used by the subscription.
|
|
100
|
+
|
|
101
|
+
##### listIntent
|
|
102
|
+
|
|
103
|
+
> **listIntent**: [`CancellableIntent`](cancellableIntent.md#cancellableintent)
|
|
104
|
+
|
|
105
|
+
The `CancellableIntent` instance managing if the list should be (re)fetched.
|
|
106
|
+
|
|
107
|
+
##### state
|
|
108
|
+
|
|
109
|
+
> **state**: `object`
|
|
110
|
+
|
|
111
|
+
The reactive state of the list subscription.
|
|
112
|
+
|
|
113
|
+
###### crud
|
|
114
|
+
|
|
115
|
+
> **crud**: `object`
|
|
116
|
+
|
|
117
|
+
CRUD functions and their configurations for the list.
|
|
118
|
+
|
|
119
|
+
###### crud.args
|
|
120
|
+
|
|
121
|
+
> **args**: `any`
|
|
122
|
+
|
|
123
|
+
Arguments for the CRUD functions.
|
|
124
|
+
|
|
125
|
+
###### crud.list
|
|
126
|
+
|
|
127
|
+
> **list**: `Function`
|
|
128
|
+
|
|
129
|
+
Function to list objects.
|
|
130
|
+
|
|
131
|
+
###### error
|
|
132
|
+
|
|
133
|
+
> **error**: `Error`
|
|
134
|
+
|
|
135
|
+
The last error encountered.
|
|
136
|
+
|
|
137
|
+
###### errored
|
|
138
|
+
|
|
139
|
+
> **errored**: `boolean`
|
|
140
|
+
|
|
141
|
+
Indicates if an error occurred during the last operation.
|
|
142
|
+
|
|
143
|
+
###### intendToList
|
|
144
|
+
|
|
145
|
+
> **intendToList**: `boolean`
|
|
146
|
+
|
|
147
|
+
If this is true, the list should be fetched, or re-fetched if arguments change.
|
|
148
|
+
|
|
149
|
+
###### intendToSubscribe
|
|
150
|
+
|
|
151
|
+
> **intendToSubscribe**: `boolean`
|
|
152
|
+
|
|
153
|
+
If this is true, the subscription should start or restart if arguments change.
|
|
154
|
+
|
|
155
|
+
###### listArgs
|
|
156
|
+
|
|
157
|
+
> **listArgs**: `any`
|
|
158
|
+
|
|
159
|
+
Arguments passed to the server for listing operations.
|
|
160
|
+
|
|
161
|
+
###### loading
|
|
162
|
+
|
|
163
|
+
> **loading**: `boolean`
|
|
164
|
+
|
|
165
|
+
Indicates if the list is currently loading.
|
|
166
|
+
|
|
167
|
+
###### objects
|
|
168
|
+
|
|
169
|
+
> **objects**: [`ObjectsById`](listInstance.md#objectsbyid)
|
|
170
|
+
|
|
171
|
+
The list objects stored by their IDs.
|
|
172
|
+
|
|
173
|
+
###### objectsInOrder
|
|
174
|
+
|
|
175
|
+
> **objectsInOrder**: [`ListObject`](listInstance.md#listobject)[]
|
|
176
|
+
|
|
177
|
+
The objects in the order specified by the list.
|
|
178
|
+
|
|
179
|
+
###### order
|
|
180
|
+
|
|
181
|
+
> **order**: `string`[]
|
|
182
|
+
|
|
183
|
+
The order of objects in the list.
|
|
184
|
+
|
|
185
|
+
###### retrieveArgs
|
|
186
|
+
|
|
187
|
+
> **retrieveArgs**: `any`
|
|
188
|
+
|
|
189
|
+
Arguments passed to the server for retrieval operations.
|
|
190
|
+
|
|
191
|
+
###### running
|
|
192
|
+
|
|
193
|
+
> **running**: `boolean`
|
|
194
|
+
|
|
195
|
+
Indicates if there are ongoing reactive updates.
|
|
196
|
+
|
|
197
|
+
###### subscribed
|
|
198
|
+
|
|
199
|
+
> **subscribed**: `boolean`
|
|
200
|
+
|
|
201
|
+
Whether the subscription is active.
|
|
202
|
+
|
|
203
|
+
###### subscriptionError
|
|
204
|
+
|
|
205
|
+
> **subscriptionError**: `Error`
|
|
206
|
+
|
|
207
|
+
The error that occurred.
|
|
208
|
+
|
|
209
|
+
###### subscriptionErrored
|
|
210
|
+
|
|
211
|
+
> **subscriptionErrored**: `boolean`
|
|
212
|
+
|
|
213
|
+
Whether the subscription has errored.
|
|
214
|
+
|
|
215
|
+
###### subscriptionLoading
|
|
216
|
+
|
|
217
|
+
> **subscriptionLoading**: `boolean`
|
|
218
|
+
|
|
219
|
+
Whether the subscription is loading.
|
|
220
|
+
|
|
221
|
+
##### subscribeIntent
|
|
222
|
+
|
|
223
|
+
> **subscribeIntent**: [`CancellableIntent`](cancellableIntent.md#cancellableintent)
|
|
224
|
+
|
|
225
|
+
The `CancellableIntent` instance managing if the subscription should be (un)subscribed.
|
|
226
|
+
|
|
227
|
+
***
|
|
228
|
+
|
|
229
|
+
### ListSubscriptionRawState
|
|
230
|
+
|
|
231
|
+
#### Properties
|
|
232
|
+
|
|
233
|
+
##### intendToList
|
|
234
|
+
|
|
235
|
+
> **intendToList**: `boolean`
|
|
236
|
+
|
|
237
|
+
If this is true, the list should be fetched, or re-fetched if arguments change.
|
|
238
|
+
|
|
239
|
+
##### intendToSubscribe
|
|
240
|
+
|
|
241
|
+
> **intendToSubscribe**: `boolean`
|
|
242
|
+
|
|
243
|
+
If this is true, the subscription should start or restart if arguments change.
|
|
244
|
+
|
|
245
|
+
##### subscribed
|
|
246
|
+
|
|
247
|
+
> **subscribed**: `boolean`
|
|
248
|
+
|
|
249
|
+
Whether the subscription is active.
|
|
250
|
+
|
|
251
|
+
##### subscriptionError
|
|
252
|
+
|
|
253
|
+
> **subscriptionError**: `Readonly`\<`Ref`\<`Error`\>\>
|
|
254
|
+
|
|
255
|
+
The error that occurred.
|
|
256
|
+
|
|
257
|
+
##### subscriptionErrored
|
|
258
|
+
|
|
259
|
+
> **subscriptionErrored**: `Readonly`\<`Ref`\<`boolean`\>\>
|
|
260
|
+
|
|
261
|
+
Whether the subscription has errored.
|
|
262
|
+
|
|
263
|
+
##### subscriptionLoading
|
|
264
|
+
|
|
265
|
+
> **subscriptionLoading**: `Readonly`\<`Ref`\<`boolean`\>\>
|
|
266
|
+
|
|
267
|
+
Whether the subscription is loading.
|
|
268
|
+
|
|
269
|
+
## Type Aliases
|
|
270
|
+
|
|
271
|
+
### ListSubscription
|
|
272
|
+
|
|
273
|
+
> **ListSubscription**\<\>: [`ListSubscriptionFunctions`](listSubscription.md#listsubscriptionfunctions) & [`ListSubscriptionProperties`](listSubscription.md#listsubscriptionproperties)
|
|
274
|
+
|
|
275
|
+
#### Type Parameters
|
|
276
|
+
|
|
277
|
+
***
|
|
278
|
+
|
|
279
|
+
### ListSubscriptionOptions
|
|
280
|
+
|
|
281
|
+
> **ListSubscriptionOptions**\<\>: `object` & [`use/listInstance`](listInstance.md)
|
|
282
|
+
|
|
283
|
+
#### Type Parameters
|
|
284
|
+
|
|
285
|
+
***
|
|
286
|
+
|
|
287
|
+
### ListSubscriptionState
|
|
288
|
+
|
|
289
|
+
> **ListSubscriptionState**\<\>: `UnwrapNestedRefs`
|
|
290
|
+
|
|
291
|
+
#### Type Parameters
|
|
292
|
+
|
|
293
|
+
## Functions
|
|
294
|
+
|
|
295
|
+
### useListSubscription()
|
|
296
|
+
|
|
297
|
+
> **useListSubscription**(`options`): [`ListSubscription`](listSubscription.md#listsubscription)
|
|
298
|
+
|
|
299
|
+
A composition function that creates a reactive object that manages a list of objects, as returned by
|
|
300
|
+
`useListInstance`, causing the list to be re-fetched as needed and listening for updates to the list.
|
|
301
|
+
|
|
302
|
+
#### Parameters
|
|
303
|
+
|
|
304
|
+
• **options**: `any`
|
|
305
|
+
|
|
306
|
+
The options for the list subscription.
|
|
307
|
+
|
|
308
|
+
#### Returns
|
|
309
|
+
|
|
310
|
+
[`ListSubscription`](listSubscription.md#listsubscription)
|
|
311
|
+
|
|
312
|
+
- Returns a robust list subscription object that manages a list instance with
|
|
313
|
+
capabilities to subscribe and unsubscribe to data sources, alongside handling real-time data updates.
|
|
314
|
+
|
|
315
|
+
#### Example
|
|
316
|
+
|
|
317
|
+
```vue
|
|
318
|
+
<script setup>
|
|
319
|
+
import { useListSubscription } from "@arrai-innovations/reactive-helpers";
|
|
320
|
+
import { reactive, toRef } from "vue";
|
|
321
|
+
|
|
322
|
+
const props = defineProps({
|
|
323
|
+
// whatever props are required for your configured list instance
|
|
324
|
+
someListFilter: {
|
|
325
|
+
type: String,
|
|
326
|
+
default: "",
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const listSubscriptionProps = reactive({
|
|
331
|
+
crudArgs: {
|
|
332
|
+
// whatever arguments are required for your configured list crud function to get the right endpoint
|
|
333
|
+
},
|
|
334
|
+
listArgs: {
|
|
335
|
+
// whatever arguments are required for your configured list function to get the right list
|
|
336
|
+
someListFilter: toRef(props, "someListFilter"),
|
|
337
|
+
},
|
|
338
|
+
retrieveArgs: {
|
|
339
|
+
// whatever arguments are required for your configured list function to get items back looking as expected
|
|
340
|
+
},
|
|
341
|
+
intendToList: false,
|
|
342
|
+
intendToSubscribe: false,
|
|
343
|
+
});
|
|
344
|
+
listSubscriptionProps.intendToList = listSubscriptionProps.intendToSubscribe = computed(()=> !!props.someListFilter);
|
|
345
|
+
const listSubscription = useListSubscription({ props: listSubscriptionProps });
|
|
346
|
+
</script>
|
|
347
|
+
<template>
|
|
348
|
+
<ul>
|
|
349
|
+
<!-- reactive list of objects, responding to updates via configured subscription function. -->
|
|
350
|
+
<li v-for="obj in listSubscription.state.objectsInOrder">
|
|
351
|
+
{{ obj }}
|
|
352
|
+
</li>
|
|
353
|
+
</ul>
|
|
354
|
+
</template>
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
#### Throws
|
|
358
|
+
|
|
359
|
+
- If both listInstance and props are passed, or if neither are passed.
|
|
360
|
+
|
|
361
|
+
***
|
|
362
|
+
|
|
363
|
+
### useListSubscriptions()
|
|
364
|
+
|
|
365
|
+
> **useListSubscriptions**(`listSubscriptionArgs`): `object`
|
|
366
|
+
|
|
367
|
+
A Vue composition function that creates multiple list subscriptions, and returns them as an object.
|
|
368
|
+
|
|
369
|
+
#### Parameters
|
|
370
|
+
|
|
371
|
+
• **listSubscriptionArgs**
|
|
372
|
+
|
|
373
|
+
Each desired list instance options, keyed by an instance name.
|
|
374
|
+
|
|
375
|
+
#### Returns
|
|
376
|
+
|
|
377
|
+
`object`
|
|
378
|
+
|
|
379
|
+
- Each list instance, keyed by the instance name.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[**@arrai-innovations/reactive-helpers**](../README.md) • **Docs**
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@arrai-innovations/reactive-helpers](../README.md) / use/loadingError
|
|
6
|
+
|
|
7
|
+
# use/loadingError
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
### default()
|
|
12
|
+
|
|
13
|
+
> **default**(): `any`
|
|
14
|
+
|
|
15
|
+
A composable function for managing loading and error states.
|
|
16
|
+
|
|
17
|
+
#### Returns
|
|
18
|
+
|
|
19
|
+
`any`
|
|
20
|
+
|
|
21
|
+
- An object containing reactive fields and actions for loading and error states.
|