public Clipboard(IJSRuntime jsRuntime, IJSObjectReferenceStore jsRefStore) { _jsRuntime = jsRuntime; _jsRefStore = jsRefStore; jsRefStore.TryGet(ModuleKey, out _jsInProcessObjectRef); }
/// <summary> /// Imports the file with the given <paramref name="path"/> and stores the reference with the given <paramref name="name"/> in the <paramref name="store"/>. /// When a reference with the same <paramref name="name"/> already exists, that reference will be returned. /// </summary> /// <param name="jsRuntime">The js-runtime to use for importing.</param> /// <param name="path">The path of the file to import.</param> /// <param name="name">The name used for storing/retrieving the imported reference.</param> /// <param name="store">The store in/from which the imported reference gets stored/retrieved.</param> public static async ValueTask <T> ImportOrGetModuleAsync <T>(this IJSRuntime jsRuntime, string path, string name, IJSObjectReferenceStore store) where T : IJSObjectReference { _ = path ?? throw new ArgumentNullException(nameof(path)); _ = name ?? throw new ArgumentNullException(nameof(name)); _ = store ?? throw new ArgumentNullException(nameof(store)); if (store.TryGet(name, out var reference)) { if (reference is not T castedReference) { throw new ApplicationException($"An module with the name \"{name}\" was already imported as another type \"{reference?.GetType().FullName}\"."); } return(castedReference); } // Import module from javascript var jsObjectRef = await jsRuntime.InvokeAsync <T>("import", path); if (jsObjectRef == null) { throw new ApplicationException($"Module with name \"{name}\" couldn't be imported."); } // Add module to store store.Add(name, jsObjectRef); return(jsObjectRef); }
public ElementService(IJSRuntime jsRuntime, IJSObjectReferenceStore jsRefStore) { _jsRuntime = jsRuntime; _jsRefStore = jsRefStore; jsRefStore.TryGet(ModuleKey, out _jsInProcessObjectRef); }
public WindowService(IJSRuntime jsRuntime, IJSObjectReferenceStore jsRefStore) { _jsRuntime = jsRuntime; _jsRefStore = jsRefStore; _eventManager = new WindowEventManager(jsRuntime, jsRefStore); jsRefStore.TryGet(ModuleKey, out _jsInProcessObjectRef); }
public WindowEventManager(IJSRuntime jsRuntime, IJSObjectReferenceStore jsRefStore) { _jsRuntime = jsRuntime; _jsRefStore = jsRefStore; _eventHandlerMapping = new(); jsRefStore.TryGet(WindowService.ModuleKey, out _jsInProcessObjectRef); }