Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
rbauduin
@rbauduin_gitlab

I have a Var holding a record, and I LensAuto on each of its fields:

        let paginationState = Var.Create {currentPage=1; perPage=10}
        let currentPage = paginationState.LensAuto (fun p -> p.currentPage)
        let perPage = paginationState.LensAuto (fun p -> p.perPage)

These Vars are used in their creation scope, and passed to functions as arguments.
Now I have a function getPerPageSelect which uses all three. What is best:

  • Should I pass all three as argument, knowing the last two are derived from the first?
  • Should I pass only one Var as argument and also call LensAutoinside getPerPageSelect to derive the two others? Is it ok to LensAuto multiple times on the same field?
rbauduin
@rbauduin_gitlab

I could remove the additional parameters, but it makes the code less approachable, see the myowndb/myowndb@78d1030.
For example, this

let paginationLinks = View.Const computePaginationLinks <*> currentPage.View <*> numberOfPages

is replaced by

        let paginationLinks = View.Const computePaginationLinks <*> paginationState.View.Map(fun r -> r.currentPage) <*> numberOfPages

and this

if currentPage.Get()<>1 then currentPage.Set 1

by

if paginationState.Get().currentPage<>1 then paginationState.Set {paginationState.Value with currentPage=1}

How would you handle that? Is using LensAuto at the start of the function the way to go? That avoids the duplicate arguments to the functions, keeps the code simple. But are there any potential problems to call LensAuto multiple times on the same value?

rbauduin
@rbauduin_gitlab
After further refactoring I got rid of the multiple lens on one field. Is multiple lens on one field a code smell?
rbauduin
@rbauduin_gitlab

I'd like to try gettext.js. Their usage example is:

<script src="/path/to/dist/gettext.iife.js" type="text/javascript"></script>
<script>
  var i18n = window.i18n(options);
  i18n.gettext('foo');
</script>

I thought I'd try with a stub, but I don't know how to get started, eg reference window.i18n in my stub... I'm looking at the Bindings doc for this. /cc @granicz @Jand42

8 replies
rbauduin
@rbauduin_gitlab

It seems that the javascript code passed to JS.Inline cannot use the spread syntax.
I wanted to use it in the use of gettext.js, which allows passing additional arguments to the string like a PrintfFormat:

     member _.ntranslate (s:string,plural:string,n:int64,[<ParamArray>]o:obj array)=
        JS.Inline ("""

        var i18n=window.i18n({})
        i18n.setMessages('messages', 'fr', {
            "Welcome": "Bienvenue",
            "There is %1 row %2 and %3": [
                "Il y a %1 rangée %2 ou %3",
                "Il y a %1 rangées %2 et %3"
            ]
            }, 'nplurals=2; plural=n>1;');

        return i18n.ngettext($0,$1,$2,...$3)
        """, s, plural, n, o)

which would be called like this:

JStr().ntranslate("There is %1 row","There are %1 rows and %2 and %3",c, "verte", "rouge")

Is there a reason to not support it or is it simply an omission?
The error reported is

WebSharper error WS9001: Macro error in WebSharper.Core.Macros+InlineJS.TranslateCall: Exception of type 'WebSharper.Core.JavaScript.Parser+ParserError' was thrown.
András Jankó
@Jand42

@rbauduin_gitlab This is an omission, JS parser/writer is not really up to date with syntax. WebSharper is fully supporting EcmaScript 5, but only some specific additions have been added since: import, BigInteger, ?? and ** operators.
So currently, if you want to use other JS syntax, you can only with outside scripts, like having a mylib.js as EmbeddedResource item add assembly-level attribute

[<assembly: WebResource("mylib.js", "text/javascript")>]

, then write inlines making use of it with

[<Require(typeof<Resources.BaseResource>, "mylib.js")>]
1 reply
Adam Granicz
@granicz
I may have been misleading here, when i said "inline the interaction", i meant inlining each initialization/function step separately
going beyond expressions and functions in inlines will hit the syntax validation limitations
@Jand42 when you say "not up to date" with syntax, do you have a list of what's not supported (on expression/function level)?
and can you ticket those please
rbauduin
@rbauduin_gitlab

