@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
|
@@ -4,12 +4,8 @@ module.exports = {
|
|
|
4
4
|
env: {
|
|
5
5
|
node: true,
|
|
6
6
|
},
|
|
7
|
-
|
|
8
|
-
extends: ["plugin:vue/vue3-essential", "eslint:recommended", "@vue/prettier"],
|
|
9
|
-
|
|
10
|
-
parserOptions: {
|
|
11
|
-
parser: "babel-eslint",
|
|
12
|
-
},
|
|
7
|
+
plugins: ["jsdoc"],
|
|
8
|
+
extends: ["plugin:vue/vue3-essential", "eslint:recommended", "@vue/prettier", "plugin:jsdoc/recommended-error"],
|
|
13
9
|
|
|
14
10
|
rules: {
|
|
15
11
|
"no-console": "off", // console.error is useful.
|
|
@@ -22,5 +18,6 @@ module.exports = {
|
|
|
22
18
|
asyncArrow: "always",
|
|
23
19
|
},
|
|
24
20
|
],
|
|
21
|
+
"jsdoc/require-jsdoc": "off", // let's ease into this
|
|
25
22
|
},
|
|
26
23
|
};
|
package/.jsdoc2md.json
ADDED
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|

|
|
6
6
|

|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Vue.js 3 utility composition functions to help manipulate objects and lists.
|
|
9
9
|
|
|
10
10
|
<!-- prettier-ignore-start -->
|
|
11
11
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
@@ -14,6 +14,7 @@ VueJS 3 utility composition functions to help manipulate objects and lists.
|
|
|
14
14
|
- [Install](#install)
|
|
15
15
|
- [Usage](#usage)
|
|
16
16
|
- [Import](#import)
|
|
17
|
+
- [JSDocs](#jsdocs)
|
|
17
18
|
- [List](#list)
|
|
18
19
|
- [Instance](#instance)
|
|
19
20
|
- [Subscription](#subscription)
|
|
@@ -46,8 +47,18 @@ $ npm install @arrai-innovations/reactive-helpers
|
|
|
46
47
|
```js
|
|
47
48
|
// base import contains all exports
|
|
48
49
|
import { useListInstance, useObjectInstance } from "@arrai-innovations/reactive-helpers";
|
|
50
|
+
// you can also import individual modules
|
|
51
|
+
import { useListInstance } from "@arrai-innovations/reactive-helpers/use/listInstance";
|
|
52
|
+
// or the module categories
|
|
53
|
+
import { useObjectInstance } from "@arrai-innovations/reactive-helpers/use";
|
|
49
54
|
```
|
|
50
55
|
|
|
56
|
+
See the [JSDocs](./docs.md) for list of available modules and imports.
|
|
57
|
+
|
|
58
|
+
### JSDocs
|
|
59
|
+
|
|
60
|
+
[View the JSDocs](./docs.md)
|
|
61
|
+
|
|
51
62
|
### List
|
|
52
63
|
|
|
53
64
|
#### Instance
|
package/docs.md
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
## Modules
|
|
2
|
+
|
|
3
|
+
| Module | Description |
|
|
4
|
+
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
5
|
+
| [utils/assignReactiveObject] | Reactive object assignment utilities |
|
|
6
|
+
| [utils/debugMessage] | Configurable logging of debug messages at runtime. |
|
|
7
|
+
| [utils/flattenPaths] | Get all paths from an array or object. |
|
|
8
|
+
| [utils/keyDiff] | Calculate the difference between objects in terms of what keys are the same, what keys are removed, and what keys are added. |
|
|
9
|
+
| [utils/lifecycleDebug] | Debug lifecycle hooks |
|
|
10
|
+
| [utils/transformWalk] | Object walking utility. |
|
|
11
|
+
|
|
12
|
+
## utils/assignReactiveObject
|
|
13
|
+
|
|
14
|
+
Reactive object assignment utilities
|
|
15
|
+
|
|
16
|
+
- [utils/assignReactiveObject]
|
|
17
|
+
- [~addReactiveObject(target, source, \[exclude\], \[addedKeys\])]
|
|
18
|
+
- [~updateReactiveObject(target, source, \[exclude\], \[sameKeys\])]
|
|
19
|
+
- [~addOrUpdateReactiveObject(target, source, \[exclude\], \[addedKeys\], \[sameKeys\])]
|
|
20
|
+
- [~trimReactiveObject(target, source, \[exclude\], \[removedKeys\])]
|
|
21
|
+
- [~assignReactiveObject(target, source, \[exclude\])]
|
|
22
|
+
- [~assignReactiveObjectDeep(target, source, \[exclude\])]
|
|
23
|
+
- [~addOrUpdateReactiveObjectDeep(target, source, \[exclude\])]
|
|
24
|
+
- [~ValidTargetOrSource]
|
|
25
|
+
|
|
26
|
+
### utils/assignReactiveObject~addReactiveObject(target, source, \[exclude\], \[addedKeys\])
|
|
27
|
+
|
|
28
|
+
Adds to a target the missing keys from a source. `addedKeys` can be precalculated to avoid recalculation.
|
|
29
|
+
|
|
30
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
31
|
+
**Returns**: `boolean` - True if any keys were added, false otherwise.
|
|
32
|
+
**Throws**:
|
|
33
|
+
|
|
34
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
35
|
+
|
|
36
|
+
| Param | Type | Description |
|
|
37
|
+
| ------------- | --------------------- | ---------------------------------------------------------------------------------------- |
|
|
38
|
+
| target | `ValidTargetOrSource` | The object receiving values. |
|
|
39
|
+
| source | `ValidTargetOrSource` | The object providing values. |
|
|
40
|
+
| \[exclude\] | `Array` | Keys to exclude from the addition. |
|
|
41
|
+
| \[addedKeys\] | `Array` | Precaulcated array of keys to add, if available. Otherwise, the keys will be calculated. |
|
|
42
|
+
|
|
43
|
+
### utils/assignReactiveObject~updateReactiveObject(target, source, \[exclude\], \[sameKeys\])
|
|
44
|
+
|
|
45
|
+
Updates a target with mutually shared keys from a source. `sameKeys` can be precalculated to avoid recalculation.
|
|
46
|
+
|
|
47
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
48
|
+
**Returns**: `boolean` - True if any keys were updated, false otherwise.
|
|
49
|
+
**Throws**:
|
|
50
|
+
|
|
51
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
52
|
+
|
|
53
|
+
| Param | Type | Description |
|
|
54
|
+
| ------------ | --------------------- | ------------------------------------------------------------------------------------------- |
|
|
55
|
+
| target | `ValidTargetOrSource` | The object receiving values. |
|
|
56
|
+
| source | `ValidTargetOrSource` | The object providing values. |
|
|
57
|
+
| \[exclude\] | `Array` | Keys to exclude from the update. |
|
|
58
|
+
| \[sameKeys\] | `Array` | Precaulcated array of keys to update, if available. Otherwise, the keys will be calculated. |
|
|
59
|
+
|
|
60
|
+
### utils/assignReactiveObject~addOrUpdateReactiveObject(target, source, \[exclude\], \[addedKeys\], \[sameKeys\])
|
|
61
|
+
|
|
62
|
+
Adds to a target the missing keys from a source, and updates a target with mutually shared keys from a source.
|
|
63
|
+
|
|
64
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
65
|
+
**Returns**: `boolean` - True if any keys were added or updated, false otherwise.
|
|
66
|
+
|
|
67
|
+
| Param | Type | Description |
|
|
68
|
+
| ------------- | --------------------- | ------------------------------------------------------------------------------------------- |
|
|
69
|
+
| target | `ValidTargetOrSource` | The object receiving values. |
|
|
70
|
+
| source | `ValidTargetOrSource` | The object providing values. |
|
|
71
|
+
| \[exclude\] | `Array` | Keys to exclude from the addition or update. |
|
|
72
|
+
| \[addedKeys\] | `Array` | Precaulcated array of keys to add, if available. Otherwise, the keys will be calculated. |
|
|
73
|
+
| \[sameKeys\] | `Array` | Precaulcated array of keys to update, if available. Otherwise, the keys will be calculated. |
|
|
74
|
+
|
|
75
|
+
### utils/assignReactiveObject~trimReactiveObject(target, source, \[exclude\], \[removedKeys\])
|
|
76
|
+
|
|
77
|
+
Removes keys from a target that are not present in a source.
|
|
78
|
+
|
|
79
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
80
|
+
**Returns**: `boolean` - True if any keys were removed, false otherwise.
|
|
81
|
+
**Throws**:
|
|
82
|
+
|
|
83
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
84
|
+
|
|
85
|
+
| Param | Type | Description |
|
|
86
|
+
| --------------- | ------------------------------- | ------------------------------------------------------------------------------- |
|
|
87
|
+
| target | `ValidTargetOrSource` | The object receiving trimming. |
|
|
88
|
+
| source | `ValidTargetOrSource` \| `null` | The object that provides the allowed set of keys for calculating `removedKeys`. |
|
|
89
|
+
| \[exclude\] | `Array` | Keys to exclude from removal. |
|
|
90
|
+
| \[removedKeys\] | `Array` | An array to store removed keys. |
|
|
91
|
+
|
|
92
|
+
### utils/assignReactiveObject~assignReactiveObject(target, source, \[exclude\])
|
|
93
|
+
|
|
94
|
+
Change a target to match a source, where keys missing from the source are removed from the target,
|
|
95
|
+
keys present in the source are added to the target, and keys present in both are updated in the target.
|
|
96
|
+
|
|
97
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
98
|
+
**Returns**: `boolean` - True if any keys were added, updated, or removed, false otherwise.
|
|
99
|
+
**Throws**:
|
|
100
|
+
|
|
101
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
102
|
+
|
|
103
|
+
| Param | Type | Description |
|
|
104
|
+
| ----------- | --------------------- | ------------------------------------ |
|
|
105
|
+
| target | `ValidTargetOrSource` | The target object or array. |
|
|
106
|
+
| source | `ValidTargetOrSource` | The reactive object to assign. |
|
|
107
|
+
| \[exclude\] | `Array` | Keys to exclude from the assignment. |
|
|
108
|
+
|
|
109
|
+
### utils/assignReactiveObject~assignReactiveObjectDeep(target, source, \[exclude\])
|
|
110
|
+
|
|
111
|
+
Recursively change a target to match a source, where keys missing from the source are removed from the target,
|
|
112
|
+
keys present in the source are added to the target, and keys present in both are updated in the target.
|
|
113
|
+
|
|
114
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
115
|
+
**Returns**: `boolean` - True if any keys were added, updated, or removed, false otherwise.
|
|
116
|
+
**Throws**:
|
|
117
|
+
|
|
118
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
119
|
+
|
|
120
|
+
| Param | Type | Description |
|
|
121
|
+
| ----------- | --------------------- | ------------------------------------ |
|
|
122
|
+
| target | `ValidTargetOrSource` | The object receiving updates. |
|
|
123
|
+
| source | `ValidTargetOrSource` | The object providing updates. |
|
|
124
|
+
| \[exclude\] | `Array` | Keys to exclude from the assignment. |
|
|
125
|
+
|
|
126
|
+
### utils/assignReactiveObject~addOrUpdateReactiveObjectDeep(target, source, \[exclude\])
|
|
127
|
+
|
|
128
|
+
Recursively change a target to match a source, where keys present in the source are added to the target, and
|
|
129
|
+
keys present in both are updated in the target. Missing keys are not removed.
|
|
130
|
+
|
|
131
|
+
**Kind**: inner method of [`utils/assignReactiveObject`]
|
|
132
|
+
**Returns**: `boolean` - True if any keys were added or updated, false otherwise.
|
|
133
|
+
**Throws**:
|
|
134
|
+
|
|
135
|
+
- `AssignReactiveObjectError` If either target or source are not ultimately objects or arrays.
|
|
136
|
+
|
|
137
|
+
| Param | Type | Description |
|
|
138
|
+
| ----------- | --------------------- | -------------------------------- |
|
|
139
|
+
| target | `ValidTargetOrSource` | The object receiving updates. |
|
|
140
|
+
| source | `ValidTargetOrSource` | The object providing updates. |
|
|
141
|
+
| \[exclude\] | `Array` | Keys to exclude from the update. |
|
|
142
|
+
|
|
143
|
+
### utils/assignReactiveObject~ValidTargetOrSource
|
|
144
|
+
|
|
145
|
+
targets and sources must be refs, objects, or arrays
|
|
146
|
+
and refs must ultimately resolve to objects or arrays
|
|
147
|
+
|
|
148
|
+
**Kind**: inner typedef of [`utils/assignReactiveObject`]
|
|
149
|
+
|
|
150
|
+
## utils/debugMessage
|
|
151
|
+
|
|
152
|
+
Configurable logging of debug messages at runtime.
|
|
153
|
+
|
|
154
|
+
- [utils/debugMessage]
|
|
155
|
+
- [~useDebugMessage(categories)]
|
|
156
|
+
- [~DebugMessageFunction]
|
|
157
|
+
|
|
158
|
+
### utils/debugMessage~useDebugMessage(categories)
|
|
159
|
+
|
|
160
|
+
Returns a function that logs debug messages based on enabled categories.
|
|
161
|
+
|
|
162
|
+
**Kind**: inner method of [`utils/debugMessage`]
|
|
163
|
+
**Returns**: `DebugMessageFunction` - debug message function
|
|
164
|
+
|
|
165
|
+
| Param | Type | Description |
|
|
166
|
+
| ---------- | ---------------- | ------------------------------ |
|
|
167
|
+
| categories | `Array.<string>` | categories for the message log |
|
|
168
|
+
|
|
169
|
+
### utils/debugMessage~DebugMessageFunction
|
|
170
|
+
|
|
171
|
+
Logs debug messages based on the specified categories and logging rules.
|
|
172
|
+
|
|
173
|
+
**Kind**: inner typedef of [`utils/debugMessage`]
|
|
174
|
+
**Properties**
|
|
175
|
+
|
|
176
|
+
| Name | Type | Description |
|
|
177
|
+
| -------- | ---------- | ------------- |
|
|
178
|
+
| messages | `function` | log a message |
|
|
179
|
+
|
|
180
|
+
## utils/flattenPaths
|
|
181
|
+
|
|
182
|
+
Get all paths from an array or object.
|
|
183
|
+
|
|
184
|
+
### utils/flattenPaths~flattenPaths(arrayOrObject, currentPath)
|
|
185
|
+
|
|
186
|
+
Turn an array or object into an array of path strings. Recurses for any found arrays or objects.
|
|
187
|
+
|
|
188
|
+
Array indexes are wrapped in square brackets and object keys are prefixed with a period.
|
|
189
|
+
|
|
190
|
+
**Kind**: inner method of [`utils/flattenPaths`]
|
|
191
|
+
**Returns**: `Array.<string>` - paths
|
|
192
|
+
|
|
193
|
+
| Param | Type | Description |
|
|
194
|
+
| ------------- | ------------------- | -------------------------------------------------- |
|
|
195
|
+
| arrayOrObject | `Array` \| `object` | array or object to flatten |
|
|
196
|
+
| currentPath | `string` | current path, for recursion or as a starting point |
|
|
197
|
+
|
|
198
|
+
## utils/keyDiff
|
|
199
|
+
|
|
200
|
+
Calculate the difference between objects in terms of what keys
|
|
201
|
+
are the same, what keys are removed, and what keys are added.
|
|
202
|
+
|
|
203
|
+
- [utils/keyDiff]
|
|
204
|
+
- [~keyDiff(newKeys, oldKeys, \[options\])]
|
|
205
|
+
- [~keyDiffDeep(newObj, oldObj, \[options\])]
|
|
206
|
+
- [~KeyDiffOptions]
|
|
207
|
+
- [~KeyDiffResult]
|
|
208
|
+
|
|
209
|
+
### utils/keyDiff~keyDiff(newKeys, oldKeys, \[options\])
|
|
210
|
+
|
|
211
|
+
Calculate the difference between two arrays of keys, in terms of what keys
|
|
212
|
+
are the same, what keys are removed, and what keys are added.
|
|
213
|
+
|
|
214
|
+
**Kind**: inner method of [`utils/keyDiff`]
|
|
215
|
+
**Returns**: `KeyDiffResult` - - the differences
|
|
216
|
+
|
|
217
|
+
| Param | Type | Description |
|
|
218
|
+
| ----------- | ---------------- | ------------------------------ |
|
|
219
|
+
| newKeys | `Array.<string>` | keys to consider as new |
|
|
220
|
+
| oldKeys | `Array.<string>` | keys to consider as old |
|
|
221
|
+
| \[options\] | `KeyDiffOptions` | which differences are returned |
|
|
222
|
+
|
|
223
|
+
### utils/keyDiff~keyDiffDeep(newObj, oldObj, \[options\])
|
|
224
|
+
|
|
225
|
+
Calculate the difference between two objects, in terms of what keys are the same,
|
|
226
|
+
what keys are removed, and what keys are added. Keys are sourced deeply in the objects.
|
|
227
|
+
|
|
228
|
+
**Kind**: inner method of [`utils/keyDiff`]
|
|
229
|
+
**Returns**: `KeyDiffResult` - - the differences
|
|
230
|
+
|
|
231
|
+
| Param | Type | Description |
|
|
232
|
+
| ----------- | ---------------- | ------------------------------ |
|
|
233
|
+
| newObj | `object` | the new version of the object |
|
|
234
|
+
| oldObj | `object` | the old version of the object |
|
|
235
|
+
| \[options\] | `KeyDiffOptions` | which differences are returned |
|
|
236
|
+
|
|
237
|
+
### utils/keyDiff~KeyDiffOptions
|
|
238
|
+
|
|
239
|
+
Options for keyDiff and keyDiffDeep
|
|
240
|
+
|
|
241
|
+
**Kind**: inner typedef of [`utils/keyDiff`]
|
|
242
|
+
**Properties**
|
|
243
|
+
|
|
244
|
+
| Name | Type | Default | Description |
|
|
245
|
+
| --------------- | --------- | ------- | -------------------------------------- |
|
|
246
|
+
| \[sameKeys\] | `boolean` | `true` | if true, return keys that are the same |
|
|
247
|
+
| \[removedKeys\] | `boolean` | `true` | if true, return keys that are removed |
|
|
248
|
+
| \[addedKeys\] | `boolean` | `true` | if true, return keys that are added |
|
|
249
|
+
|
|
250
|
+
### utils/keyDiff~KeyDiffResult
|
|
251
|
+
|
|
252
|
+
Result object of keyDiff and keyDiffDeep
|
|
253
|
+
|
|
254
|
+
**Kind**: inner typedef of [`utils/keyDiff`]
|
|
255
|
+
**Properties**
|
|
256
|
+
|
|
257
|
+
| Name | Type | Description |
|
|
258
|
+
| --------------- | ---------------- | ----------------------------------------------------------- |
|
|
259
|
+
| \[sameKeys\] | `Array.<string>` | if sameKeys option is true, return keys that are the same |
|
|
260
|
+
| \[removedKeys\] | `Array.<string>` | if removedKeys option is true, return keys that are removed |
|
|
261
|
+
| \[addedKeys\] | `Array.<string>` | if addedKeys option is true, return keys that are added |
|
|
262
|
+
|
|
263
|
+
## utils/lifecycleDebug
|
|
264
|
+
|
|
265
|
+
Debug lifecycle hooks
|
|
266
|
+
|
|
267
|
+
### utils/lifecycleDebug~useLifecycleDebug(categories, \[includes\], \[excludes\])
|
|
268
|
+
|
|
269
|
+
Using useDebugMessage, log lifecycle events for the current component, with the specified categories.
|
|
270
|
+
|
|
271
|
+
**Kind**: inner method of [`utils/lifecycleDebug`]
|
|
272
|
+
|
|
273
|
+
| Param | Type | Description |
|
|
274
|
+
| ------------ | ---------------- | ---------------------------------------------- |
|
|
275
|
+
| categories | `Array.<string>` | the categories to give messages this generates |
|
|
276
|
+
| \[includes\] | `Array.<string>` | the lifecycle functions to include |
|
|
277
|
+
| \[excludes\] | `Array.<string>` | the lifecycle functions to exclude |
|
|
278
|
+
|
|
279
|
+
## utils/transformWalk
|
|
280
|
+
|
|
281
|
+
Object walking utility.
|
|
282
|
+
|
|
283
|
+
### utils/transformWalk~transformWalk(obj, transformFn, path)
|
|
284
|
+
|
|
285
|
+
Recursively walks through an object's values and applies a transformation function to each value.
|
|
286
|
+
The value recursed into is the transformed value, not the original value.
|
|
287
|
+
|
|
288
|
+
**Kind**: inner method of [`utils/transformWalk`]
|
|
289
|
+
**Returns**: `*` - The transformed initial value.
|
|
290
|
+
|
|
291
|
+
| Param | Type | Description |
|
|
292
|
+
| ----------- | ---------- | ------------------------------------- |
|
|
293
|
+
| obj | `*` | The object to start walking from. |
|
|
294
|
+
| transformFn | `function` | The function to transform each value. |
|
|
295
|
+
| path | `string` | The path to the current value. |
|
|
296
|
+
|
|
297
|
+
**Example**
|
|
298
|
+
|
|
299
|
+
```js
|
|
300
|
+
const obj = {
|
|
301
|
+
a: 1,
|
|
302
|
+
b: {
|
|
303
|
+
c: 2,
|
|
304
|
+
d: [3, 4, { e: 5 }],
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const transformed = transformWalk(obj, (key, value, path) => {
|
|
309
|
+
if (key === "e") {
|
|
310
|
+
return value * 2;
|
|
311
|
+
}
|
|
312
|
+
return value;
|
|
313
|
+
});
|
|
314
|
+
// transformed = {
|
|
315
|
+
// a: 1,
|
|
316
|
+
// b: {
|
|
317
|
+
// c: 2,
|
|
318
|
+
// d: [3, 4, { e: 10 }]
|
|
319
|
+
// }
|
|
320
|
+
// }
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
<!-- LINKS -->
|
|
324
|
+
|
|
325
|
+
[utils/assignreactiveobject]: #utilsassignreactiveobject
|
|
326
|
+
[utils/debugmessage]: #utilsdebugmessage
|
|
327
|
+
[utils/flattenpaths]: #utilsflattenpaths
|
|
328
|
+
[utils/keydiff]: #utilskeydiff
|
|
329
|
+
[utils/lifecycledebug]: #utilslifecycledebug
|
|
330
|
+
[utils/transformwalk]: #utilstransformwalk
|
|
331
|
+
[~validtargetorsource]: #utilsassignreactiveobjectvalidtargetorsource
|
|
332
|
+
[`utils/assignreactiveobject`]: #utilsassignreactiveobject
|
|
333
|
+
[~debugmessagefunction]: #utilsdebugmessagedebugmessagefunction
|
|
334
|
+
[`utils/debugmessage`]: #utilsdebugmessage
|
|
335
|
+
[`utils/flattenpaths`]: #utilsflattenpaths
|
|
336
|
+
[~keydiffoptions]: #utilskeydiffkeydiffoptions
|
|
337
|
+
[~keydiffresult]: #utilskeydiffkeydiffresult
|
|
338
|
+
[`utils/keydiff`]: #utilskeydiff
|
|
339
|
+
[`utils/lifecycledebug`]: #utilslifecycledebug
|
|
340
|
+
[`utils/transformwalk`]: #utilstransformwalk
|
|
341
|
+
[~addreactiveobject(target, source, \[exclude\], \[addedkeys\])]: #utilsassignreactiveobjectaddreactiveobjecttarget-source-exclude-addedkeys
|
|
342
|
+
[~updatereactiveobject(target, source, \[exclude\], \[samekeys\])]: #utilsassignreactiveobjectupdatereactiveobjecttarget-source-exclude-samekeys
|
|
343
|
+
[~addorupdatereactiveobject(target, source, \[exclude\], \[addedkeys\], \[samekeys\])]: #utilsassignreactiveobjectaddorupdatereactiveobjecttarget-source-exclude-addedkeys-samekeys
|
|
344
|
+
[~trimreactiveobject(target, source, \[exclude\], \[removedkeys\])]: #utilsassignreactiveobjecttrimreactiveobjecttarget-source-exclude-removedkeys
|
|
345
|
+
[~assignreactiveobject(target, source, \[exclude\])]: #utilsassignreactiveobjectassignreactiveobjecttarget-source-exclude
|
|
346
|
+
[~assignreactiveobjectdeep(target, source, \[exclude\])]: #utilsassignreactiveobjectassignreactiveobjectdeeptarget-source-exclude
|
|
347
|
+
[~addorupdatereactiveobjectdeep(target, source, \[exclude\])]: #utilsassignreactiveobjectaddorupdatereactiveobjectdeeptarget-source-exclude
|
|
348
|
+
[~usedebugmessage(categories)]: #utilsdebugmessageusedebugmessagecategories
|
|
349
|
+
[~keydiff(newkeys, oldkeys, \[options\])]: #utilskeydiffkeydiffnewkeys-oldkeys-options
|
|
350
|
+
[~keydiffdeep(newobj, oldobj, \[options\])]: #utilskeydiffkeydiffdeepnewobj-oldobj-options
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
npx --no-install jsdoc-to-markdown > ./docs.new.md
|
|
4
|
+
npx --no-install prettier --write docs.new.md > /dev/null
|
|
5
|
+
set +e
|
|
6
|
+
diff ./docs.new.md ./docs.md > /dev/null
|
|
7
|
+
diffCode=$?
|
|
8
|
+
# we want to return a non-zero exit code if the files are different, to stop the commit
|
|
9
|
+
if [ $diffCode != 0 ]; then
|
|
10
|
+
echo "docs.md is out of date, see git diff for details"
|
|
11
|
+
mv -f ./docs.new.md ./docs.md
|
|
12
|
+
exit $diffCode
|
|
13
|
+
fi
|
|
14
|
+
rm -f ./docs.new.md
|
|
15
|
+
git rm ./docs.new.md > /dev/null 2>&1
|
|
16
|
+
exit 0
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
"**/*.{js,cjs,mjs,ts,jsx,tsx}": [
|
|
3
|
+
"npx --no-install eslint --fix",
|
|
4
|
+
"npx --no-install prettier --write",
|
|
5
|
+
() => "npm run docs",
|
|
6
|
+
],
|
|
7
|
+
"**/*.{markdown,md}": ["npx --no-install doctoc --github -u ."],
|
|
8
|
+
"**/*.{less,scss,css,vue,markdown,json,md,yml,yaml,html}": ["npx --no-install prettier --write"],
|
|
9
|
+
".circleci/config.yml": ["circleci config validate"],
|
|
10
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrai-innovations/reactive-helpers",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "VueJS 3 utility composition functions to help manipulate objects and lists.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"directories": {
|
|
7
8
|
"use": "use",
|
|
8
9
|
"utils": "utils",
|
|
9
10
|
"tests": "tests"
|
|
10
11
|
},
|
|
11
12
|
"scripts": {
|
|
12
|
-
"test": "
|
|
13
|
+
"test": "vitest",
|
|
13
14
|
"coverage": "npm run coverage:clean; npm test -- --coverage=true",
|
|
14
15
|
"coverage:clean": "rm -rf coverage",
|
|
15
|
-
"prepare": "husky install"
|
|
16
|
+
"prepare": "husky install",
|
|
17
|
+
"docs": "./jsdoc-to-markdown.sh"
|
|
16
18
|
},
|
|
17
19
|
"repository": {
|
|
18
20
|
"type": "git",
|
|
@@ -26,29 +28,29 @@
|
|
|
26
28
|
"homepage": "https://github.com/arrai-innovations/reactive-helpers#readme",
|
|
27
29
|
"devDependencies": {
|
|
28
30
|
"@arrai-innovations/commitlint-config": "^1.1.0",
|
|
29
|
-
"@babel/preset-env": "^7.17.10",
|
|
30
31
|
"@commitlint/cli": "^16.2.4",
|
|
32
|
+
"@godaddy/dmd": "^1.0.4",
|
|
31
33
|
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
|
|
32
|
-
"@
|
|
34
|
+
"@vitest/coverage-v8": "^0.32.2",
|
|
33
35
|
"@vue/compiler-sfc": "^3.3.4",
|
|
34
36
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
35
37
|
"@vue/test-utils": "^2.3.2",
|
|
36
|
-
"@vue/vue3-jest": "^27.0.0",
|
|
37
|
-
"babel-eslint": "^10.1.0",
|
|
38
|
-
"babel-jest": "^27.5.1",
|
|
39
38
|
"doctoc": "^2.1.0",
|
|
40
|
-
"eslint": "
|
|
41
|
-
"eslint-plugin-
|
|
39
|
+
"eslint": ">=8.0.0",
|
|
40
|
+
"eslint-plugin-jsdoc": "^46.2.6",
|
|
41
|
+
"eslint-plugin-vitest": "0.2.6",
|
|
42
|
+
"eslint-plugin-vitest-globals": "^1.3.1",
|
|
42
43
|
"eslint-plugin-vue": "^8.7.1",
|
|
43
44
|
"flush-promises": "^1.0.2",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
45
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
46
|
+
"lint-staged": "^13.2.2",
|
|
47
|
+
"prettier": "2.6.2",
|
|
48
|
+
"vitest": "^0.32.2"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
51
|
"browser-util-inspect": "^0.2.0",
|
|
49
52
|
"flexsearch": "^0.7.21",
|
|
50
53
|
"husky": "^7.0.4",
|
|
51
|
-
"jest": "^27.5.1",
|
|
52
54
|
"pinst": "^3.0.0",
|
|
53
55
|
"vue-deepunref": "^1.0.1"
|
|
54
56
|
},
|
|
@@ -11,7 +11,7 @@ export class CancellableResolvable {
|
|
|
11
11
|
constructor() {
|
|
12
12
|
const newResolvable = new Resolvable();
|
|
13
13
|
const cancelResolvable = new Resolvable();
|
|
14
|
-
newResolvable.promise.cancel =
|
|
14
|
+
newResolvable.promise.cancel = vi
|
|
15
15
|
.fn()
|
|
16
16
|
.mockImplementationOnce(async () => cancelResolvable.promise)
|
|
17
17
|
.mockRejectedValue(new Error("cancel already called"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function getMockOnUnmounted() {
|
|
2
2
|
const mockOnUnmounted = {};
|
|
3
|
-
|
|
3
|
+
vi.mock("vue", () => ({
|
|
4
4
|
_esModule: true,
|
|
5
|
-
...
|
|
5
|
+
...vi.requireActual("vue"),
|
|
6
6
|
onUnmounted: () => mockOnUnmounted,
|
|
7
7
|
}));
|
|
8
8
|
return mockOnUnmounted;
|