Skip to content
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

Update code for Blazor's new IJSInterop abstraction #1

Closed
DNF-SaS opened this issue Jun 28, 2018 · 8 comments
Closed

Update code for Blazor's new IJSInterop abstraction #1

DNF-SaS opened this issue Jun 28, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@DNF-SaS
Copy link

DNF-SaS commented Jun 28, 2018

Blazor.registerFunction() is no longer needed, because the new IJSRuntime.InvokeAsync() invokes the (specified) method on the current window-object.

@Tewr Tewr added the enhancement New feature or request label Jun 28, 2018
@Tewr
Copy link
Owner

Tewr commented Jun 29, 2018

The only async method I have is unmarshalled. Looks like RegisteredFunction will be phased out anyway in 0.5.0 (it's no longer in the repo?), so the interop has to be changed for sure. Can't really see at the current state of affairs how Unmarshalled calls should be done. Looks like MonoWebAssemblyJSRuntime exposes the method, but ill have to migrate first to see if this is viable, might be something I'm missing when just reading source. Perhaps I'll suggest IJSRuntime.InvokeUnmarshalledAsync(), to the Blazor team, unless its already in the pipeline, or if there is another way to do it.

@DNF-SaS
Copy link
Author

DNF-SaS commented Jul 2, 2018

I've extended the FileReaderJsInterop by two functions for mocking the old functionality of JSInterop.
It's oviously working on MonoRuntime only, but I would suggest that this is okay for the moment.

private static T InvokeOnMono<T>(string identifier, params object[] args)
{
    if ( JSRuntime.Current is MonoWebAssemblyJSRuntime mono )
    {
	    return mono.Invoke<T>(identifier, args);
    }

    throw new NotImplementedException($"TODO: Support {identifier} on other runtimes.");
}

private static TRes InvokeUnmarshalledOnMono<T0, T1, TRes>(string identifier, T0 arg0, T1 arg1)
{
    if ( JSRuntime.Current is MonoWebAssemblyJSRuntime mono )
    {
	    return mono.InvokeUnmarshalled<T0, T1, TRes>(identifier, arg0, arg1);
    }

    throw new NotImplementedException($"TODO: Support {identifier} on other runtimes.");
}

Additionally, the TypeScript-Code should be adapted so that the code from Blazor.registerFunction() is moved to some function residing below window.(namespace).

@Tewr
Copy link
Owner

Tewr commented Jul 2, 2018

Yes, I did something like this yesterday, think its the way to go for this. I'll have to pass all sync methods to async as well, to avoid using the special methods, and implement the js/ts as a class instance.
As you are showing a bit of interest, I pushed a half-built branch which depends on 0.5.0

@DNF-SaS
Copy link
Author

DNF-SaS commented Jul 2, 2018

Pulled the 0.5-Branch; it's pretty work in progress, so I'll wait in order to prevent merge conflicts.

@Tewr
Copy link
Owner

Tewr commented Jul 2, 2018

I've got it fully working now. Had to change most of the API but in any case I like it better now. There is some weird behaviour when calling back to .NET from js, I was unable to figure out what it was. I didn't manage to call back without more than one parameter (first one was lost, not the second one?). Might be a bug in blazor, might have been me doing something goofy. In any case, current solution is not that bad anyway, might even be better.

@Tewr Tewr closed this as completed Jul 2, 2018
@DNF-SaS
Copy link
Author

DNF-SaS commented Jul 3, 2018

Great!
You copied your changes from 0.5.0-p1 back to the master-branch? (no merge?)

@Tewr
Copy link
Owner

Tewr commented Jul 3, 2018

:) Well, the intention was a merge, but didnt really end up that way, had some conflict gore when branching out in the middle to save 0.4.0. That'll teach me not to merge late at night

@DNF-SaS
Copy link
Author

DNF-SaS commented Jul 3, 2018

I suppose, every dev has some bad memories about git and merging... ;-)

Tewr pushed a commit that referenced this issue Jun 5, 2023
* File folder path drag drop (#1)

* .

* Add TypeScript MSBuild

* Add Check in GetFiles for missing files. Get from dragdrop instead.

* Update Demos

* Use native input functionality for drag / drop. Add option to switch between using webkitdirectory. Use div / ondrop to drop multiple folders and files.

* Move property to non standard properties

* Update Demo

* Fix/Cleanup

* Fix async issue

* remove try catches not needed and rethrow others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants