1
1
import { options as _options } from 'preact' ;
2
- import { SKIP_CHILDREN } from 'preact /src/constants' ;
2
+ import { SKIP_CHILDREN } from '../.. /src/constants' ;
3
3
4
4
/** @type {number } */
5
5
let currentIndex ;
@@ -25,6 +25,7 @@ let oldAfterDiff = options.diffed;
25
25
let oldCommit = options . _commit ;
26
26
let oldBeforeUnmount = options . unmount ;
27
27
let oldRoot = options . _root ;
28
+ let oldAfterRender = options . _afterRender ;
28
29
29
30
const RAF_TIMEOUT = 100 ;
30
31
let prevRaf ;
@@ -194,12 +195,10 @@ export function useReducer(reducer, initialState, init) {
194
195
195
196
if ( hookState . _actions . length ) {
196
197
const initialValue = hookState . _value [ 0 ] ;
197
- hookState . _actions . forEach ( action => {
198
- const value = hookState . _value [ 0 ] ;
199
- hookState . _value [ 0 ] = hookState . _reducer ( value , action ) ;
198
+ hookState . _actions . some ( action => {
199
+ hookState . _value [ 0 ] = hookState . _reducer ( hookState . _value [ 0 ] , action ) ;
200
200
} ) ;
201
201
202
- hookState . _actions = [ ] ;
203
202
// This is incorrect, we set this shallowly based on the last state
204
203
// which means that if 2 useReducer calls have actions and the last one
205
204
// settles to an equal state we bail the previous one as well. This should
@@ -208,19 +207,19 @@ export function useReducer(reducer, initialState, init) {
208
207
hookState . _didUpdate = initialValue !== hookState . _value [ 0 ] ;
209
208
hookState . _value = [ hookState . _value [ 0 ] , hookState . _value [ 1 ] ] ;
210
209
hookState . _didExecute = true ;
210
+ hookState . _actions = [ ] ;
211
211
}
212
212
213
213
return hookState . _value ;
214
214
}
215
215
216
- const oldAfterRender = options . _afterRender ;
217
216
options . _afterRender = ( newVNode , oldVNode ) => {
218
217
if ( newVNode . _component && newVNode . _component . __hooks ) {
219
218
const hooks = newVNode . _component . __hooks . _list ;
220
219
const stateHooksThatExecuted = hooks . filter (
221
220
/** @type {(x: import('./internal').HookState) => x is import('./internal').ReducerHookState } */
222
221
// @ts -expect-error
223
- x => ! ! x . _component && x . _didExecute
222
+ x => x . _component && x . _didExecute
224
223
) ;
225
224
226
225
if (
@@ -232,9 +231,8 @@ options._afterRender = (newVNode, oldVNode) => {
232
231
newVNode . _flags |= SKIP_CHILDREN ;
233
232
}
234
233
235
- stateHooksThatExecuted . forEach ( hook => {
236
- hook . _didUpdate = undefined ;
237
- hook . _didExecute = false ;
234
+ stateHooksThatExecuted . some ( hook => {
235
+ hook . _didExecute = hook . _didUpdate = false ;
238
236
} ) ;
239
237
}
240
238
0 commit comments