Skip to content

Commit

Permalink
Apparently Flow doesn't like variables called event
Browse files Browse the repository at this point in the history
  • Loading branch information
poteto committed Sep 29, 2022
1 parent 436d6a5 commit 2abf7db
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ function commitUseEventMount(finishedWork: Fiber) {
// [EventFunctionWrapper, EventFunction, ...], so increment by 2 each iteration to find the next
// pair.
for (let ii = 0; ii < eventPayloads.length; ii += 2) {
const event: EventFunctionWrapper<any, any, any> = eventPayloads[ii];
const eventFn: EventFunctionWrapper<any, any, any> = eventPayloads[ii];
const nextImpl = eventPayloads[ii + 1];
event._impl = nextImpl;
eventFn._impl = nextImpl;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,9 @@ function commitUseEventMount(finishedWork: Fiber) {
// [EventFunctionWrapper, EventFunction, ...], so increment by 2 each iteration to find the next
// pair.
for (let ii = 0; ii < eventPayloads.length; ii += 2) {
const event: EventFunctionWrapper<any, any, any> = eventPayloads[ii];
const eventFn: EventFunctionWrapper<any, any, any> = eventPayloads[ii];
const nextImpl = eventPayloads[ii + 1];
event._impl = nextImpl;
eventFn._impl = nextImpl;
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -1898,29 +1898,28 @@ function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();

const event: EventFunctionWrapper<Args, Return, F> = function event() {
const eventFn: EventFunctionWrapper<Args, Return, F> = function eventFn() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error(
"A function wrapped in useEvent can't be called during rendering.",
);
}
return event._impl.apply(undefined, arguments);
return eventFn._impl.apply(undefined, arguments);
};
event._impl = callback;
eventFn._impl = callback;

useEventImpl(event, callback);
hook.memoizedState = event;
return event;
useEventImpl(eventFn, callback);
hook.memoizedState = eventFn;
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = updateWorkInProgressHook();
const event = hook.memoizedState;
useEventImpl(event, callback);
return event;
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
}

function mountInsertionEffect(
Expand Down
19 changes: 9 additions & 10 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -1898,29 +1898,28 @@ function mountEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = mountWorkInProgressHook();

const event: EventFunctionWrapper<Args, Return, F> = function event() {
const eventFn: EventFunctionWrapper<Args, Return, F> = function eventFn() {
if (isInvalidExecutionContextForEventFunction()) {
throw new Error(
"A function wrapped in useEvent can't be called during rendering.",
);
}
return event._impl.apply(undefined, arguments);
return eventFn._impl.apply(undefined, arguments);
};
event._impl = callback;
eventFn._impl = callback;

useEventImpl(event, callback);
hook.memoizedState = event;
return event;
useEventImpl(eventFn, callback);
hook.memoizedState = eventFn;
return eventFn;
}

function updateEvent<Args, Return, F: (...Array<Args>) => Return>(
callback: F,
): EventFunctionWrapper<Args, Return, F> {
const hook = updateWorkInProgressHook();
const event = hook.memoizedState;
useEventImpl(event, callback);
return event;
const eventFn = hook.memoizedState;
useEventImpl(eventFn, callback);
return eventFn;
}

function mountInsertionEffect(
Expand Down

0 comments on commit 2abf7db

Please sign in to comment.