Skip to content

Commit

Permalink
Merge pull request #1339 from VisActor/fix/Event-harmony
Browse files Browse the repository at this point in the history
Fix/event harmony
  • Loading branch information
xile611 authored Aug 5, 2024
2 parents 0e8bc88 + 496c024 commit 6a9a9a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-core",
"comment": "fix: fix issue with Event class in harmony event",
"type": "none"
}
],
"packageName": "@visactor/vrender-core"
}
21 changes: 17 additions & 4 deletions packages/vrender-core/src/event/federated-event/base-event.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isFunction } from '@visactor/vutils';
import type { IPickEventParams } from '../../interface';
import type { EventPoint, IEventTarget } from '../../interface/event';
import type { EventManager } from '../event-manager';
Expand Down Expand Up @@ -200,8 +201,14 @@ export class FederatedEvent<N extends Event = Event> implements Event {
}

preventDefault(): void {
if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
this.nativeEvent.preventDefault();
try {
if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
this.nativeEvent.preventDefault();
}
} catch (err) {
this.nativeEvent.preventDefault &&
isFunction(this.nativeEvent.preventDefault) &&
this.nativeEvent.preventDefault();
}

this.defaultPrevented = true;
Expand All @@ -212,8 +219,14 @@ export class FederatedEvent<N extends Event = Event> implements Event {
}

stopPropagation(): void {
if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
this.nativeEvent.stopPropagation();
try {
if (this.nativeEvent instanceof Event && this.nativeEvent.cancelable) {
this.nativeEvent.stopPropagation();
}
} catch (err) {
this.nativeEvent.stopPropagation &&
isFunction(this.nativeEvent.stopPropagation) &&
this.nativeEvent.stopPropagation();
}

this.propagationStopped = true;
Expand Down

0 comments on commit 6a9a9a3

Please sign in to comment.