简体   繁体   English

在 blazor 中使用 EventCallback 时,我应该将什么传递给 InvokeAsync?

[英]What should I pass to InvokeAsync when using EventCallback in blazor?

When using InvokeAsync in a EventCallback (without any type ie doesn't return anything) it still need an argument to invoke ir.InvokeAsync中使用EventCallback时(没有任何类型,即不返回任何内容),它仍然需要一个参数来调用 ir。

在此处输入图像描述

What should I pass there?我应该通过那里? Looks like I can pass anything that won't have any difference, but I'm not sure of that.看起来我可以通过任何没有任何区别的东西,但我不确定。

It also have a nice explanation for that argument它对该论点也有很好的解释

arg: The argument. arg:参数。

If you have a model you can pass it, or any property you use as a model.如果您有 model,您可以传递它,或者您用作 model 的任何属性。 If not, you might try passing this .如果没有,您可以尝试通过this It won't do anything execution wise, but it will calm the compiler down and your code will run.它不会执行任何明智的操作,但它会使编译器平静下来,您的代码将运行。 The MS docs state that you should "Prefer strongly typed Event Callbacks", however sometimes that just doesn't make sense and you end up here. MS docs state 说你应该“首选强类型事件回调”,但有时这没有意义,你最终会在这里。

One thought I had on the matter in keeping with the idea of reducing side effects, is that maybe we should use the strongly typed EventCallBack<bool> to kick out a bool that can be captured in the supplied method and used to verify something or other was complete, true, etc. The weakly typed version is in essence a "void" return on a method that is a code smell for side effects.与减少副作用的想法一致,我对此事的一个想法是,也许我们应该使用强类型EventCallBack<bool>来踢出一个可以在提供的方法中捕获并用于验证某事或其他的 bool是完整的,真实的等等。弱类型版本本质上是对方法的“无效”返回,这是副作用的代码气味。 I still don't know exactly where I land on the matter, and these are just my thoughts, take them with a grain of salt.我仍然不知道我在这件事上的确切位置,这些只是我的想法,持保留态度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM