Skip to content
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

Use Transferable type #281

Merged
merged 1 commit into from
May 11, 2019
Merged

Use Transferable type #281

merged 1 commit into from
May 11, 2019

Conversation

MattiasBuelens
Copy link
Contributor

TypeScript comes with a built-in type definition for transferable objects. Let's use it! 🙂

This changes the following types in Comlink's public API (dist/umd/comlink.d.ts):

 export interface TransferHandler {
     canHandle(obj: any): boolean;
-    serialize(obj: any): [any, any[]];
+    serialize(obj: any): [any, Transferable[]];
     deserialize(obj: any): any;
 }
-export declare function transfer(obj: any, transfers: any[]): any;
+export declare function transfer(obj: any, transfers: Transferable[]): any;

Copy link
Collaborator

@surma surma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant. Thank you :)

@MattiasBuelens
Copy link
Contributor Author

I'm not entirely sure what to do with the NodeEndpoint interface:

export interface NodeEndpoint {
  postMessage(message: any, transfer?: any[]): void;
}

We could change it to transfer?: Transferable[] as well, but then the endpoint would also have to accept ImageBitmap objects, which don't exist on Node. I guess we could define our own type instead?

export type NodeTransferable = ArrayBuffer | MessagePort;

Thoughts?

@surma surma merged commit 9e6a637 into GoogleChromeLabs:master May 11, 2019
@surma
Copy link
Collaborator

surma commented May 11, 2019

I'll leave any in Node for now. Needs more field testing anyways :)

@MattiasBuelens
Copy link
Contributor Author

Sounds good to me!

Thanks for the (insanely) fast merge! 😁

@MattiasBuelens MattiasBuelens deleted the transferable-type branch May 11, 2019 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants