/// <summary> /// Return a reference to the JS instance located on the given property /// </summary> /// <param name="jsRuntime">Current JS runtime</param> /// <param name="jsObjectRef">Reference to the parent instance</param> /// <param name="propertyPath">property path</param> /// <returns></returns> public static async ValueTask <JsRuntimeObjectRef> GetInstancePropertyRef(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, string propertyPath) { var jsRuntimeObjectRef = await jsRuntime.InvokeAsync <JsRuntimeObjectRef>("browserInterop.getInstancePropertyRef", jsObjectRef, propertyPath).ConfigureAwait(false); jsRuntimeObjectRef.JsRuntime = jsRuntime; return(jsRuntimeObjectRef); }
/// <summary> /// Add an event listener to the given property and event Type /// </summary> /// <param name="jsRuntime"></param> /// <param name="jsRuntimeObject"></param> /// <param name="propertyName"></param> /// <param name="eventName"></param> /// <param name="callBack"></param> /// <returns></returns> public static async ValueTask <IAsyncDisposable> AddEventListener(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsRuntimeObject, string propertyName, string eventName, CallBackInteropWrapper callBack) { var listenerId = await jsRuntime.InvokeAsync <int>("browserInterop.addEventListener", jsRuntimeObject, propertyName, eventName, callBack).ConfigureAwait(false); return(new ActionAsyncDisposable(async() => await jsRuntime.InvokeVoidAsync("browserInterop.removeEventListener", jsRuntimeObject, propertyName, eventName, listenerId).ConfigureAwait(false))); }
/// <summary> /// Call the method on the js instance and return the result /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="windowObject">Reference to the JS instance</param> /// <param name="methodName">Method name/path </param> /// <param name="arguments">method arguments</param> /// <returns></returns> public static async ValueTask <T> InvokeInstanceMethod <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef windowObject, string methodName, params object[] arguments) { if (jsRuntime is null) { throw new ArgumentNullException(nameof(jsRuntime)); } if (windowObject is null) { throw new ArgumentNullException(nameof(windowObject)); } return(await jsRuntime.InvokeAsync <T>("browserInterop.callInstanceMethod", new object[] { windowObject, methodName }.Concat(arguments).ToArray()).ConfigureAwait(false)); }
/// <summary> /// Call the method on the js instance and return the wrapper of the js object /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="windowObject">Reference to the JS instance</param> /// <param name="methodName">Method name/path </param> /// <param name="arguments">method arguments</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async ValueTask <T> InvokeInstanceMethodWrapper <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef windowObject, string methodName, params object[] arguments) where T : JsObjectWrapperBase { var jsRef = await jsRuntime.InvokeInstanceMethodGetRef(windowObject, methodName, arguments) .ConfigureAwait(false); var content = await jsRuntime.GetObjectFromRef <T>(jsRef).ConfigureAwait(false); if (content == null) { return(null); } content.SetJsRuntime(jsRuntime, jsRef); return(content); }
/// <summary> /// Get the js object property value and initialize its js object reference /// </summary> /// <param name="jsRuntime">current js runtime</param> /// <param name="propertyPath">path of the property</param> /// <param name="jsObjectRef">Ref to the js object from which we'll get the property</param> /// <param name="serializationSpec"> /// An object specifying the member we'll want from the JS object. /// "new { allChild = "*", onlyMember = true, ignore = false }" will get all the fields in allChild, /// the value of "onlyMember" and will ignore "ignore" /// "true" or null will get everything, false will get nothing /// </param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async ValueTask <T> GetInstancePropertyWrapper <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, string propertyPath, object serializationSpec = null) where T : JsObjectWrapperBase { var taskContent = GetInstanceProperty <T>(jsRuntime, jsObjectRef, propertyPath, serializationSpec); var taskRef = GetInstancePropertyRef(jsRuntime, jsObjectRef, propertyPath); var res = await taskContent; var jsRuntimeObjectRef = await taskRef; if (res == null) { return(null); } res.SetJsRuntime(jsRuntime, jsRuntimeObjectRef); return(res); }
public CancellableEvent(IJSRuntime jsRuntime, JsRuntimeObjectRef jsRuntimeObjectRef) { this.jsRuntime = jsRuntime; this.jsRuntimeObjectRef = jsRuntimeObjectRef; }
/// <summary> /// Get the js object property value /// </summary> /// <param name="jsRuntime">current js runtime</param> /// <param name="propertyPath">path of the property</param> /// <param name="jsObjectRef">Ref to the js object from which we'll get the property</param> /// <param name="serializationSpec"> /// An object specifying the member we'll want from the JS object. /// "new { allChild = "*", onlyMember = true, ignore = false }" will get all the fields in allChild, /// the value of "onlyMember" and will ignore "ignore" /// "true" or null will get everything, false will get nothing /// </param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static async ValueTask <T> GetInstanceProperty <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, string propertyPath, object serializationSpec = null) { return(await jsRuntime.InvokeAsync <T>("browserInterop.getInstancePropertySerializable", jsObjectRef, propertyPath, serializationSpec).ConfigureAwait(false)); }
public static async ValueTask <bool> HasProperty(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObject, string propertyPath) { return(await jsRuntime.InvokeAsync <bool>("browserInterop.hasProperty", jsObject, propertyPath).ConfigureAwait(false)); }
/// <summary> /// Call the method on the js instance and return the references to the items of the array result /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="windowObject">Reference to the JS instance</param> /// <param name="methodName">Method name/path </param> /// <param name="arguments">method arguments</param> /// <returns></returns> public static async ValueTask <JsRuntimeObjectRef[]> InvokeInstanceMethodGetRefs(this IJSRuntime jsRuntime, JsRuntimeObjectRef windowObject, string methodName, params object[] arguments) { if (jsRuntime is null) { throw new ArgumentNullException(nameof(jsRuntime)); } var jsRuntimeObjectRefs = await jsRuntime.InvokeAsync <JsRuntimeObjectRef[]>( "browserInterop.callInstanceMethodGetRefs", new object[] { windowObject, methodName }.Concat(arguments).ToArray()).ConfigureAwait(false); foreach (var reference in jsRuntimeObjectRefs) { reference.JsRuntime = jsRuntime; } return(jsRuntimeObjectRefs); }
/// <summary> /// Get the js object content /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="jsObject">Reference to the JS instance</param> /// <param name="serializationSpec"> /// An object specifying the member we'll want from the JS object. /// "new { allChild = "*", onlyMember = true, ignore = false }" will get all the fields in allChild, /// the value of "onlyMember" and will ignore "ignore" /// "true" or null will get everything, false will get nothing /// </param> /// <returns></returns> public static async ValueTask <T> GetInstanceContent <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObject, object serializationSpec) { return(await jsRuntime.InvokeAsync <T>("browserInterop.returnInstance", jsObject, serializationSpec).ConfigureAwait(false)); }
/// <summary> /// Call the method on the js instance /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="windowObject">Reference to the JS instance</param> /// <param name="methodName">Method name/path </param> /// <param name="arguments">method arguments</param> /// <returns></returns> public static async ValueTask InvokeInstanceMethod(this IJSRuntime jsRuntime, JsRuntimeObjectRef windowObject, string methodName, params object[] arguments) { await jsRuntime.InvokeVoidAsync("browserInterop.callInstanceAction", new object[] { windowObject, methodName }.Concat(arguments).ToArray()).ConfigureAwait(false); }
/// <summary> /// Set the js object property value /// </summary> /// <param name="jsRuntime"></param> /// <param name="jsObjectRef">The JS object you want to change</param> /// <param name="propertyPath">The object property name</param> /// <param name="value">The new value (can be a JsRuntimeObjectRef)</param> /// <returns></returns> public static async ValueTask SetInstanceProperty(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, string propertyPath, object value) { await jsRuntime.InvokeVoidAsync("browserInterop.setInstanceProperty", jsObjectRef, propertyPath, value).ConfigureAwait(false); }
public static async ValueTask <T> GetObjectFromRef <T>(this IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef) { var obj = await jsRuntime.InvokeAsync <T>("browserInterop.getObjectFromRef", jsObjectRef) .ConfigureAwait(false); return(obj); }
internal virtual void SetJsRuntime(IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef) { JsObjectRef = jsObjectRef ?? throw new ArgumentNullException(nameof(jsObjectRef)); JsRuntime = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime)); }
/// <summary> /// Call the method on the js instance and return the reference to the js object /// </summary> /// <param name="jsRuntime">Current JS Runtime</param> /// <param name="windowObject">Reference to the JS instance</param> /// <param name="methodName">Method name/path </param> /// <param name="arguments">method arguments</param> /// <returns></returns> public static async ValueTask <JsRuntimeObjectRef> InvokeInstanceMethodGetRef(this IJSRuntime jsRuntime, JsRuntimeObjectRef windowObject, string methodName, params object[] arguments) { if (jsRuntime is null) { throw new ArgumentNullException(nameof(jsRuntime)); } var jsRuntimeObjectRef = await jsRuntime.InvokeAsync <JsRuntimeObjectRef>( "browserInterop.callInstanceMethodGetRef", new object[] { windowObject, methodName }.Concat(arguments).ToArray()); jsRuntimeObjectRef.JsRuntime = jsRuntime; return(jsRuntimeObjectRef); }