[Feature Request] Add possibility to return value in CallBackInteropWrapper
Closed this issue · 9 comments
Hi,,
It would be nice to have possibility to return value from CallBackInteropWrapper
like ValueTask<TResult>
You can already do it with the generic CallBackInteropWrapper if I understand you correctly. Like here https://github.com/RemiBou/BrowserInterop/blob/master/src/BrowserInterop/WindowInterop.cs#L656
You can already do it with the generic CallBackInteropWrapper if I understand you correctly. Like here https://github.com/RemiBou/BrowserInterop/blob/master/src/BrowserInterop/WindowInterop.cs#L656
@RemiBou But how to return the value to Js code from CallBackInteropWrapper
?
I have not found proper solution and I have created two callbacks in BlazorGooglePay
that one is used to send data to C# code and second is used to get data from Js storage after ...
You use the value as a parameter of your callback.
CallBackInteropWrapper.Create<MyObject>(
(MyObject o) => {
Console.WriteLine(o.ToString());
return taslk.CompletedTask
},
getJsObjectRef: false,
serializationSpec:"*")
You will use your object where I did the Console.WriteLine.
The value returned by CallBackInteropWrapper is only the disposable for unsubscribing.
You use the value as a parameter of your callback.
CallBackInteropWrapper.Create<MyObject>( (MyObject o) => { Console.WriteLine(o.ToString()); return taslk.CompletedTask }, getJsObjectRef: false, serializationSpec:"*")You will use your object where I did the Console.WriteLine.
The value returned by CallBackInteropWrapper is only the disposable for unsubscribing.
@RemiBou Yes, I understand, but I want something like this:
CallBackInteropWrapper.Create<MyObject>(
(MyObject o) => {
Console.WriteLine(o.ToString());
return "Token value";
},
getJsObjectRef: false,
serializationSpec:"*")
Where Js code will get some value back like "Token value"
ok I see ! Good idea, it's indeed a new feature. For now the workaround is to use interop for calling an other method with "Token value".
ok I see ! Good idea, it's indeed a new feature. For now the workaround is to use interop for calling an other method with "Token value".
@RemiBou Yeah, I actually did like this in BlazorGooglePay )
But it is little bit ugly )))
@RemiBou Seems like this feature is relatively easy to implement
https://github.com/RemiBou/BrowserInterop/blob/master/src/BrowserInterop/wwwroot/scripts.js#L52
I guess there should be return
keyword before netObjectRef.invokeMethodAsync('Invoke', ...args);
Indeed, I'll try to include it next release (with your PR and some other little changes) maybe tonight (CET) if I can
Feature is implemented within above pull-requests