In my opinion the cleanest way to do this would be to write a WebSharper macro that simply takes the getter function and infers the setter. This is something I've wanted to implement in UI.Next for quite some time actually, as it would cut down a lot on boilerplate as you said.

Here I implemented such a macro for record fields. In the future we'll probably add to UI.Next a more advanced version which would be able to recognize more getters (field of field, tuple deconstruction, etc).

By on 5/1/2016 12:22 AM ()

Thanks for the info. Your macro looks like it's a good starting point for what I want to d, but I'm bound to say it's a bit obscure to understand, and I can't find much in the standard docs to explain the detail of all the calls. Is this stuff a matter of reading the source code, or are there some more detailed docs out there. And is the macro api likely to be stable or will it all change with the next major version?

By on 5/2/2016 11:41 AM ()

No, unfortunately the macro API will be completely different in the next major version, both due to the inner workings of WebSharper being completely revamped, and the macro API being enhanced to reduce the need to use .NET reflection like I did above at line 33. The current API is not very well documented (basically the page I linked is the only documentation), we hope to do better for the next one.

By on 5/3/2016 3:04 AM ()

Well thanks for the clarification anyway even if it's not what I hoped to hear. Meanwhile, I'm having trouble getting your sample to work. If I add in a reference in my code to the lensFirst method, the F# compiles OK, but then websharper says:

1
C:\home\Gary\Documents\Visual Studio 2015\Projects\UINextClientServer1\packages\WebSharper.3.6.11.234\build\WebSharper.targets(60,5): error : Cannot load generic type

I'm assuming that the macro can't handle the passed-in type having a generic parameter. is there a workaround?

By on 5/3/2016 9:07 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper