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

instance interop #143

Merged
merged 47 commits into from
Feb 5, 2024
Merged

instance interop #143

merged 47 commits into from
Feb 5, 2024

Conversation

elringus
Copy link
Owner

@elringus elringus commented Feb 1, 2024

This adds support for interop via object instances.

When an interface is supplied as argument or return type of an interop method, instead of serializing it as value, Bootsharp will instead generate an instance binding, eg:

public interface IExported { string GetFromCSharp (); }
public interface IImported { string GetFromJavaScript (); }

public class Exported : IExported
{
    public string GetFromCSharp () => "cs";
}

public static partial class Factory
{
    [JSInvokable] public static IExported GetExported () => new Exported();
    [JSFunction] public static partial IImported GetImported ();
}

var imported = Factory.GetImported();
imported.GetFromJavaScript(); //returns "js"
import { Factory, IImported } from "bootsharp";

class Imported implements IImported {
    getFromJavaScript() { return "js"; }
}

Factory.getImported = () => new Imported();

const exported = Factory.getExported();
exported.getFromCSharp(); // returns "cs"

Interop instances are subject to the following limitations:

  • Can't be args or return values of other interop instance method
  • Can't be args of events
  • Interfaces from "System" namespace are not qualified

Resolves #84.

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a5cc885) 100.00% compared to head (e093d86) 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #143    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           42        45     +3     
  Lines         1425      1653   +228     
  Branches       246       296    +50     
==========================================
+ Hits          1425      1653   +228     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@elringus elringus added the enhancement New feature or enhancement label Feb 1, 2024
@elringus elringus merged commit 4656f67 into main Feb 5, 2024
8 checks passed
@elringus elringus deleted the feat/instance branch February 5, 2024 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript declarations for IJSObjectReference
1 participant