Skip to content

Commit

Permalink
capricorn86#1092@patch: Simplifies MessageEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrotoff committed Sep 24, 2023
1 parent 99cee75 commit 4d515d3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/happy-dom/src/event/events/MessageEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ import IMessageEventInit from './IMessageEventInit.js';
* @see https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
*/
export default class MessageEvent extends Event {
public data?: unknown | null = null;
public origin?: string = '';
public lastEventId?: string = '';
public source?: IWindow | null = null;
public ports?: IMessagePort[] = [];
public readonly data: unknown | null;
public readonly origin: string;
public readonly lastEventId: string;
public readonly source: IWindow | null;
public readonly ports: IMessagePort[];

/**
* Constructor.
*
* @param type Event type.
* @param [eventInit] Event init.
*/
constructor(type: string, eventInit?: IMessageEventInit) {
constructor(type: string, eventInit: IMessageEventInit = {}) {
super(type, eventInit);
this.data = eventInit?.data !== undefined ? eventInit.data : null;
this.origin = eventInit?.origin || '';
this.lastEventId = eventInit?.lastEventId || '';
this.source = eventInit?.source || null;
this.ports = eventInit?.ports || [];

this.data = eventInit.data ?? null;
this.origin = eventInit.origin ?? '';
this.lastEventId = eventInit.lastEventId ?? '';
this.source = eventInit.source ?? null;
this.ports = eventInit.ports ?? [];
}
}

0 comments on commit 4d515d3

Please sign in to comment.