Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
273 stars 55 forks source link

Enable IServer as interface #113

Closed humhei closed 5 years ago

humhei commented 5 years ago

image

Why? IMO named parameters is important when communicate between server and client

In my use case: ExcelDna can read named parameters functions from interface

humhei commented 5 years ago

Just read sourcecodes... Seems this is a breaking change which is hard to implement

Zaid-Ajaj commented 5 years ago

Hello @humhei, this is actually a duplicate of Hard to use APIs due to lack of parameter names.

Let me break down why I didn't implement this and why I think it is not a good idea

Interfaces are erased

The technical difficulty is primarily due to the fact that interfaces are erased at compile time on the client side of things because interfaces are used for interop in Fable. This makes it impossible for Remoting.Client to build a proxy without reflection metadata

Too many opinions

Having two ways of doing the same thing, i.e. defining protocols where records already work really well. I don't want people to think too much of whether they use an interface or a record.

Alternatives for named paramteres

Simply use a record for all inputs or use single case unions for names parameters:

type EvalParams = { code: string; input: string }

type IServer = 
  { eval : EvalParams -> Async<string> 
    test : unit -> Async<unit> }

Use single case unions:

type Code = Code of string
type Input = Input of string

type IServer = 
  { eval :  Code * Input -> Async<string> 
    test : unit -> Async<unit> }

// build proxy
let server = (* . . . *)

// use proxy
server.eval (Code "() => 5", Input "()")

Hope this helps

humhei commented 5 years ago

Thanks. Good workaround for me Get it 😄