I think eventually the function will look like this:

     member _.ntranslate (s:string,plural:string,n:int64,[<ParamArray>]o:obj array)=
        JS.Inline ("""
          var i18n=window.i18n({})
          return spread_ngettext(i18n,$0,$1,$2,$3)
        """, s, plural, n, o)

This should be ok, no?

Adam Granicz
@granicz
is a new window.i18ninstance needed for every call (i mean from the perspective of the library)?
rbauduin
@rbauduin_gitlab
no, it's not needed (I think), but I didn't know how to do otherwise
and I still don't know :-D
Adam Granicz
@granicz
i would put the i18n object/context creation in the initialization (code that executes on page load)
13 replies
then inline the single function call to get translations
gmlion
@gmlion
how can I catch http errors when using Remoting? Should I implement a new IRemotingProvider?
3 replies
rbauduin
@rbauduin_gitlab

With this code filling a ws-onafterrender hole:

                            .InitI18n(<@fun (t:Dom.Element) -> JS.Inline("""
                                myowndb_i18n=window.i18n({});
                                console.log("init")
                                console.log(myowndb_i18n)
                                myowndb_i18n.setMessages('messages', 'fr', {
                                    "Welcome": "Bienvenue",
                                    "There is %1 row %2 and %3": [
                                        "Il y a %1 rangée %2 ou %3",
                                        "Il y a %1 rangées %2 et %3"
                                    ]
                                    }, 'nplurals=2; plural=n>1;');
                                """) @>)

I get an error in the browser console: Uncaught TypeError: _4 is undefined.
When looking at the code causing this, I have:

..... a.myowndb_i18n=a.i18n({});I.log("init");I.log(a.myowndb_i18n);_4.setMessages("messages"......

So with the translation the setMessages is called on another variable that the one holding the result of window.i18n({});.
Any idea what's happening?

3 replies
rbauduin
@rbauduin_gitlab
I finally got the client side translation working. As suggested by @granicz , but maybe wrongly interpreted by me :-), I do a JS.Inline with a onafterrender hole here.
The only small problem I see is that as JS.Inline is working at compile time, I need to pass it a static string, and I can't parameterise it with the locale to load. So the locale loading is done all in javascript, meaning there's one additional XMLHttpRequest done. Not a big deal, but if there's a way to avoid that request I'm interested to hear about it ;-)
@gmlion : you had asked about client side translation, so you might be interested to take a look at the commits of 9 december here
4 replies
rbauduin
@rbauduin_gitlab
In my code, I have a [<RPC>] marked function returning Async<Result<list<Entity.EntityDetail>,string>>.
Entity.EntityDetail is defined in the library used by the web frontend. So it is not marked with [<JavaScript>] but it is usable in client side code (here and here).
However, when I try to instanciate the type MarkupEvaluatordefined with same file as EntityDetail, it complains with Type not found in JavaScript compilation: Entity+MarkupEvaluator'1'.
Is there a trick to bing the MarkupEvaluator in the javascript like it was done implicitly for EntityDetail? I want MarkupEvaluator to be front-end neutral, so I can't mark it with [<JavaScript>] explicitly (and it's not in a WebShaper dependent project anyway).
13 replies
rbauduin
@rbauduin_gitlab
^ /cc @granicz @Jand42 @Jooseppi12
rbauduin
@rbauduin_gitlab

I had this code:

        let dt_countView = View.MapAsync2
                                (fun paginationState search -> async {
                                    return! Server.InstancesDataTable id paginationState search
                                })
                                paginationState.View
                                searchCriteria.View

to which I needed to add an argument, the sortCriteria. I hoped to be able to write something like

        let(<*>) = View.Apply
        // View<Async<Result<string * int64,string>>>
        let dt_countView= View.Const (fun paginationState search sort-> async {
                                    return! Server.InstancesDataTable id paginationState search sort
                          })
                          <*>   paginationState.View
                          <*>   searchCriteria.View
                          <*>   sortCriteria.View

but I end up with an View<Async<...>>.
I solved it by writing

        let dt_countViewWithoutSort = View.MapAsync2 (fun paginationState search -> async {
                                                return Server.InstancesDataTable id paginationState search
                                            })
                                        paginationState.View
                                        searchCriteria.View
        let dt_countView = View.MapAsync2 (fun  f sort-> f sort)
                            dt_countViewWithoutSort
                            sortCriteria.View

