Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew-Daniels committed Aug 6, 2024
1 parent b4d6fa7 commit 29168d4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions libs/core/src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export interface ParentOpts extends BaseClientOpts {
}

export interface IFrameOpts extends BaseClientOpts {
// TODO: Add support for multiple whitelisted URLs - in cases where the iFrame could be used in different sites
/** The URL where your iframe expects to receive messages from: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#targetorigin */
targetOrigin: string;
}

Expand All @@ -54,15 +52,14 @@ export class ClientContract {
window.removeEventListener('message', this.onMessageEvent);
}

// Have to use arrow function here to preserve `this`
protected onMessageEvent = (messageEvent: MessageEvent) => {
if (this.isWhitelisted(messageEvent)) {
if (this.isSignal(messageEvent)) {
const { name, args = {} } = messageEvent.data;
this.callEffect(name, args);
}
}
}
};

private callEffect(name: string, args: Record<string, unknown>) {
if (this.effects[name]) {
Expand All @@ -75,10 +72,8 @@ export class ClientContract {
}

private isSignal(e: MessageEvent): e is SignalEvent {
if (e.data as Signal) {
return true;
}
return false;
const { data } = e;
return 'name' in data;
}

private isWhitelisted(messageEvent: MessageEvent) {
Expand Down

0 comments on commit 29168d4

Please sign in to comment.