Skip to content

Commit

Permalink
s/form state/action state (#28631)
Browse files Browse the repository at this point in the history
Rename internals from "form state" to "action state"

DiffTrain build for commit 05797cc.
  • Loading branch information
rickhanlonii committed Mar 28, 2024
1 parent d9c978d commit 9e0cbef
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<9163dccf70951cc5d1bae88f3bef99d1>>
* @generated SignedSource<<e3c2cd0dc2c519bacd879ada7f0bbba4>>
*/

"use strict";
Expand Down Expand Up @@ -9122,10 +9122,10 @@ if (__DEV__) {
hook.baseState = passthrough;
var dispatch = hook.queue.dispatch;
return [passthrough, dispatch];
} // useFormState actions run sequentially, because each action receives the
} // useActionState actions run sequentially, because each action receives the
// previous state as an argument. We store pending actions on a queue.

function dispatchFormState(
function dispatchActionState(
fiber,
actionQueue,
setPendingState,
Expand All @@ -9146,7 +9146,7 @@ if (__DEV__) {
next: null // circular
};
newLast.next = actionQueue.pending = newLast;
runFormStateAction(actionQueue, setPendingState, setState, payload);
runActionStateAction(actionQueue, setPendingState, setState, payload);
} else {
// There's already an action running. Add to the queue.
var first = last.next;
Expand All @@ -9158,7 +9158,7 @@ if (__DEV__) {
}
}

function runFormStateAction(
function runActionStateAction(
actionQueue,
setPendingState,
setState,
Expand Down Expand Up @@ -9195,14 +9195,14 @@ if (__DEV__) {
thenable.then(
function (nextState) {
actionQueue.state = nextState;
finishRunningFormStateAction(
finishRunningActionStateAction(
actionQueue,
setPendingState,
setState
);
},
function () {
return finishRunningFormStateAction(
return finishRunningActionStateAction(
actionQueue,
setPendingState,
setState
Expand All @@ -9214,10 +9214,14 @@ if (__DEV__) {
setState(returnValue);
var nextState = returnValue;
actionQueue.state = nextState;
finishRunningFormStateAction(actionQueue, setPendingState, setState);
finishRunningActionStateAction(
actionQueue,
setPendingState,
setState
);
}
} catch (error) {
// This is a trick to get the `useFormState` hook to rethrow the error.
// This is a trick to get the `useActionState` hook to rethrow the error.
// When it unwraps the thenable with the `use` algorithm, the error
// will be thrown.
var rejectedThenable = {
Expand All @@ -9226,7 +9230,7 @@ if (__DEV__) {
reason: error // $FlowFixMe: Not sure why this doesn't work
};
setState(rejectedThenable);
finishRunningFormStateAction(actionQueue, setPendingState, setState);
finishRunningActionStateAction(actionQueue, setPendingState, setState);
} finally {
ReactCurrentBatchConfig$2.transition = prevTransition;

Expand All @@ -9248,7 +9252,7 @@ if (__DEV__) {
}
}

function finishRunningFormStateAction(
function finishRunningActionStateAction(
actionQueue,
setPendingState,
setState
Expand All @@ -9268,7 +9272,7 @@ if (__DEV__) {
var next = first.next;
last.next = next; // Run the next action.

runFormStateAction(
runActionStateAction(
actionQueue,
setPendingState,
setState,
Expand All @@ -9278,11 +9282,11 @@ if (__DEV__) {
}
}

function formStateReducer(oldState, newState) {
function actionStateReducer(oldState, newState) {
return newState;
}

function mountFormState(action, initialStateProp, permalink) {
function mountActionState(action, initialStateProp, permalink) {
var initialState = initialStateProp;
// the `use` algorithm during render.

Expand All @@ -9294,7 +9298,7 @@ if (__DEV__) {
pending: null,
lanes: NoLanes,
dispatch: null,
lastRenderedReducer: formStateReducer,
lastRenderedReducer: actionStateReducer,
lastRenderedState: initialState
};
stateHook.queue = stateQueue;
Expand Down Expand Up @@ -9326,7 +9330,7 @@ if (__DEV__) {
pending: null
};
actionQueueHook.queue = actionQueue;
var dispatch = dispatchFormState.bind(
var dispatch = dispatchActionState.bind(
null,
currentlyRenderingFiber$1,
actionQueue,
Expand All @@ -9341,13 +9345,13 @@ if (__DEV__) {
return [initialState, dispatch, false];
}

function updateFormState(action, initialState, permalink) {
function updateActionState(action, initialState, permalink) {
var stateHook = updateWorkInProgressHook();
var currentStateHook = currentHook;
return updateFormStateImpl(stateHook, currentStateHook, action);
return updateActionStateImpl(stateHook, currentStateHook, action);
}

function updateFormStateImpl(
function updateActionStateImpl(
stateHook,
currentStateHook,
action,
Expand All @@ -9357,7 +9361,7 @@ if (__DEV__) {
var _updateReducerImpl = updateReducerImpl(
stateHook,
currentStateHook,
formStateReducer
actionStateReducer
),
actionResult = _updateReducerImpl[0];

Expand All @@ -9380,7 +9384,7 @@ if (__DEV__) {
currentlyRenderingFiber$1.flags |= Passive$1;
pushEffect(
HasEffect | Passive,
formStateActionEffect.bind(null, actionQueue, action),
actionStateActionEffect.bind(null, actionQueue, action),
createEffectInstance(),
null
);
Expand All @@ -9389,12 +9393,12 @@ if (__DEV__) {
return [state, dispatch, isPending];
}

function formStateActionEffect(actionQueue, action) {
function actionStateActionEffect(actionQueue, action) {
actionQueue.action = action;
}

function rerenderFormState(action, initialState, permalink) {
// Unlike useState, useFormState doesn't support render phase updates.
function rerenderActionState(action, initialState, permalink) {
// Unlike useState, useActionState doesn't support render phase updates.
// Also unlike useState, we need to replay all pending updates again in case
// the passthrough value changed.
//
Expand All @@ -9406,7 +9410,7 @@ if (__DEV__) {

if (currentStateHook !== null) {
// This is an update. Process the update queue.
return updateFormStateImpl(stateHook, currentStateHook, action);
return updateActionStateImpl(stateHook, currentStateHook, action);
}

updateWorkInProgressHook(); // State
Expand Down Expand Up @@ -10466,7 +10470,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useFormState";
mountHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};

HooksDispatcherOnMountInDEV.useActionState = function useActionState(
Expand All @@ -10476,7 +10480,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useActionState";
mountHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};
}

Expand Down Expand Up @@ -10622,14 +10626,14 @@ if (__DEV__) {
function useFormState(action, initialState, permalink) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};

HooksDispatcherOnMountWithHookTypesInDEV.useActionState =
function useActionState(action, initialState, permalink) {
currentHookNameInDev = "useActionState";
updateHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};
}

Expand Down Expand Up @@ -10776,7 +10780,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
return updateFormState(action);
return updateActionState(action);
};

HooksDispatcherOnUpdateInDEV.useActionState = function useActionState(
Expand All @@ -10786,7 +10790,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useActionState";
updateHookTypesDev();
return updateFormState(action);
return updateActionState(action);
};
}

Expand Down Expand Up @@ -10935,7 +10939,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useFormState";
updateHookTypesDev();
return rerenderFormState(action);
return rerenderActionState(action);
};

HooksDispatcherOnRerenderInDEV.useActionState = function useActionState(
Expand All @@ -10945,7 +10949,7 @@ if (__DEV__) {
) {
currentHookNameInDev = "useActionState";
updateHookTypesDev();
return rerenderFormState(action);
return rerenderActionState(action);
};
}

Expand Down Expand Up @@ -11116,15 +11120,15 @@ if (__DEV__) {
currentHookNameInDev = "useFormState";
warnInvalidHookAccess();
mountHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};

InvalidNestedHooksDispatcherOnMountInDEV.useActionState =
function useActionState(action, initialState, permalink) {
currentHookNameInDev = "useActionState";
warnInvalidHookAccess();
mountHookTypesDev();
return mountFormState(action, initialState);
return mountActionState(action, initialState);
};
}

Expand Down Expand Up @@ -11294,15 +11298,15 @@ if (__DEV__) {
currentHookNameInDev = "useFormState";
warnInvalidHookAccess();
updateHookTypesDev();
return updateFormState(action);
return updateActionState(action);
};

InvalidNestedHooksDispatcherOnUpdateInDEV.useActionState =
function useActionState(action, initialState, permalink) {
currentHookNameInDev = "useActionState";
warnInvalidHookAccess();
updateHookTypesDev();
return updateFormState(action);
return updateActionState(action);
};
}

Expand Down Expand Up @@ -11472,15 +11476,15 @@ if (__DEV__) {
currentHookNameInDev = "useFormState";
warnInvalidHookAccess();
updateHookTypesDev();
return rerenderFormState(action);
return rerenderActionState(action);
};

InvalidNestedHooksDispatcherOnRerenderInDEV.useActionState =
function useActionState(action, initialState, permalink) {
currentHookNameInDev = "useActionState";
warnInvalidHookAccess();
updateHookTypesDev();
return rerenderFormState(action);
return rerenderActionState(action);
};
}

Expand Down Expand Up @@ -26246,7 +26250,7 @@ if (__DEV__) {
return root;
}

var ReactVersion = "19.0.0-canary-9cf58c47";
var ReactVersion = "19.0.0-canary-04ac921d";

// Might add PROFILE later.

Expand Down
Loading

0 comments on commit 9e0cbef

Please sign in to comment.