@@ -60,7 +60,7 @@ options._render = vnode => {
60
60
if ( previousComponent === currentComponent ) {
61
61
hooks . _pendingEffects = [ ] ;
62
62
currentComponent . _renderCallbacks = [ ] ;
63
- hooks . _list . forEach ( hookItem => {
63
+ hooks . _list . some ( hookItem => {
64
64
if ( hookItem . _nextValue ) {
65
65
hookItem . _value = hookItem . _nextValue ;
66
66
}
@@ -83,7 +83,7 @@ options.diffed = vnode => {
83
83
const c = vnode . _component ;
84
84
if ( c && c . __hooks ) {
85
85
if ( c . __hooks . _pendingEffects . length ) afterPaint ( afterPaintEffects . push ( c ) ) ;
86
- c . __hooks . _list . forEach ( hookItem => {
86
+ c . __hooks . _list . some ( hookItem => {
87
87
if ( hookItem . _pendingArgs ) {
88
88
hookItem . _args = hookItem . _pendingArgs ;
89
89
}
@@ -121,7 +121,7 @@ options.unmount = vnode => {
121
121
const c = vnode . _component ;
122
122
if ( c && c . __hooks ) {
123
123
let hasErrored ;
124
- c . __hooks . _list . forEach ( s => {
124
+ c . __hooks . _list . some ( s => {
125
125
try {
126
126
invokeCleanup ( s ) ;
127
127
} catch ( e ) {
@@ -133,6 +133,23 @@ options.unmount = vnode => {
133
133
}
134
134
} ;
135
135
136
+ /**
137
+ *
138
+ * @returns {import('./internal').HookState }
139
+ */
140
+ function createHookState ( ) {
141
+ return {
142
+ _value : undefined ,
143
+ _args : undefined ,
144
+ _cleanup : undefined ,
145
+ _pendingArgs : undefined ,
146
+ _component : undefined ,
147
+ _reducer : undefined ,
148
+ _context : undefined ,
149
+ _factory : undefined
150
+ } ;
151
+ }
152
+
136
153
/**
137
154
* Get a hook's state from the currentComponent
138
155
* @param {number } index The index of the hook to get
@@ -158,7 +175,7 @@ function getHookState(index, type) {
158
175
} ) ;
159
176
160
177
if ( index >= hooks . _list . length ) {
161
- hooks . _list . push ( { } ) ;
178
+ hooks . _list . push ( createHookState ( ) ) ;
162
179
}
163
180
164
181
return hooks . _list [ index ] ;
@@ -248,7 +265,7 @@ export function useReducer(reducer, initialState, init) {
248
265
let shouldUpdate =
249
266
hookState . _component . props !== p ||
250
267
hooksList . every ( x => ! x . _nextValue ) ;
251
- hooksList . forEach ( hookItem => {
268
+ hooksList . some ( hookItem => {
252
269
if ( hookItem . _nextValue ) {
253
270
const currentValue = hookItem . _value [ 0 ] ;
254
271
hookItem . _value = hookItem . _nextValue ;
0 commit comments