granicz on main
Fixed #15 (compare)
granicz on main
Fixed #15 (compare)
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:
LensAuto
inside getPerPageSelect
to derive the two others? Is it ok to LensAuto
multiple times on the same field?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?
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
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.
@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")>]
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?
JS.Inline
with a onafterrender
hole here.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 ;-)[<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).MarkupEvaluator
defined with same file as EntityDetail
, it complains with Type not found in JavaScript compilation: Entity+MarkupEvaluator'1'
.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).
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?
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
dotnet ws build
?
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".
....
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.
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 :-(
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
dotnet new -i "WebSharper.Templates::*"
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.
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?