Skip to content

Commit 54e9c76

Browse files
SteveSandersonMSguardrexcaptainsafia
authored
Add README.md for JSInterop (#28074)
* Add README.md for JSInterop * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md Co-authored-by: Luke Latham <[email protected]> * Update src/JSInterop/README.md * Update src/JSInterop/README.md Co-authored-by: Safia Abdalla <[email protected]> Co-authored-by: Luke Latham <[email protected]> Co-authored-by: Safia Abdalla <[email protected]>
1 parent d7187b0 commit 54e9c76

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

src/JSInterop/README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
1-
# jsinterop
1+
# JSInterop
22

3-
This repo is for `Microsoft.JSInterop`, a package that provides abstractions and features for interop between .NET and JavaScript code.
3+
This directory contains sources for [`Microsoft.JSInterop`](https://www.nuget.org/packages/Microsoft.JSInterop), a package that provides abstractions and features for interop between .NET and JavaScript code.
44

5-
## Usage
5+
The primary use case is for applications built with Blazor. For usage information, see the following documentation:
66

7-
The primary use case is for applications built with Mono WebAssembly or Blazor. It's not expected that developers will typically use these libraries separately from Mono WebAssembly, Blazor, or a similar technology.
7+
* [Call JavaScript functions from .NET methods in ASP.NET Core Blazor](https://docs.microsoft.com/aspnet/core/blazor/call-javascript-from-dotnet)
8+
* [Call .NET methods from JavaScript functions in ASP.NET Core Blazor](https://docs.microsoft.com/aspnet/core/blazor/call-dotnet-from-javascript)
89

10+
## Description
11+
12+
This section provides a brief overview of the architecture.
13+
14+
`Microsoft.JSInterop` is a .NET package with the following roles:
15+
16+
* Defining abstractions to describe how .NET code can invoke JavaScript code and pass parameters. These abstractions include `IJSRuntime`, `IJSInProcessRuntime`, `DotNetObjectReference`, `IJSObjectReference`, and others.
17+
* Providing platform-independent abstract base class implementations of those abstractions, such as `JSRuntime` and `JSObjectReference`. These implement common logic around handling errors and asynchrony, even though they are independent of any particular runtime environment.
18+
* Providing extension methods on `IJSRuntime` that simplify making calls with differing numbers of parameters, cancellation tokens, and other characteristics.
19+
20+
For these types to become usable in a particular runtime environment, such as Blazor Server or Blazor WebAssembly, the runtime environment implements its own concrete subclasses that know how to dispatch calls to the actual JavaScript runtime that is available in that environment. For example, Blazor Server uses the SignalR-based circuit to send invocations to the end user's browser.
21+
22+
`Microsoft.JSInterop.JS` is the JavaScript-side counterpart to the preceding. It runs within a standard web browser environment, receives the invocations from .NET code, executes them, and sends back results in the format understood by the `JSRuntime` base class. This includes special handling for certain parameter types such as `ElementReference` and `DotNetObjectReference`. `Microsoft.JSInterop.JS` also exposes JavaScript functions that can be used to issue calls from JavaScript to .NET.
23+
24+
Since `Microsoft.JSInterop.JS` is platform-independent, runtime environments such as Blazor Server or Blazor WebAssembly must initialize it by registering environment-specific callbacks that know how to dispatch invocations across their own communication channels.
25+
26+
## Development Setup
27+
28+
### Build and test
29+
30+
To build the .NET code, you can:
31+
32+
* Run `dotnet build` in the `Microsoft.JSInterop/src` directory. You can also read more [on building a subset of the code](../../docs/BuildFromSource.md#building-a-subset-of-the-code).
33+
* Run `dotnet build` or `dotnet test` in the `Microsoft.JSInterop/test` directory. You can also read more about how to [run the tests on the command line](../../docs/BuildFromSource.md#running-tests-on-command-line).
34+
35+
Alternatively, open `JSInterop.slnf` in Visual Studio.
36+
37+
To build the JavaScript code, execute the following commands in a command shell:
38+
39+
* `cd Microsoft.JSInterop.JS/src`
40+
* `npm run preclean`
41+
* `npm run build`
42+
43+
**Warning:** Due to special requirements related to ASP.NET Core's CI process for Linux distributions, we store the compiled JavaScript artifacts for `Microsoft.JSInterop.JS` in source control in the `Microsoft.JSInterop.JS/src/dist` directory. If you edit and build JavaScript sources, your Git client should indicate that those outputs have changed. You will need to include changes to those `dist` files in any PRs that you submit. When this leads to merge conflicts, we have to resolve them manually by rebasing and rebuilding.
44+
45+
## More Information
46+
47+
For more information, see the [ASP.NET Core README](../../README.md).

0 commit comments

Comments
 (0)