Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Naming changes
  • Loading branch information
poteto committed Sep 29, 2022
commit a015335daba6d6b74a085125b658e9931b412a1e
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,11 @@ function commitHookEffectListMount(flags: HookFlags, finishedWork: Fiber) {

function commitUseEventMount(finishedWork: Fiber) {
const updateQueue: FunctionComponentUpdateQueue | null = (finishedWork.updateQueue: any);
const eventStates = updateQueue !== null ? updateQueue.events : null;
if (eventStates !== null) {
for (let ii = 0; ii < eventStates.length; ii++) {
const eventState = eventStates[ii];
eventState.event._current = eventState.nextEvent;
const eventPayloads = updateQueue !== null ? updateQueue.events : null;
if (eventPayloads !== null) {
for (let ii = 0; ii < eventPayloads.length; ii++) {
const eventPayload = eventPayloads[ii];
eventPayload.event._impl = eventPayload.nextImpl;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,19 @@ type StoreConsistencyCheck<T> = {
getSnapshot: () => T,
};

type EventFunctionState<T> = {
type EventFunctionPayload<T> = {
event: EventFunctionWrapper<T>,
nextEvent: EventFunction<T>,
nextImpl: EventFunction<T>,
};
type EventFunctionWrapper<T> = {
(): T,
_current: EventFunction<T>,
_impl: EventFunction<T>,
};
type EventFunction<T> = () => T;

export type FunctionComponentUpdateQueue = {
lastEffect: Effect | null,
events: Array<EventFunctionState<any>> | null,
events: Array<EventFunctionPayload<any>> | null,
stores: Array<StoreConsistencyCheck<any>> | null,
// NOTE: optional, only set when enableUseMemoCacheHook is enabled
memoCache?: MemoCache | null,
Expand Down Expand Up @@ -1883,20 +1883,20 @@ function updateEffect(
return updateEffectImpl(PassiveEffect, HookPassive, create, deps);
}

function useEventImpl<T>(event: EventFunction<T>, nextEvent: () => T) {
const eventState = {event, nextEvent};
function useEventImpl<T>(event: EventFunction<T>, nextImpl: () => T) {
const eventPayload = {event, nextImpl};
currentlyRenderingFiber.flags |= UpdateEffect;
let componentUpdateQueue: null | FunctionComponentUpdateQueue = (currentlyRenderingFiber.updateQueue: any);
if (componentUpdateQueue === null) {
componentUpdateQueue = createFunctionComponentUpdateQueue();
currentlyRenderingFiber.updateQueue = (componentUpdateQueue: any);
componentUpdateQueue.events = [eventState];
componentUpdateQueue.events = [eventPayload];
} else {
const events = componentUpdateQueue.events;
if (events === null) {
componentUpdateQueue.events = [eventState];
componentUpdateQueue.events = [eventPayload];
} else {
events.push(eventState);
events.push(eventPayload);
}
}
}
Expand All @@ -1910,9 +1910,9 @@ function mountEvent<T>(callback: () => T): () => T {
"A function wrapped in useEvent can't be called during rendering.",
);
}
return event._current.apply(undefined, arguments);
return event._impl.apply(undefined, arguments);
}
event._current = callback;
event._impl = callback;

useEventImpl(event, callback);
hook.memoizedState = event;
Expand Down