but wouldn't it make sense to add something like ApplyAsync? Or is there a better way available now?

rbauduin
@rbauduin_gitlab

Not sure what this means:

dotnet ws build
Couldn't build project because: Value cannot be null. (Parameter 'value')

Fallback to "dotnet build".

Any pointer? What Value is it talking about? Something in my code? Can I get more information somehow?

András Jankó
@Jand42
@rbauduin_gitlab What project are you trying to build. The only thing dotnet ws build relies on iirc is that project has been restored, make sure to run dotnet restore first
but it is set up if there is any unexcected failure, it should revert to running standard dotnet build as the goal of dotnet ws build is to have fast single-project rebuild of js outputs only when server side dll update is not necessary
rbauduin
@rbauduin_gitlab
@Jand42 I have tested it on a very simple project and I have the same problem. Could it be due to running on Linux? Here's the simple project having no dependency, so you can easily test it at your side: https://gitlab.com/rbauduin/wsclientside
rbauduin
@rbauduin_gitlab
When I following this link I get an error: https://forums.websharper.com/topic/91233
Going to the post from the index seems to work though
3 replies
Adam Granicz
@granicz
image.png
@rbauduin_gitlab are you still encountering issues with dotnet ws build?
note the time to compile from zero
then (with source file updated) the second run goes down to <1sec:
image.png
rbauduin
@rbauduin_gitlab
I still have issues @granicz . Possibly linked to the fact I'm running it on Linux?
It always falls back to dotnet build because "Value cannot be null". Here is the output I get:
rb@siopi:/tmp/wsclientside$ dotnet ws start --rid linux-x64
version: 5.0.0.120; path: /home/rb/.nuget/packages/websharper.fsharp/5.0.0.120/tools/net5.0/linux-x64/wsfscservice_start.sh Started.
rb@siopi:/tmp/wsclientside$ dotnet ws build
Couldn't build project because: Value cannot be null. (Parameter 'value')

Fallback to "dotnet build".
....
rbauduin
@rbauduin_gitlab
I took a quick look, and the error could come from https://github.com/dotnet-websharper/dotnet-ws/blob/main/Program.fs#L342
However, when I moved the code extracting the version in another Program.fs, it worked fine. So the regexp is doing its job.
9 replies
rbauduin
@rbauduin_gitlab
Hi @Jooseppi12 , a couple of months ago you told me you had ideas about a client side routing problem I had. I think it can be described as how to handle the situation with two separate page elements that are handled by client side routing. I had prepared a small example project to illustrate the problem. In the template, I have both title and body that need to be handled (here). In the current code I install the client side router and do the router view's map twice ( here and here). If you have the time I'm interested in your suggestions. If it can help, the project can be opened in gitpod.
12 replies
rbauduin
@rbauduin_gitlab

When transposing the change in my app, I get an error I can't explain. Here is my change myowndb/myowndb@8194635, and the error is

