Skip to content

Commit

Permalink
Now logging CadenzaEvents instead of browser MessageEvents.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkissel committed Dec 5, 2023
1 parent f743083 commit 89b09c4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- Now logging `CadenzaEvent`s instead of browser `MessageEvent`s.

## 2.1.0 - 2023-11-29
### Added
Expand Down
8 changes: 4 additions & 4 deletions src/cadenza.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ export class CadenzaClient {

// Use arrow function so that it's bound to this.
#onMessage = (/** @type MessageEvent<CadenzaEvent<never>> */ event) => {
this.#log('Received message', event);
if (
event.origin !== this.#origin ||
event.source !== this.#requiredIframe.contentWindow
Expand All @@ -482,6 +481,7 @@ export class CadenzaClient {
}

const cadenzaEvent = event.data;
this.#log('Received message', cadenzaEvent);
this.#subscriptions.forEach(([type, subscriber]) => {
if (type === cadenzaEvent.type) {
subscriber(cadenzaEvent);
Expand All @@ -490,12 +490,12 @@ export class CadenzaClient {
};

#postEvent(/** @type string */ type, /** @type unknown */ detail) {
const event = { type, detail };
this.#log('postMessage', event);
const cadenzaEvent = { type, detail };
this.#log('postMessage', cadenzaEvent);
const contentWindow = /** @type {WindowProxy} */ (
this.#requiredIframe.contentWindow
);
contentWindow.postMessage(event, { targetOrigin: this.#origin });
contentWindow.postMessage(cadenzaEvent, { targetOrigin: this.#origin });
}

/**
Expand Down

0 comments on commit 89b09c4

Please sign in to comment.