Skip to content

Commit

Permalink
useOptimisticState -> useOptimistic (#26772)
Browse files Browse the repository at this point in the history
Drop the "state". Just "useOptimistic". It's cleaner.

This is still an experimental API. May not be the final name.

DiffTrain build for [b797282](b797282)
  • Loading branch information
acdlite committed May 3, 2023
1 parent 0b3882c commit 098e6fd
Show file tree
Hide file tree
Showing 28 changed files with 406 additions and 390 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
559e83aebb2026035d47aa0ebf842f78d4cd6757
b7972822b5887d05ae772ef757a453265b4b7aec
8 changes: 4 additions & 4 deletions compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-classic-9b9fa2f6";
var ReactVersion = "18.3.0-www-classic-53439320";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -2026,10 +2026,10 @@ function useEffectEvent(callback) {

return dispatcher.useEffectEvent(callback);
}
function useOptimisticState(passthrough, reducer) {
function useOptimistic(passthrough, reducer) {
var dispatcher = resolveDispatcher(); // $FlowFixMe[not-a-function] This is unstable, thus optional

return dispatcher.useOptimisticState(passthrough, reducer);
return dispatcher.useOptimistic(passthrough, reducer);
}

// Helpers to patch console.logs to avoid logging during side-effect free
Expand Down Expand Up @@ -4180,7 +4180,7 @@ exports.createMutableSource = createMutableSource;
exports.createRef = createRef;
exports.createServerContext = createServerContext;
exports.experimental_useEffectEvent = useEffectEvent;
exports.experimental_useOptimisticState = useOptimisticState;
exports.experimental_useOptimistic = useOptimistic;
exports.forwardRef = forwardRef;
exports.isValidElement = isValidElement$1;
exports.jsx = jsx;
Expand Down
8 changes: 4 additions & 4 deletions compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (
}
"use strict";

var ReactVersion = "18.3.0-www-modern-66e1909a";
var ReactVersion = "18.3.0-www-modern-171e8ddd";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -2026,10 +2026,10 @@ function useEffectEvent(callback) {

return dispatcher.useEffectEvent(callback);
}
function useOptimisticState(passthrough, reducer) {
function useOptimistic(passthrough, reducer) {
var dispatcher = resolveDispatcher(); // $FlowFixMe[not-a-function] This is unstable, thus optional

return dispatcher.useOptimisticState(passthrough, reducer);
return dispatcher.useOptimistic(passthrough, reducer);
}

// Helpers to patch console.logs to avoid logging during side-effect free
Expand Down Expand Up @@ -4144,7 +4144,7 @@ exports.createMutableSource = createMutableSource;
exports.createRef = createRef;
exports.createServerContext = createServerContext;
exports.experimental_useEffectEvent = useEffectEvent;
exports.experimental_useOptimisticState = useOptimisticState;
exports.experimental_useOptimistic = useOptimistic;
exports.forwardRef = forwardRef;
exports.isValidElement = isValidElement$1;
exports.jsx = jsx;
Expand Down
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,8 @@ exports.createServerContext = function (globalName, defaultValue) {
exports.experimental_useEffectEvent = function (callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.experimental_useOptimisticState = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimisticState(
passthrough,
reducer
);
exports.experimental_useOptimistic = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimistic(passthrough, reducer);
};
exports.forwardRef = function (render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -652,4 +649,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-f9e05cb4";
exports.version = "18.3.0-www-classic-f8d70dc8";
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,8 @@ exports.createServerContext = function (globalName, defaultValue) {
exports.experimental_useEffectEvent = function (callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.experimental_useOptimisticState = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimisticState(
passthrough,
reducer
);
exports.experimental_useOptimistic = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimistic(passthrough, reducer);
};
exports.forwardRef = function (render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -644,4 +641,4 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-2e6e6832";
exports.version = "18.3.0-www-modern-d4574969";
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,8 @@ exports.createServerContext = function (globalName, defaultValue) {
exports.experimental_useEffectEvent = function (callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.experimental_useOptimisticState = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimisticState(
passthrough,
reducer
);
exports.experimental_useOptimistic = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimistic(passthrough, reducer);
};
exports.forwardRef = function (render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -663,7 +660,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-8122ba25";
exports.version = "18.3.0-www-classic-7784bb55";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
9 changes: 3 additions & 6 deletions compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,11 +540,8 @@ exports.createServerContext = function (globalName, defaultValue) {
exports.experimental_useEffectEvent = function (callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.experimental_useOptimisticState = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimisticState(
passthrough,
reducer
);
exports.experimental_useOptimistic = function (passthrough, reducer) {
return ReactCurrentDispatcher.current.useOptimistic(passthrough, reducer);
};
exports.forwardRef = function (render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -655,7 +652,7 @@ exports.useSyncExternalStore = function (
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-eff148b0";
exports.version = "18.3.0-www-modern-7a4b93ac";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
88 changes: 47 additions & 41 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function _assertThisInitialized(self) {
return self;
}

var ReactVersion = "18.3.0-www-classic-993a41e1";
var ReactVersion = "18.3.0-www-classic-e737edcf";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -9440,7 +9440,7 @@ function rerenderState(initialState) {
return rerenderReducer(basicStateReducer);
}

function mountOptimisticState(passthrough, reducer) {
function mountOptimistic(passthrough, reducer) {
var hook = mountWorkInProgressHook();
hook.memoizedState = hook.baseState = passthrough;
var queue = {
Expand All @@ -9463,7 +9463,7 @@ function mountOptimisticState(passthrough, reducer) {
return [passthrough, dispatch];
}

function updateOptimisticState(passthrough, reducer) {
function updateOptimistic(passthrough, reducer) {
var hook = updateWorkInProgressHook(); // Optimistic updates are always rebased on top of the latest value passed in
// as an argument. It's called a passthrough because if there are no pending
// updates, it will be returned as-is.
Expand All @@ -9478,8 +9478,8 @@ function updateOptimisticState(passthrough, reducer) {
return updateReducerImpl(hook, currentHook, resolvedReducer);
}

function rerenderOptimisticState(passthrough, reducer) {
// Unlike useState, useOptimisticState doesn't support render phase updates.
function rerenderOptimistic(passthrough, reducer) {
// Unlike useState, useOptimistic 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 @@ -9488,7 +9488,7 @@ function rerenderOptimisticState(passthrough, reducer) {
// regular mount or update.
if (currentHook !== null) {
// This is an update. Process the update queue.
return updateOptimisticState(passthrough, reducer);
return updateOptimistic(passthrough, reducer);
} // This is a mount. No updates to process.

var hook = updateWorkInProgressHook(); // Reset the base state and memoized state to the passthrough. Future
Expand Down Expand Up @@ -10456,7 +10456,7 @@ var ContextOnlyDispatcher = {
}

if (enableAsyncActions) {
ContextOnlyDispatcher.useOptimisticState = throwInvalidHookError;
ContextOnlyDispatcher.useOptimistic = throwInvalidHookError;
}

var HooksDispatcherOnMountInDEV = null;
Expand Down Expand Up @@ -10626,12 +10626,14 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
HooksDispatcherOnMountInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
mountHookTypesDev();
return mountOptimisticState(passthrough);
};
HooksDispatcherOnMountInDEV.useOptimistic = function useOptimistic(
passthrough,
reducer
) {
currentHookNameInDev = "useOptimistic";
mountHookTypesDev();
return mountOptimistic(passthrough);
};
}

HooksDispatcherOnMountWithHookTypesInDEV = {
Expand Down Expand Up @@ -10768,11 +10770,11 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
HooksDispatcherOnMountWithHookTypesInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
HooksDispatcherOnMountWithHookTypesInDEV.useOptimistic =
function useOptimistic(passthrough, reducer) {
currentHookNameInDev = "useOptimistic";
updateHookTypesDev();
return mountOptimisticState(passthrough);
return mountOptimistic(passthrough);
};
}

Expand Down Expand Up @@ -10910,12 +10912,14 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
HooksDispatcherOnUpdateInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
updateHookTypesDev();
return updateOptimisticState(passthrough, reducer);
};
HooksDispatcherOnUpdateInDEV.useOptimistic = function useOptimistic(
passthrough,
reducer
) {
currentHookNameInDev = "useOptimistic";
updateHookTypesDev();
return updateOptimistic(passthrough, reducer);
};
}

HooksDispatcherOnRerenderInDEV = {
Expand Down Expand Up @@ -11053,12 +11057,14 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
HooksDispatcherOnRerenderInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
updateHookTypesDev();
return rerenderOptimisticState(passthrough, reducer);
};
HooksDispatcherOnRerenderInDEV.useOptimistic = function useOptimistic(
passthrough,
reducer
) {
currentHookNameInDev = "useOptimistic";
updateHookTypesDev();
return rerenderOptimistic(passthrough, reducer);
};
}

InvalidNestedHooksDispatcherOnMountInDEV = {
Expand Down Expand Up @@ -11219,12 +11225,12 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
InvalidNestedHooksDispatcherOnMountInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
InvalidNestedHooksDispatcherOnMountInDEV.useOptimistic =
function useOptimistic(passthrough, reducer) {
currentHookNameInDev = "useOptimistic";
warnInvalidHookAccess();
mountHookTypesDev();
return mountOptimisticState(passthrough);
return mountOptimistic(passthrough);
};
}

Expand Down Expand Up @@ -11386,12 +11392,12 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
InvalidNestedHooksDispatcherOnUpdateInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
InvalidNestedHooksDispatcherOnUpdateInDEV.useOptimistic =
function useOptimistic(passthrough, reducer) {
currentHookNameInDev = "useOptimistic";
warnInvalidHookAccess();
updateHookTypesDev();
return updateOptimisticState(passthrough, reducer);
return updateOptimistic(passthrough, reducer);
};
}

Expand Down Expand Up @@ -11553,12 +11559,12 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

if (enableAsyncActions) {
InvalidNestedHooksDispatcherOnRerenderInDEV.useOptimisticState =
function useOptimisticState(passthrough, reducer) {
currentHookNameInDev = "useOptimisticState";
InvalidNestedHooksDispatcherOnRerenderInDEV.useOptimistic =
function useOptimistic(passthrough, reducer) {
currentHookNameInDev = "useOptimistic";
warnInvalidHookAccess();
updateHookTypesDev();
return rerenderOptimisticState(passthrough, reducer);
return rerenderOptimistic(passthrough, reducer);
};
}
}
Expand Down
Loading

0 comments on commit 098e6fd

Please sign in to comment.