[2022:02:09 13:08:00 +1 FTL]  Host terminated
System.TypeInitializationException: The type initializer for 'web.Site' threw an exception.
 ---> System.TypeInitializationException: The type initializer for '<StartupCode$webws>.$Site' threw an exception.
 ---> System.TypeInitializationException: The type initializer for '<StartupCode$webws>.$Routing' threw an exception.
 ---> WebSharper.JavaScript.ClientSideOnly: This function is intended for client-side use only.
   at WebSharper.UI.Router.Install[T](T onParseError, Router`1 router)
   at <StartupCode$webws>.$Routing..cctor() in /home/rb/gits/myowndb/app/webui/Routing.fs:line 26
   --- End of inner exception stack trace ---
   at web.Routing.get_router()
   at <StartupCode$webws>.$Site..cctor() in /home/rb/gits/myowndb/app/webui/Site.fs:line 329
error when instanciating client router once
   --- End of inner exception stack trace ---
   at web.Site..cctor()
   --- End of inner exception stack trace ---
   at web.Site.get_Main()
   at web.Startup.ConfigureServices(IServiceCollection services) in /home/rb/gits/myowndb/app/webui/Startup.fs:line 137
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at web.Program.BuildWebHost(String[] args) in /home/rb/gits/myowndb/app/webui/Startup.fs:line 209
   at web.Program.main(String[] args) in /home/rb/gits/myowndb/app/webui/Startup.fs:line 231

The code calls Sitelet.New and the example code from this morning used Application.Multipage. But if I change the code to use Application.MultiPage, the app starts but the error appears when accessing a page. Any idea what this might be?
If you're curious, you can open a gitpod vscode environment here. To run the app, just do cd webui && make run. The app doesn't start as that error is raised :-(

2 replies
Catalin Bocirnea
@cata
Hey guys, getting warnings in Chrome/Edge about adding non-passive touchstart event listeners - any plans on allowing flags on on.touchStart and other event handlers? Is there currently a way to set event listener flags ? see https://dom.spec.whatwg.org/#interface-eventtarget and https://chromestatus.com/feature/5745543795965952
2 replies
Catalin Bocirnea
@cata
Hi guys, heads-up:
I've noticed that Websharper booster might not play well with type providers. As an example, we use https://github.com/zanaptak/TypedCssClasses for safely referencing CSS classes in out SPA, and noticed that when referencing a new CSS class, while the call is picled up by VS Intellisense and we see no erros in VS, building the SPA fails. Killing the WS booster process and then building the project again makes the build succeed.
8 replies
Patrik Fábián
@OrkenWhite
Hi, I've been trying out WS recently under Fedora 35, but I can't build anything with it. The error message is:
/tools/net5.0/fedora.35-x64//wsfsc.sh': No such file or directory
It seems to me that Fedora has its own RID instead of linux-x64.
2 replies
András Jankó
@Jand42
@OrkenWhite @granicz @cata I have been testing WS6 templates to build on build matrix of win+ubuntu+macos on GH, now have all passing: https://github.com/dotnet-websharper/build-script/actions/runs/1976269889
András Jankó
@Jand42
(you need to use https://nuget.pkg.github.com/dotnet-websharper/index.json feed with a PAT for WS6 builds yet, but hopefully going out to nuget.org soon)
The compilers have platform specific builds for 3 RIDs: win-64, linux-x64, linux-musl-x64 now. I have made so that if a platform is unrecognized, F# compiler runs in standalone mode (no compiler service) as it was hanging up on MacOS. So further optimizations for more platforms is possible from here, but at the baseline, compiler should work.
8 replies
rbauduin
@rbauduin_gitlab
For those like me that forget how, I wrote down how to generate access tokens to install unreleased websharper versions here
Patrik Fábián
@OrkenWhite
WS6 templates build for me now, but don't run:
Unhandled exception. System.Exception: IWebSharperService not found. Use AddSitelet in your ConfigureServices.
András Jankó
@Jand42
@OrkenWhite Thanks for the notice, fixing
András Jankó
@Jand42
@OrkenWhite Minor fix for SPA templates uncovered a larger issue of dead-code elimination being broken by some WS6 improvements (better support for interfaces, including correct handling of ICollection/IList/IDictionary and their ReadOnly variants)
Latest template build 6.0.0.175 now works (we will need to add automatic testing for this too...)
Patrik Fábián
@OrkenWhite
@Jand42 Thanks, it worked for a few versions, but with 6.0.0.181, I can't build projects (under Fedora 35):
error MSB3073: The command "chmod u+x '/usr/lib64/dotnet/wsfsc.sh'" exited with code 1.
Why does it look for that script in /usr?
6 replies
Ash Bhaskar
@ashokkbhaskar
Is the Bitbucket page for the Websharper website (https://bitbucket.org/IntelliFactory/websharper.website/issues) still being used? The last updates are from two years ago.
On the Downloads page of the main site, the template update command is displayed as dotnet new -i &quot;WebSharper.Templates::*&quot; instead of dotnet new -i "WebSharper.Templates::*". I can post this issue somewhere to make tracking easier, but I'm not sure which page is most active.
rbauduin
@rbauduin_gitlab

I'm looking at using WS6 in my app, and I get the error

 The type 'WebSharperBuilder' does not define the field, constructor or member 'SiteletAssembly'.

The code is here.
Is this normal, and is a change required in my code?

Adam Granicz
@granicz
(Hi folks - to better focus on growing the WebSharper community and giving the project more visibility with newcomers to F#, going forward please use the F# Slack #web channel for WebSharper-related questions and discussions, thank you!)