Skip to content

Commit

Permalink
fix: replace Window type with reduced types (#306)
Browse files Browse the repository at this point in the history
fix: replace Window type with reduced types
  • Loading branch information
surma authored Jun 16, 2019
2 parents 75e9c62 + e42601d commit 22c11c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/comlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

import {
Endpoint,
EventSource,
Message,
MessageType,
PostMessageWithOrigin,
WireValue,
WireValueType
} from "./protocol.js";
Expand Down Expand Up @@ -245,7 +247,10 @@ export function proxy<T>(obj: T): T & { [proxyMarker]: true } {
return Object.assign(obj, { [proxyMarker]: true }) as any;
}

export function windowEndpoint(w: Window, context = self): Endpoint {
export function windowEndpoint(
w: PostMessageWithOrigin,
context: EventSource = self
): Endpoint {
return {
postMessage: (msg: any, transferables: Transferable[]) =>
w.postMessage(msg, "*", transferables),
Expand Down
15 changes: 13 additions & 2 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
* limitations under the License.
*/

export interface Endpoint {
postMessage(message: any, transfer?: Transferable[]): void;
export interface EventSource {
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
Expand All @@ -23,6 +22,18 @@ export interface Endpoint {
listener: EventListenerOrEventListenerObject,
options?: {}
): void;
}

export interface PostMessageWithOrigin {
postMessage(
message: any,
targetOrigin: string,
transfer?: Transferable[]
): void;
}

export interface Endpoint extends EventSource {
postMessage(message: any, transfer?: Transferable[]): void;
start?: () => void;
}

Expand Down

0 comments on commit 22c11c9

Please sign in to comment.