by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Pieter Bryon
    @pbryon
    thanks for trying!
    Cody Johnson
    @Shmew
    np
    gl
    Pieter Bryon
    @pbryon
    thanks
    njlr
    @njlr
    Can Thoth.Json decode an plain-old-javascript object to give something like a runtime schema checker?
    Florian Verdonck
    @nojaf
    Yes, I believe you have Decode.fromObject
    Or it is called .from value
    Maxime Mangel
    @MangelMaxime

    @njlr Yes it can and it's actually how Thoth.Json is working :)

    Soure code

        let fromValue (path : string) (decoder : Decoder<'T>) =
            fun value ->
                match decoder path value with
                | Ok success ->
                    Ok success
                | Error error ->
                    Error (errorToString error)
    
        let fromString (decoder : Decoder<'T>) =
            fun value ->
                try
                   let json = JS.JSON.parse value
                   fromValue "$" decoder json
                with
                    | ex when Helpers.isSyntaxError ex ->
                        Error("Given an invalid JSON: " + ex.Message)

    See how fromString use fromValue by passing the result of JS.JSON.parse which gives you an "obj".

    This is also how Nacara use Thoth.Json to explore the global configuration and the configuration of a page etc. Mentioning that to say that's supported
    Ben Collins
    @aggieben
    Trying to work through the elmish book and found that the elmish-getting-started project fails somewhere in Fable build:
    image.png
    totally newbie question: how do we troubleshoot?
    Ben Collins
    @aggieben
    looks like maybe the Fable.Elmish.3.0.0 project in .fable is expecting a Paket.Restore.targets file that doesn't exist?
    njlr
    @njlr
    @MangelMaxime Perfect! Turns out I can remove a redundant JSON.parse(JSON.stringify(x) from my app!
    Ben Collins
    @aggieben
    Opened this issue over at Zaid's repo: Zaid-Ajaj/elmish-getting-started#2
    Peter Keše
    @pkese
    I'm banging my head on trying to understand async code
    All I want is to cache an async result (wrap it in lazy) and then use it in several places (but accessing the server just once)
    But I'm finding out that that the async code is being executed multiple times:
    let asyncData = lazy (async { return fetchSomeUrl () })
    let getOrFetch = asyncData.Force
    ...then when I intialize my state, I add initial command
    state, Cmd.OfAsync.either getOrFetch () ConsumeServerData ConsumeServerError
    Cody Johnson
    @Shmew
    @pkese I'd recommend just putting the result in local storage, and then when making calls it can check if it already exists and if so, not make the call
    Peter Keše
    @pkese
    @Shmew thanks for suggestion.
    There seems to be a mismatch between my conceptual map of the world (i.e. how I think async works) and how async really works. I can of course do a workaround, but that's just a way to avoid understanding what's going on.
    And then I'll get bitten again next time I try to use async.
    njlr
    @njlr
    I think you are caching the construction of the async, not the execution of the async?
    Peter Keše
    @pkese
    How should I change the code to cache the execution?
    njlr
    @njlr
    I would hide a mutable somewhere
    open Fable.Core
    
    let computation = async {
      printfn "Computing... "
      return 42
    }
    
    let cache workflow = 
      let mutable cachedValue = None
      async {
        match cachedValue with
        | Some x -> return x
        | None -> 
          let! x = workflow
          cachedValue <- Some x
          return x
      }
    
    Async.StartAsPromise (async {
      let cachedComputation = cache computation
    
      for i in 0..10 do
        let! x = cachedComputation
        printfn "%i" x
    
      printfn "Done. "
    })
    |> ignore
    sorry for formatting..
    Peter Keše
    @pkese
    Yes, I guess I'll do that in the end
    Cody Johnson
    @Shmew
    I have a file in my web app project that isn't used in the actual application, but webpack includes it in the bundle and apparently breaks the app because of it. Is there a way to make sure fable doesn't include a file in my webpack.config.js?
    The file is completely self-contained, doesn't reference any of the files or vice versa
    Damian Reeves
    @DamianReeves
    Hey… is there any good example of building a node commandline application with fable (outside of the node samples in fable2-samples.
    Cody Johnson
    @Shmew
    Hey @MangelMaxime in my webpack.config.js I'm setting this option: define: isProduction ? ['WEBPACK'] : ['DEBUG','WEBPACK'] but I'm having trouble with doing <Compile Include="SomeFile.fs" Condition="$(WEBPACK) == True" /> I've tried a few different variations, but the best I've been able to do is essentially have it be != True which works kinda, but it's annoying never having my file in my project. Do you know what I'm doing wrong?
    Ilja Nosik
    @inosik
    @DamianReeves ts2fable is a Node application. Are you looking for something in particular?
    Ilja Nosik
    @inosik
    @Shmew Are you sure that the file isn't actually used? The tree-shaking should take care of that, I think. Or maybe your configuration is incomplete?
    Anyways, the values you configure in the define option are compiler constants, not MSBuild properties. You can set the WEBPACK environment variable to True, which MSBuild will then use as a property and hopefully evaluate your condition correctly.
    I wouldn't recommend this, though. If this file is really unused by the actual project, then why keep it there?
    Damian Reeves
    @DamianReeves
    @inosik Thanks
    I’m working on a library which I want to build to target dotnetcore and Fable. Everything is cool except for the fact I need JSON encoding/decoding and Thoth.Json separates its Fable vs Framework code into distinct NuGet packages. How are folks managing these situations since the Fable docs say your Fable library should have a simple .fsproj file with no conditionals?
    It seems the only thing I can do is split into 2 libraries as well.
    Damian Reeves
    @DamianReeves
    This sort of splitting is why TargetFrameworks was introduced, has anyone done any research to see if its possible to have Fable added as a legit target framework so we could do proper conditional building in a single project instead of needing to split?
    Damian Reeves
    @DamianReeves
    This has me thinking… do Shared Projects work with F#/Fable?
    Maxime Mangel
    @MangelMaxime

    Hello @Shmew , so I never used condition in a fsproj so I can't really say.

    The only condition I used is compiler directive directly into the code. #if FABLE_COMPILER

    Maxime Mangel
    @MangelMaxime

    @DamianReeves Perhaps, but I suppose Microsoft is the only one who can such things.

    Also, in the case of Thoth.Json I decided to split the package in order to keep the code easier to maintain and avoid having a #id .... #else ... #endif everywhere in the code.

    You can make your library required both Thoth.Json and Thoth.Json.Net as long as you choose the right one to use when calling them. For example, that's more or less what the shared libraries does.

    I have the project to make it easier to share the code but still haven't had the time to do it. Will require a major rewrite of the library for it to work
    Damian Reeves
    @DamianReeves
    So what you mean is I can include both and do something like the following in my code?
    #if FABLE_COMPILER
    open Thoth.Json
    #else
    open Thoth.Json.Net
    #end
    Maxime Mangel
    @MangelMaxime
    In theory yes
    Cody Johnson
    @Shmew
    @inosik the file is my web worker, I want to keep it in the same fsproj if possible so it can just open namespaces and such as needed. If I don't add this kind of compiler condition webpack via fable-loader always tries to bundle the file in and my app stops working
    it currently all works as expected, just that since I don't know what the value should actually be for the constant I have to use negation rather than affirmation of the constant's value
    which means the file doesn't show up in visual studio under the project which is really annoying
    Cody Johnson
    @Shmew
    and I'm sure it isn't used, because at the moment since I'm just testing it this is the file:
    module WorkerFunction
    
    let rng = System.Random()
    
    let sortNumbers () =
        Array.init 500000 (fun _ -> rng.NextDouble() * 1000000.)
        |> Array.sort
        |> Array.sum
        |> int
    apparently it properly shakes it off if it isn't the last .fs file in the project
    Maxime Mangel
    @MangelMaxime

    @Shmew Can't you add WEBPACK directive to your VS configuration.

    I think VS allows you to add compiler directive in the configuration of your project.

    Cody Johnson
    @Shmew
    yeah I've tried it, it wasn't helpful