-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add support for JSObjectReference/IJSObjectReference #233
Comments
Hey Egil, A problem that I'm facing (that is not directly related) is that I can't reference |
Hey Kristoffer My initial design thoughts on this are as follows (assuming users have called
What do you think? Btw. in addition to this, I plan to change how bUnit's JSInterop/mock JSRuntime is surfaced to the user. I want to add a property |
Hey again, Nice to see that you've already had a lot of ideas. 👍
In total it seems like a good plan. If there were to be added an on-by-default result for an invoked import then that might be the easiest to add by simply checking in the Sounds interesting to add |
Thanks for the input Kristoffer. Regarding 1: As part of the "always on" issue #237, planned invocations for Regarding 4: Agreed, some base type/interface is probably needed. But are we sure that Regarding 5: I see two layers, the "root" jsruntime mock that can return zero or more child
With the always on, we will just register planned handlers for that case. I do not think an special override is needed.
Probably some tweaks to the public API, but lets keep those discussions in that issue. |
Hey again, |
@KristofferStrube if you want to take a crack at this issue, feel free to go ahead. Do check out the contributor guidelines first thought. |
I will try putting something together. I haven't done any pull requests before, so might need some help through the process, but I'm up for the challenge. |
That's fair. This is a pretty complex one. If you want to get your feet wet first then there are also other issues with the good first issue label that you can look at. |
Hey @KristofferStrube, you can check out the PR #247 to see what I am planned to change in bUnit s JSInterop. |
Hi @KristofferStrube, im going to start looking at this now. Let me know if you want to contribute. |
Hey @egil, sounds great. I don't think I have the time currently to contribute a lot, but I would love to ping-pong if you have any decisions that you need sparring for or other minor tasks. |
Here is my design/progress so far:
|
Looks good @egil,
Extra thing: |
Yes. There is a default "loose mode"
Are you even allowed to call |
Yep. I have an example here where I do it: here |
Hmm, so does... var module1 = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./js/script1.js");
var module2 = await module1.InvokeAsync<IJSObjectReference>("importScript", "./script2.js");
await module2.InvokeVoidAsync("hello2", "Importing indirectly works");
|
export function importScript(Url) {
return import(Url);
} and export function hello2(message) {
console.log(message);
}
|
This might just be a very specific use case so might not be necessary to handle for now? |
Yes and no. Its probably easier to design for this now than later.
My impression is that calls that follow the pattern If this is the case, then I need to, in general, return a If a user creates their own import function, where the second argument is not script name as it is on your case, but the import is hardcoded, e.g. |
Even though we handle I think another way to name the module would be to add together all arguments concatenated since all arguments identify which module is imported (this of course depends on the implementation). |
I like the The need for casting could obviously be worked around by adding extension methods to The alternative, which I am leaning towards, is to continue to disallow setting up SetupModule(moduleName: "./js/script1.js");
SetupModule(identifier: "importScript", moduleName: "./script2.js"); That would mean we have the following overloads: 1. SetupModule(string moduleName);
2. SetupModule(string identifier, string moduleName);
3. SetupModule(string identifier, params object[] arguments);
4. SetupModule(InvocationMatcher invocationMatcher);
5. SetupModule(string identifier, InvocationMatcher invocationMatcher);
6. SetupModule(); // catch all These basically mirror the
Since we cannot consistently get the name module, I wonder if it is just better to not prefix the invocation identifiers with the module name. Users can always inspect the |
I like this approach. Covers all use cases and is very flexible while still using the I agree that it should be fine to not prefix the invocation identifiers. |
Something I worked with today while writing an article is |
How is it possible to cast/get a |
Nevermind, figured it out. It seems it is only partially supported in Blazor, depending on how you setup your app. Anyway, its pretty easy to add support for it in bUnit, so Ill just do it now. |
Cool. |
I found an issue related to it, it is something that might make it into the next version. It is covered in the draft for Steves performance guidelines, so I think it is safe to assume it will be supported. Either way, it is not a problem for us to have it in now. |
The new way of loading JavaScript modules into a Blazor app and then receiving a
JSObjectReference
after the call should be eksplicit supported by the mock js runtime in bUnit, such that the resultingJSObjectReference
just works.More info here: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-5-release-candidate-1/#blazor-javascript-isolation-and-object-references
Related: dotnet/aspnetcore#26981
The text was updated successfully, but these errors were encountered: