| File: IJSObjectReference.cs | Web Access |
| Project: src\aspnetcore\src\JSInterop\Microsoft.JSInterop\src\Microsoft.JSInterop.csproj (Microsoft.JSInterop) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.CodeAnalysis; using static Microsoft.AspNetCore.Internal.LinkerFlags; namespace Microsoft.JSInterop; /// <summary> /// Represents a reference to a JavaScript object. /// </summary> public interface IJSObjectReference : IAsyncDisposable { /// <summary> /// Invokes the specified JavaScript function asynchronously. /// <para> /// <see cref="JSRuntime"/> will apply timeouts to this operation based on the value configured in <see cref="JSRuntime.DefaultAsyncTimeout"/>. To dispatch a call with a different, or no timeout, /// consider using <see cref="InvokeAsync{TValue}(string, CancellationToken, object[])" />. /// </para> /// </summary> /// <typeparam name="TValue">The JSON-serializable return type.</typeparam> /// <param name="identifier">An identifier for the function to invoke. For example, the value <c>"someScope.someFunction"</c> will invoke the function <c>someScope.someFunction</c> on the target instance.</param> /// <param name="args">JSON-serializable arguments.</param> /// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns> ValueTask<TValue> InvokeAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, object?[]? args); /// <summary> /// Invokes the specified JavaScript function asynchronously. /// </summary> /// <typeparam name="TValue">The JSON-serializable return type.</typeparam> /// <param name="identifier">An identifier for the function to invoke. For example, the value <c>"someScope.someFunction"</c> will invoke the function <c>someScope.someFunction</c> on the target instance.</param> /// <param name="cancellationToken"> /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. /// </param> /// <param name="args">JSON-serializable arguments.</param> /// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns> ValueTask<TValue> InvokeAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken, object?[]? args); /// <summary> /// Invokes the specified JavaScript constructor function asynchronously. The function is invoked with the <c>new</c> operator. /// </summary> /// <param name="identifier">An identifier for the constructor function to invoke. For example, the value <c>"someScope.SomeClass"</c> will invoke the constructor <c>someScope.SomeClass</c> on the target instance.</param> /// <param name="args">JSON-serializable arguments.</param> /// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns> ValueTask<IJSObjectReference> InvokeConstructorAsync(string identifier, object?[]? args) => throw new NotImplementedException(); /// <summary> /// Invokes the specified JavaScript constructor function asynchronously. The function is invoked with the <c>new</c> operator. /// </summary> /// <param name="identifier">An identifier for the constructor function to invoke. For example, the value <c>"someScope.SomeClass"</c> will invoke the constructor <c>someScope.SomeClass</c> on the target instance.</param> /// <param name="cancellationToken"> /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. /// </param> /// <param name="args">JSON-serializable arguments.</param> /// <returns>An <see cref="IJSObjectReference"/> instance that represents the created JS object.</returns> ValueTask<IJSObjectReference> InvokeConstructorAsync(string identifier, CancellationToken cancellationToken, object?[]? args) => throw new NotImplementedException(); /// <summary> /// Reads the value of the specified JavaScript property asynchronously. /// </summary> /// <typeparam name="TValue">The JSON-serializable return type.</typeparam> /// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>someScope.someProp</c> on the target instance.</param> /// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns> ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier) => throw new NotImplementedException(); /// <summary> /// Reads the value of the specified JavaScript property asynchronously. /// </summary> /// <typeparam name="TValue">The JSON-serializable return type.</typeparam> /// <param name="identifier">An identifier for the property to read. For example, the value <c>"someScope.someProp"</c> will read the value of the property <c>window.someScope.someProp</c>.</param> /// <param name="cancellationToken"> /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. /// </param> /// <returns>An instance of <typeparamref name="TValue"/> obtained by JSON-deserializing the return value.</returns> ValueTask<TValue> GetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, CancellationToken cancellationToken) => throw new NotImplementedException(); /// <summary> /// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created. /// </summary> /// <typeparam name="TValue">JSON-serializable argument type.</typeparam> /// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>someScope.someProp</c> on the target instance.</param> /// <param name="value">JSON-serializable value.</param> /// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns> ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value) => throw new NotImplementedException(); /// <summary> /// Updates the value of the specified JavaScript property asynchronously. If the property is not defined on the target object, it will be created. /// </summary> /// <typeparam name="TValue">JSON-serializable argument type.</typeparam> /// <param name="identifier">An identifier for the property to set. For example, the value <c>"someScope.someProp"</c> will update the property <c>someScope.someProp</c> on the target instance.</param> /// <param name="value">JSON-serializable value.</param> /// <param name="cancellationToken"> /// A cancellation token to signal the cancellation of the operation. Specifying this parameter will override any default cancellations such as due to timeouts /// (<see cref="JSRuntime.DefaultAsyncTimeout"/>) from being applied. /// </param> /// <returns>A <see cref="ValueTask"/> that represents the asynchronous invocation operation.</returns> ValueTask SetValueAsync<[DynamicallyAccessedMembers(JsonSerialized)] TValue>(string identifier, TValue value, CancellationToken cancellationToken) => throw new NotImplementedException(); }