@@ -54,16 +54,14 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
54
54
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
55
55
thisArg ?: unknown ,
56
56
) {
57
- const result = apply ( this , 'filter' , fn , thisArg )
58
- return isProxy ( this ) && ! isShallow ( this ) ? result . map ( toReactive ) : result
57
+ return apply ( this , 'filter' , fn , thisArg , v => v . map ( toReactive ) )
59
58
} ,
60
59
61
60
find (
62
61
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
63
62
thisArg ?: unknown ,
64
63
) {
65
- const result = apply ( this , 'find' , fn , thisArg )
66
- return isProxy ( this ) && ! isShallow ( this ) ? toReactive ( result ) : result
64
+ return apply ( this , 'find' , fn , thisArg , toReactive )
67
65
} ,
68
66
69
67
findIndex (
@@ -77,8 +75,7 @@ export const arrayInstrumentations: Record<string | symbol, Function> = <any>{
77
75
fn : ( item : unknown , index : number , array : unknown [ ] ) => boolean ,
78
76
thisArg ?: unknown ,
79
77
) {
80
- const result = apply ( this , 'findLast' , fn , thisArg )
81
- return isProxy ( this ) && ! isShallow ( this ) ? toReactive ( result ) : result
78
+ return apply ( this , 'findLast' , fn , thisArg , toReactive )
82
79
} ,
83
80
84
81
findLastIndex (
@@ -237,11 +234,14 @@ function apply(
237
234
method : ArrayMethods ,
238
235
fn : ( item : unknown , index : number , array : unknown [ ] ) => unknown ,
239
236
thisArg ?: unknown ,
237
+ wrappedRetFn ?: ( result : any ) => unknown ,
240
238
) {
241
239
const arr = shallowReadArray ( self )
240
+ let needsWrap = false
242
241
let wrappedFn = fn
243
242
if ( arr !== self ) {
244
- if ( ! isShallow ( self ) ) {
243
+ needsWrap = ! isShallow ( self )
244
+ if ( needsWrap ) {
245
245
wrappedFn = function ( this : unknown , item , index ) {
246
246
return fn . call ( this , toReactive ( item ) , index , self )
247
247
}
@@ -252,7 +252,8 @@ function apply(
252
252
}
253
253
}
254
254
// @ts -expect-error our code is limited to es2016 but user code is not
255
- return arr [ method ] ( wrappedFn , thisArg )
255
+ const result = arr [ method ] ( wrappedFn , thisArg )
256
+ return needsWrap && wrappedRetFn ? wrappedRetFn ( result ) : result
256
257
}
257
258
258
259
// instrument reduce and reduceRight to take ARRAY_ITERATE dependency
0 commit comments