MCPcopy Create free account
hub / github.com/microsoft/SandDance / rerenderReducer

Function rerenderReducer

docs/external/js/react-dom.development.js:15299–15350  ·  view source on GitHub ↗
(reducer, initialArg, init)

Source from the content-addressed store, hash-verified

15297 }
15298
15299 function rerenderReducer(reducer, initialArg, init) {
15300 var hook = updateWorkInProgressHook();
15301 var queue = hook.queue;
15302
15303 if (!(queue !== null)) {
15304 {
15305 throw Error( "Should have a queue. This is likely a bug in React. Please file an issue." );
15306 }
15307 }
15308
15309 queue.lastRenderedReducer = reducer; // This is a re-render. Apply the new render phase updates to the previous
15310 // work-in-progress hook.
15311
15312 var dispatch = queue.dispatch;
15313 var lastRenderPhaseUpdate = queue.pending;
15314 var newState = hook.memoizedState;
15315
15316 if (lastRenderPhaseUpdate !== null) {
15317 // The queue doesn't persist past this render pass.
15318 queue.pending = null;
15319 var firstRenderPhaseUpdate = lastRenderPhaseUpdate.next;
15320 var update = firstRenderPhaseUpdate;
15321
15322 do {
15323 // Process this render phase update. We don't have to check the
15324 // priority because it will always be the same as the current
15325 // render's.
15326 var action = update.action;
15327 newState = reducer(newState, action);
15328 update = update.next;
15329 } while (update !== firstRenderPhaseUpdate); // Mark that the fiber performed work, but only if the new state is
15330 // different from the current state.
15331
15332
15333 if (!objectIs(newState, hook.memoizedState)) {
15334 markWorkInProgressReceivedUpdate();
15335 }
15336
15337 hook.memoizedState = newState; // Don't persist the state accumulated from the render phase updates to
15338 // the base state unless the queue is empty.
15339 // TODO: Not sure if this is the desired semantics, but it's what we
15340 // do for gDSFP. I can't remember why.
15341
15342 if (hook.baseQueue === null) {
15343 hook.baseState = newState;
15344 }
15345
15346 queue.lastRenderedState = newState;
15347 }
15348
15349 return [newState, dispatch];
15350 }
15351
15352 function mountState(initialState) {
15353 var hook = mountWorkInProgressHook();

Callers 2

rerenderStateFunction · 0.85

Calls 3

updateWorkInProgressHookFunction · 0.85
reducerFunction · 0.85

Tested by

no test coverage detected