-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only export core types from messaging #1188
Draft
shakyShane
wants to merge
1
commit into
main
Choose a base branch
from
11-01-only_export_core_types_from_messaging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,16 @@ | |
* - Implementation Guide: {@link "Messaging Implementation Guide"} | ||
* | ||
* @module Messaging | ||
* | ||
* @import { WindowsMessagingConfig, } from './lib/windows.js' | ||
* @import { WebkitMessagingConfig, WebkitMessagingTransport } from './lib/webkit.js'; | ||
* @import { AndroidMessagingConfig } from './lib/android.js'; | ||
* @typedef {WebkitMessagingConfig | WindowsMessagingConfig | AndroidMessagingConfig | TestTransportConfig} MessagingConfig | ||
* @typedef {{intoMessaging: (ctx: MessagingContext) => Messaging}} IntoMessaging | ||
* | ||
*/ | ||
import { WindowsMessagingConfig, WindowsMessagingTransport, WindowsInteropMethods, WindowsNotification, WindowsRequestMessage } from './lib/windows.js' | ||
import { WebkitMessagingConfig, WebkitMessagingTransport } from './lib/webkit.js' | ||
|
||
import { NotificationMessage, RequestMessage, Subscription, MessageResponse, MessageError, SubscriptionEvent } from './schema.js' | ||
import { AndroidMessagingConfig, AndroidMessagingTransport } from './lib/android.js' | ||
import { createTypedMessages } from './lib/typed-messages.js' | ||
|
||
/** | ||
|
@@ -45,20 +50,22 @@ export class MessagingContext { | |
} | ||
|
||
/** | ||
* @typedef {WebkitMessagingConfig | WindowsMessagingConfig | AndroidMessagingConfig | TestTransportConfig} MessagingConfig | ||
*/ | ||
|
||
/** | ||
* | ||
* The consumer interface | ||
*/ | ||
export class Messaging { | ||
/** | ||
* @param {MessagingContext} messagingContext | ||
* @param {MessagingConfig} config | ||
* @param {MessagingTransport} transport | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the significant change here, is that we directly take a transport now, preventing the core library needing to know about them all ahead of time |
||
*/ | ||
constructor (messagingContext, config) { | ||
constructor (messagingContext, transport) { | ||
/** | ||
* @internal | ||
*/ | ||
this.messagingContext = messagingContext | ||
this.transport = getTransport(config, this.messagingContext) | ||
/** | ||
* @internal | ||
*/ | ||
this.transport = transport | ||
} | ||
|
||
/** | ||
|
@@ -164,6 +171,7 @@ export class MessagingTransport { | |
* It's useful for debugging, and for enabling scripts to run in | ||
* other environments - for example, testing in a browser without the need | ||
* for a full integration | ||
* @implements IntoMessaging | ||
*/ | ||
export class TestTransportConfig { | ||
/** | ||
|
@@ -172,6 +180,13 @@ export class TestTransportConfig { | |
constructor (impl) { | ||
this.impl = impl | ||
} | ||
|
||
/** | ||
* @param {MessagingContext} context | ||
*/ | ||
intoMessaging (context) { | ||
return new Messaging(context, new TestTransport(this, context)) | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -200,27 +215,6 @@ export class TestTransport { | |
} | ||
} | ||
|
||
/** | ||
* @param {WebkitMessagingConfig | WindowsMessagingConfig | AndroidMessagingConfig | TestTransportConfig} config | ||
* @param {MessagingContext} messagingContext | ||
* @returns {MessagingTransport} | ||
*/ | ||
function getTransport (config, messagingContext) { | ||
if (config instanceof WebkitMessagingConfig) { | ||
return new WebkitMessagingTransport(config, messagingContext) | ||
} | ||
if (config instanceof WindowsMessagingConfig) { | ||
return new WindowsMessagingTransport(config, messagingContext) | ||
} | ||
if (config instanceof AndroidMessagingConfig) { | ||
return new AndroidMessagingTransport(config, messagingContext) | ||
} | ||
if (config instanceof TestTransportConfig) { | ||
return new TestTransport(config, messagingContext) | ||
} | ||
throw new Error('unreachable') | ||
} | ||
|
||
/** | ||
* Thrown when a handler cannot be found | ||
*/ | ||
|
@@ -239,20 +233,11 @@ export class MissingHandler extends Error { | |
* Some re-exports for convenience | ||
*/ | ||
export { | ||
WebkitMessagingConfig, | ||
WebkitMessagingTransport, | ||
WindowsMessagingConfig, | ||
WindowsMessagingTransport, | ||
WindowsInteropMethods, | ||
NotificationMessage, | ||
RequestMessage, | ||
Subscription, | ||
MessageResponse, | ||
MessageError, | ||
SubscriptionEvent, | ||
WindowsNotification, | ||
WindowsRequestMessage, | ||
AndroidMessagingConfig, | ||
AndroidMessagingTransport, | ||
createTypedMessages | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By reversing the dependency here, it prevents the Messaging constructor from having to know about every transport