dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

Ability to pass multiple arguments to a function $disptach call #314

Closed parksj10 closed 1 year ago

parksj10 commented 1 year ago

Is there any way to pass multiple arguments to a $dispatch call in js, writing something like the following js code

vm.$dispatch({ CreateNewRunFromTemplate: { runName: runName, templateId: templateId } });

To call the following function in .NET:

public void CreateNewRunFromTemplate(string runName, string templateId)
        { ...
dsuryd commented 1 year ago

Sure, the js part can pass multiple arguments to the .NET function if the argument is of type that can be deserialized to:

public class Template 
{ 
   public string runName { get; set; } 
   public string templateId { get; set; }
}

public void CreateNewRunFromTemplate(Template arg) { ... }
parksj10 commented 1 year ago

Ok, that's how I ended up doing it, I just didn't really want to create a class just for arguments. But if that's the only way to do it, so it shall be!

parksj10 commented 1 year ago

Quick question, I just learned .NET6 supports inline tuple declaration, however when I implement

public void CreateNewRunFromTemplate((string RunName, string TemplateId) newInputRun)
{
...

I get the following error:

fail: DotNetify[0]
      Failed to deserialize view model property 'CreateNewRunFromTemplate': TypeConverter cannot convert from System.String.

any idea why?

dsuryd commented 1 year ago

Safe to say the view model deserialization logic does not yet support tuples. I may look into enhancing the logic if I can find the time, in case you want to take a stab at it, here is the place where it happens: https://github.com/dsuryd/dotNetify/blob/67f2dcca62fc6253845a1487833a50aa92c0a85e/DotNetifyLib.Core/BaseVM/VMSerializer.cs#L88