@peter.naydenov/walk-async 2.0.2 → 3.0.1
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/Changelog.md +10 -0
- package/Migration.guide.md +23 -0
- package/package.json +8 -8
- package/src/main.js +22 -14
package/Changelog.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
### 3.0.1 ( 2024-12-18)
|
|
5
|
+
- [x] Dependencies updates. Ask-for-promise to version 3.0.1;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 3.0.0 ( 2024-12-04)
|
|
10
|
+
- [x] Object callback will be triggered on 'root' object as well;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
4
14
|
|
|
5
15
|
### 2.0.2 ( 2024-01-31)
|
|
6
16
|
- [x] Dev dependencies updates. Chai to version 5.0.3;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Migration Guides
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## From v.2.x.x - v.3.x.x
|
|
6
|
+
Difference between v.2.x.x and v.3.x.x is that object callbacks are triggered on 'root' object as well. So if you have object callbacks that are not working as expected after upgrade, you need to add extra line of code for version 3.
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
// version 2
|
|
10
|
+
function oCallbackFn ({ value:o, key, IGNORE }) {
|
|
11
|
+
// Some code
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// version 3
|
|
15
|
+
function oCallbackFn ({ value:o, key, IGNORE, breadcrumbs }) {
|
|
16
|
+
if ( breadcrumbs === 'root' ) return o // Extra line of code for version 3
|
|
17
|
+
// Some code
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Everything else works the same.
|
|
22
|
+
|
|
23
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/walk-async",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Deep copy with fine control during the process. Can be used also as a deep forEach function",
|
|
5
5
|
"main": ".dist/walk-async.umd.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"author": "Peter Naydenov",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"ask-for-promise": "
|
|
29
|
+
"ask-for-promise": "3.0.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@rollup/plugin-commonjs": "^
|
|
33
|
-
"@rollup/plugin-node-resolve": "^
|
|
32
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
34
34
|
"@rollup/plugin-terser": "^0.4.4",
|
|
35
|
-
"c8": "^
|
|
36
|
-
"chai": "^5.
|
|
37
|
-
"mocha": "^
|
|
38
|
-
"rollup": "^4.
|
|
35
|
+
"c8": "^10.1.3",
|
|
36
|
+
"chai": "^5.1.2",
|
|
37
|
+
"mocha": "^11.0.1",
|
|
38
|
+
"rollup": "^4.28.1"
|
|
39
39
|
},
|
|
40
40
|
"c8": {
|
|
41
41
|
"include": [
|
package/src/main.js
CHANGED
|
@@ -31,16 +31,16 @@ function walk ({
|
|
|
31
31
|
, cb = [ keyCallback, objectCallback ]
|
|
32
32
|
, end = askForPromise ()
|
|
33
33
|
;
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
switch ( type ) {
|
|
36
36
|
case 'array' :
|
|
37
37
|
result = []
|
|
38
|
-
copyObject ( origin, result, extend, cb, breadcrumbs, ...args )
|
|
38
|
+
copyObject ( {root:origin}, result, extend, cb, breadcrumbs, ...args )
|
|
39
39
|
.then ( () => goNext ( extend, result, end ))
|
|
40
40
|
break
|
|
41
41
|
case 'object' :
|
|
42
42
|
result = {}
|
|
43
|
-
copyObject ( origin, result, extend, cb, breadcrumbs, ...args )
|
|
43
|
+
copyObject ( {root:origin}, result, extend, cb, breadcrumbs, ...args )
|
|
44
44
|
.then ( () => {
|
|
45
45
|
goNext ( extend, result, end )
|
|
46
46
|
})
|
|
@@ -106,6 +106,8 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
106
106
|
, resultIsArray = (findType (result) === 'array')
|
|
107
107
|
, keyNumber = !isNaN ( k )
|
|
108
108
|
, IGNORE = Symbol ( 'ignore___' )
|
|
109
|
+
, isRoot = (breadcrumbs === 'root' && k === 'root' )
|
|
110
|
+
, br = isRoot ? 'root' : `${breadcrumbs}/${k}`
|
|
109
111
|
;
|
|
110
112
|
|
|
111
113
|
if ( hasObjectCallback ) {
|
|
@@ -114,7 +116,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
114
116
|
, reject : () => objectCallbackTask.done ( IGNORE )
|
|
115
117
|
, value : item
|
|
116
118
|
, key : k
|
|
117
|
-
, breadcrumbs :
|
|
119
|
+
, breadcrumbs : br
|
|
118
120
|
}, ...args )
|
|
119
121
|
}
|
|
120
122
|
else {
|
|
@@ -122,7 +124,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
objectCallbackTask.onComplete ( res => {
|
|
125
|
-
if ( res === '$$cancel' &&
|
|
127
|
+
if ( res === '$$cancel' && !keyCallback ) { // deep copy, no callbacks
|
|
126
128
|
keyCallbackTask.done ( '$$noUpdates' )
|
|
127
129
|
return
|
|
128
130
|
}
|
|
@@ -131,7 +133,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
131
133
|
type = findType ( item )
|
|
132
134
|
}
|
|
133
135
|
if ( item == IGNORE ) {
|
|
134
|
-
executeCallback[i].done ( 'ignore object' )
|
|
136
|
+
executeCallback.promises[i].done ( 'ignore object' )
|
|
135
137
|
return
|
|
136
138
|
}
|
|
137
139
|
if ( type === 'simple' ) {
|
|
@@ -144,7 +146,7 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
144
146
|
, reject : () => keyCallbackTask.done ( IGNORE )
|
|
145
147
|
, value : item
|
|
146
148
|
, key : k
|
|
147
|
-
, breadcrumbs :
|
|
149
|
+
, breadcrumbs : br
|
|
148
150
|
}, ...args );
|
|
149
151
|
}
|
|
150
152
|
else {
|
|
@@ -153,8 +155,13 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
153
155
|
}) // objectCallbackTask complete
|
|
154
156
|
|
|
155
157
|
keyCallbackTask.onComplete ( value => {
|
|
158
|
+
if ( isRoot ) {
|
|
159
|
+
extend.push ( generateList ( item, result, extend, cb, 'root', args ) )
|
|
160
|
+
executeCallback.promises[i].done ( 'root' )
|
|
161
|
+
return
|
|
162
|
+
}
|
|
156
163
|
if ( value == IGNORE ) {
|
|
157
|
-
executeCallback[i].done ( 'ignore key' )
|
|
164
|
+
executeCallback.promises[i].done ( 'ignore key' )
|
|
158
165
|
return
|
|
159
166
|
}
|
|
160
167
|
if ( value === '$$cancel' ) {
|
|
@@ -163,15 +170,16 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
163
170
|
}
|
|
164
171
|
if ( value !== '$$noUpdates' ) {
|
|
165
172
|
item = value
|
|
166
|
-
type = findType ( item )
|
|
173
|
+
type = findType ( item )
|
|
167
174
|
}
|
|
168
175
|
if ( type === 'simple' ) {
|
|
169
176
|
const canInsert = validateForInsertion ( k, result )
|
|
170
177
|
if ( canInsert ) result.push ( item )
|
|
171
178
|
else result [k] = item
|
|
172
|
-
executeCallback[i].done ('key')
|
|
179
|
+
executeCallback.promises[i].done ('key')
|
|
173
180
|
return
|
|
174
181
|
}
|
|
182
|
+
|
|
175
183
|
finishWithCallbacks.done ()
|
|
176
184
|
}) // keyCallbackTask complete
|
|
177
185
|
|
|
@@ -180,15 +188,15 @@ function copyObject ( origin, result, extend, cb, breadcrumbs, ...args ) {
|
|
|
180
188
|
const newObject = {};
|
|
181
189
|
if ( resultIsArray && keyNumber ) result.push ( newObject )
|
|
182
190
|
else result[k] = newObject
|
|
183
|
-
extend.push ( generateList( item, newObject, extend, cb,
|
|
184
|
-
executeCallback[i].done ('object')
|
|
191
|
+
extend.push ( generateList( item, newObject, extend, cb, br, args ) )
|
|
192
|
+
executeCallback.promises[i].done ('object')
|
|
185
193
|
}
|
|
186
194
|
if ( type === 'array' ) {
|
|
187
195
|
const newArray = [];
|
|
188
196
|
if ( resultIsArray && keyNumber ) result.push ( newArray )
|
|
189
197
|
else result[k] = newArray
|
|
190
|
-
extend.push ( generateList( item, newArray, extend, cb,
|
|
191
|
-
executeCallback[i].done ('array')
|
|
198
|
+
extend.push ( generateList( item, newArray, extend, cb, br, args ) )
|
|
199
|
+
executeCallback.promises[i].done ('array')
|
|
192
200
|
}
|
|
193
201
|
})
|
|
194
202
|
}) // forEach k
|