Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix(remax): 修复在父元素阻止冒泡时,点击子事件有可能不执行的问题 (#553)
Browse files Browse the repository at this point in the history
fix #552
  • Loading branch information
zcfan authored and Darmody committed Jan 1, 2020
1 parent a5649dc commit 4d60af3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/remax/src/SyntheticEvent/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ export default class SyntheticEventPool {
);
}

public initialEventState(eventType: string, eventId?: string) {
public initialEventState(
eventType: string,
eventId?: string,
currentEventID?: string
) {
if (!this.state[eventType]) {
this.state[eventType] = {};
}

if (eventId) {
if (eventId && currentEventID) {
this.state[eventType] = {
[eventId]: {
propagationStopped: false,
currentEventId: eventId,
currentEventId: currentEventID,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/remax/src/SyntheticEvent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function createCallbackProxy(

if (isNewEvent(eventType, nativeEvent)) {
// 新的事件流,初始化 store 数据
eventPool.initialEventState(eventType, eventId);
eventPool.initialEventState(eventType, eventId, currentEventId);
} else {
// 记录当前冒泡到的事件 ID
eventPool.setLatestEvent(eventType, eventId, currentEventId);
Expand Down
25 changes: 25 additions & 0 deletions packages/remax/src/__tests__/SyntheticEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,30 @@ describe('synthetic event', () => {

expect(bar).toBeCalledTimes(2);
});

it('invoke parent onClick callback every time with stopPropagation called', () => {
const foo = jest.fn(e => {
e.stopPropagation();
});
const fooProxy = createCallbackProxy('onClick', foo);

const event = {
target: {
dataset: {
rid: 1,
},
},
currentTarget: {
dataset: {
rid: 2,
},
},
};

fooProxy(event);
fooProxy(event);

expect(foo).toBeCalledTimes(2);
});
});
});

0 comments on commit 4d60af3

Please sign in to comment.