@@ -35,17 +35,16 @@ const emptyObject = {};
35
35
36
36
function collectScopedNodes (
37
37
node : Fiber ,
38
- fn : ( type : string | Object , props : Object ) = > boolean ,
38
+ fn : ( type : string | Object , props : Object , instance : Object ) = > boolean ,
39
39
scopedNodes : Array < any > ,
40
- searchNode : null | Set < Object > ,
41
40
) : void {
42
41
if ( enableScopeAPI ) {
43
42
if ( node . tag === HostComponent ) {
44
- const instance = getPublicInstance ( node . stateNode ) ;
45
- const { type , memoizedProps } = node ;
43
+ const { type , memoizedProps , stateNode } = node ;
44
+ const instance = getPublicInstance ( stateNode ) ;
46
45
if (
47
- ( searchNode !== null && searchNode . has ( instance ) ) ||
48
- fn ( type , memoizedProps || emptyObject ) === true
46
+ instance !== null &&
47
+ fn ( type , memoizedProps || emptyObject , instance ) === true
49
48
) {
50
49
scopedNodes . push ( instance ) ;
51
50
}
@@ -56,20 +55,21 @@ function collectScopedNodes(
56
55
child = getSuspenseFallbackChild ( node ) ;
57
56
}
58
57
if ( child !== null ) {
59
- collectScopedNodesFromChildren ( child , fn , scopedNodes , searchNode ) ;
58
+ collectScopedNodesFromChildren ( child , fn , scopedNodes ) ;
60
59
}
61
60
}
62
61
}
63
62
64
63
function collectFirstScopedNode (
65
64
node : Fiber ,
66
- fn : ( type : string | Object , props : Object ) = > boolean ,
65
+ fn : ( type : string | Object , props : Object , instance : Object ) = > boolean ,
67
66
) : null | Object {
68
67
if ( enableScopeAPI ) {
69
68
if ( node . tag === HostComponent ) {
70
- const { type , memoizedProps } = node ;
71
- if ( fn ( type , memoizedProps ) === true ) {
72
- return getPublicInstance ( node . stateNode ) ;
69
+ const { type , memoizedProps , stateNode } = node ;
70
+ const instance = getPublicInstance ( stateNode ) ;
71
+ if ( instance !== null && fn ( type , memoizedProps , instance ) === true ) {
72
+ return instance ;
73
73
}
74
74
}
75
75
let child = node . child ;
@@ -86,20 +86,19 @@ function collectFirstScopedNode(
86
86
87
87
function collectScopedNodesFromChildren (
88
88
startingChild : Fiber ,
89
- fn : ( type : string | Object , props : Object ) = > boolean ,
89
+ fn : ( type : string | Object , props : Object , instance : Object ) = > boolean ,
90
90
scopedNodes : Array < any > ,
91
- searchNode : null | Set < Object > ,
92
91
) : void {
93
92
let child = startingChild ;
94
93
while ( child !== null ) {
95
- collectScopedNodes ( child , fn , scopedNodes , searchNode ) ;
94
+ collectScopedNodes ( child , fn , scopedNodes ) ;
96
95
child = child . sibling ;
97
96
}
98
97
}
99
98
100
99
function collectFirstScopedNodeFromChildren (
101
100
startingChild : Fiber ,
102
- fn : ( type : string | Object , props : Object ) = > boolean ,
101
+ fn : ( type : string | Object , props : Object , instance : Object ) = > boolean ,
103
102
) : Object | null {
104
103
let child = startingChild ;
105
104
while ( child !== null ) {
@@ -197,20 +196,18 @@ export function createScopeMethods(
197
196
return currentFiber . memoizedProps ;
198
197
} ,
199
198
queryAllNodes (
200
- fn : ( type : string | Object , props : Object ) = > boolean ,
201
- searchNodes ?: Array < Object > ,
199
+ fn : ( type : string | Object , props : Object , instance : Object ) = > boolean ,
202
200
) : null | Array < Object > {
203
201
const currentFiber = ( ( instance . fiber : any ) : Fiber ) ;
204
202
const child = currentFiber . child ;
205
203
const scopedNodes = [ ] ;
206
- const searchNodeSet = searchNodes ? new Set ( searchNodes ) : null ;
207
204
if ( child !== null ) {
208
- collectScopedNodesFromChildren ( child , fn , scopedNodes , searchNodeSet ) ;
205
+ collectScopedNodesFromChildren ( child , fn , scopedNodes ) ;
209
206
}
210
207
return scopedNodes . length === 0 ? null : scopedNodes ;
211
208
} ,
212
209
queryFirstNode (
213
- fn : ( type : string | Object , props : Object ) => boolean ,
210
+ fn : ( type : string | Object , props : Object , instance : Object ) => boolean ,
214
211
) : null | Object {
215
212
const currentFiber = ( ( instance . fiber : any ) : Fiber ) ;
216
213
const child = currentFiber . child ;
0 commit comments