Skip to content

Commit

Permalink
Rename experimental useEvent to useEffectEvent (#25881)
Browse files Browse the repository at this point in the history
We originally had grand plans for using this Event concept for more but
now it's only meant to be used in combination with effects.

It's an Event in the FRP terms, that is triggered from an Effect.
Technically it can also be from another function that itself is
triggered from an existing side-effect but that's kind of an advanced
case.

The canonical case is an effect that triggers an event:

```js
const onHappened = useEffectEvent(() => ...);
useEffect(() => {
  onHappened();
}, []);
```

DiffTrain build for [84a0a17](84a0a17)
[View git log for this commit](https://github.com/facebook/react/commits/84a0a171ea0ecd25e287bd3d3dd30e932beb4677)
  • Loading branch information
sebmarkbage committed Dec 14, 2022
1 parent 385f204 commit 6b30524
Show file tree
Hide file tree
Showing 31 changed files with 249 additions and 225 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4dda96a4071d2cc4bbcc444438cfacee991f07e2
84a0a171ea0ecd25e287bd3d3dd30e932beb4677
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4dda96a4071d2cc4bbcc444438cfacee991f07e2
84a0a171ea0ecd25e287bd3d3dd30e932beb4677
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-4dda96a40-20221213";
var ReactVersion = "18.3.0-www-classic-84a0a171e-20221214";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -2054,10 +2054,10 @@ function useMemoCache(size) {

return dispatcher.useMemoCache(size);
}
function useEvent(callback) {
function useEffectEvent(callback) {
var dispatcher = resolveDispatcher(); // $FlowFixMe This is unstable, thus optional

return dispatcher.useEvent(callback);
return dispatcher.useEffectEvent(callback);
}

// Helpers to patch console.logs to avoid logging during side-effect free
Expand Down Expand Up @@ -4197,7 +4197,7 @@ exports.createFactory = createFactory;
exports.createMutableSource = createMutableSource;
exports.createRef = createRef;
exports.createServerContext = createServerContext;
exports.experimental_useEvent = useEvent;
exports.experimental_useEffectEvent = useEffectEvent;
exports.forwardRef = forwardRef;
exports.isValidElement = isValidElement;
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-4dda96a40-20221213";
var ReactVersion = "18.3.0-www-modern-84a0a171e-20221214";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -2054,10 +2054,10 @@ function useMemoCache(size) {

return dispatcher.useMemoCache(size);
}
function useEvent(callback) {
function useEffectEvent(callback) {
var dispatcher = resolveDispatcher(); // $FlowFixMe This is unstable, thus optional

return dispatcher.useEvent(callback);
return dispatcher.useEffectEvent(callback);
}

// Helpers to patch console.logs to avoid logging during side-effect free
Expand Down Expand Up @@ -4161,7 +4161,7 @@ exports.createElement = createElement$1;
exports.createMutableSource = createMutableSource;
exports.createRef = createRef;
exports.createServerContext = createServerContext;
exports.experimental_useEvent = useEvent;
exports.experimental_useEffectEvent = useEffectEvent;
exports.forwardRef = forwardRef;
exports.isValidElement = isValidElement;
exports.jsx = jsx;
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ exports.createServerContext = function(globalName, defaultValue) {
throw Error("ServerContext: " + globalName + " already defined");
return context$1;
};
exports.experimental_useEvent = function(callback) {
return ReactCurrentDispatcher.current.useEvent(callback);
exports.experimental_useEffectEvent = function(callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.forwardRef = function(render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -643,4 +643,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-4dda96a40-20221213";
exports.version = "18.3.0-www-classic-84a0a171e-20221214";
6 changes: 3 additions & 3 deletions compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ exports.createServerContext = function(globalName, defaultValue) {
throw Error("ServerContext: " + globalName + " already defined");
return context$1;
};
exports.experimental_useEvent = function(callback) {
return ReactCurrentDispatcher.current.useEvent(callback);
exports.experimental_useEffectEvent = function(callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.forwardRef = function(render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -635,4 +635,4 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-4dda96a40-20221213";
exports.version = "18.3.0-www-modern-84a0a171e-20221214";
6 changes: 3 additions & 3 deletions compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ exports.createServerContext = function(globalName, defaultValue) {
throw Error("ServerContext: " + globalName + " already defined");
return context$1;
};
exports.experimental_useEvent = function(callback) {
return ReactCurrentDispatcher.current.useEvent(callback);
exports.experimental_useEffectEvent = function(callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.forwardRef = function(render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -654,7 +654,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-classic-4dda96a40-20221213";
exports.version = "18.3.0-www-classic-84a0a171e-20221214";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ exports.createServerContext = function(globalName, defaultValue) {
throw Error("ServerContext: " + globalName + " already defined");
return context$1;
};
exports.experimental_useEvent = function(callback) {
return ReactCurrentDispatcher.current.useEvent(callback);
exports.experimental_useEffectEvent = function(callback) {
return ReactCurrentDispatcher.current.useEffectEvent(callback);
};
exports.forwardRef = function(render) {
return { $$typeof: REACT_FORWARD_REF_TYPE, render: render };
Expand Down Expand Up @@ -646,7 +646,7 @@ exports.useSyncExternalStore = function(
);
};
exports.useTransition = useTransition;
exports.version = "18.3.0-www-modern-4dda96a40-20221213";
exports.version = "18.3.0-www-modern-84a0a171e-20221214";

/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
if (
Expand Down
50 changes: 28 additions & 22 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-4dda96a40-20221213";
var ReactVersion = "18.3.0-www-classic-84a0a171e-20221214";

var LegacyRoot = 0;
var ConcurrentRoot = 1;
Expand Down Expand Up @@ -8899,7 +8899,7 @@ function updateEffect(create, deps) {
updateEffectImpl(Passive, Passive$1, create, deps);
}

function useEventImpl(payload) {
function useEffectEventImpl(payload) {
currentlyRenderingFiber.flags |= Update;
var componentUpdateQueue = currentlyRenderingFiber.updateQueue;

Expand Down Expand Up @@ -8928,7 +8928,7 @@ function mountEvent(callback) {
return function eventFn() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error(
"A function wrapped in useEvent can't be called during rendering."
"A function wrapped in useEffectEvent can't be called during rendering."
);
}

Expand All @@ -8939,15 +8939,15 @@ function mountEvent(callback) {
function updateEvent(callback) {
var hook = updateWorkInProgressHook();
var ref = hook.memoizedState;
useEventImpl({
useEffectEventImpl({
ref: ref,
nextImpl: callback
}); // $FlowIgnore[incompatible-return]

return function eventFn() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error(
"A function wrapped in useEvent can't be called during rendering."
"A function wrapped in useEffectEvent can't be called during rendering."
);
}

Expand Down Expand Up @@ -9570,7 +9570,7 @@ var ContextOnlyDispatcher = {
}

{
ContextOnlyDispatcher.useEvent = throwInvalidHookError;
ContextOnlyDispatcher.useEffectEvent = throwInvalidHookError;
}

var HooksDispatcherOnMountInDEV = null;
Expand Down Expand Up @@ -9730,8 +9730,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
HooksDispatcherOnMountInDEV.useEvent = function useEvent(callback) {
currentHookNameInDev = "useEvent";
HooksDispatcherOnMountInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEffectEvent";
mountHookTypesDev();
return mountEvent(callback);
};
Expand Down Expand Up @@ -9861,10 +9863,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
HooksDispatcherOnMountWithHookTypesInDEV.useEvent = function useEvent(
HooksDispatcherOnMountWithHookTypesInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEvent";
currentHookNameInDev = "useEffectEvent";
updateHookTypesDev();
return mountEvent(callback);
};
Expand Down Expand Up @@ -9994,8 +9996,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
HooksDispatcherOnUpdateInDEV.useEvent = function useEvent(callback) {
currentHookNameInDev = "useEvent";
HooksDispatcherOnUpdateInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEffectEvent";
updateHookTypesDev();
return updateEvent(callback);
};
Expand Down Expand Up @@ -10125,8 +10129,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
HooksDispatcherOnRerenderInDEV.useEvent = function useEvent(callback) {
currentHookNameInDev = "useEvent";
HooksDispatcherOnRerenderInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEffectEvent";
updateHookTypesDev();
return updateEvent(callback);
};
Expand Down Expand Up @@ -10279,10 +10285,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
InvalidNestedHooksDispatcherOnMountInDEV.useEvent = function useEvent(
InvalidNestedHooksDispatcherOnMountInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEvent";
currentHookNameInDev = "useEffectEvent";
warnInvalidHookAccess();
mountHookTypesDev();
return mountEvent(callback);
Expand Down Expand Up @@ -10436,10 +10442,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
InvalidNestedHooksDispatcherOnUpdateInDEV.useEvent = function useEvent(
InvalidNestedHooksDispatcherOnUpdateInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEvent";
currentHookNameInDev = "useEffectEvent";
warnInvalidHookAccess();
updateHookTypesDev();
return updateEvent(callback);
Expand Down Expand Up @@ -10593,10 +10599,10 @@ var InvalidNestedHooksDispatcherOnRerenderInDEV = null;
}

{
InvalidNestedHooksDispatcherOnRerenderInDEV.useEvent = function useEvent(
InvalidNestedHooksDispatcherOnRerenderInDEV.useEffectEvent = function useEffectEvent(
callback
) {
currentHookNameInDev = "useEvent";
currentHookNameInDev = "useEffectEvent";
warnInvalidHookAccess();
updateHookTypesDev();
return updateEvent(callback);
Expand Down Expand Up @@ -18965,7 +18971,7 @@ function commitBeforeMutationEffectsOnFiber(finishedWork) {
case FunctionComponent: {
{
if ((flags & Update) !== NoFlags) {
commitUseEventMount(finishedWork);
commitUseEffectEventMount(finishedWork);
}
}

Expand Down Expand Up @@ -19244,7 +19250,7 @@ function commitHookEffectListMount(flags, finishedWork) {
}
}

function commitUseEventMount(finishedWork) {
function commitUseEffectEventMount(finishedWork) {
var updateQueue = finishedWork.updateQueue;
var eventPayloads = updateQueue !== null ? updateQueue.events : null;

Expand Down
Loading

0 comments on commit 6b30524

Please sign in to comment.