Code Monkey home page Code Monkey logo

fable-promise's Introduction

Fable.Promise

Fable bindings for JS promise.

Before doing anything make sure to install the dependencies after cloning the repository by running:

npm install

How to test locally ?

npm run test

How to publish a new version of the package ?

npm run publish

How to work on the documentation ?

  1. npm run docs:watch
  2. Go to http://localhost:8080/

How to update the documentation ?

Deployment should be done automatically when pushing to dev branch.

If the CI is broken, you can manually deploy it by running npm run docs:deploy.

fable-promise's People

Contributors

alarbada avatar alfonsogarciacaro avatar angelmunoz avatar baronfel avatar delneg avatar dependabot[bot] avatar forki avatar mangelmaxime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fable-promise's Issues

Using Fable.Promise with Fable.SimpleJson causes fable compiler error

We were trying to update packages in Fable.SignalR and came across the following problem.

If only Fable.SimpleJson is used everything compiles fine, but as soon as Fable.Promise is added as nuget package the compilation fails with following output:

Fable 4.1.4: F# to JavaScript compiler
Minimum fable-library version (when installed from npm): 1.1.1

Thanks to the contributor! @cmeeren
Stand with Ukraine! https://standwithukraine.com.ua/

Parsing TestSimpleJson.fsproj...
.> cmd /C dotnet restore TestSimpleJson.csproj -p:FABLE_COMPILER=true -p:FABLE_COMPILER_4=true -p:FABLE_COMPILER_JAVASCRIPT=true
  Determining projects to restore...
  Restored C:\Users\leko.tomas\playground\TestSimpleJson\TestSimpleJson.csproj (in 207 ms).
Project and references (12 source files) parsed in 3833ms

Started Fable compilation...
Fable compilation finished in 3523ms

.\fable_modules\Fable.SimpleJson.3.24.0\SimpleJson.fs(6,12): (6,18) error FSHARP: The namespace 'Import' is not defined. (code 39)
Compilation failed

Here is a smallest repro I could make. TestSimpleJson

  • clone the repo
  • dotnet tool restore
  • dotnet fable .

We already found a similar issue here, but we couldn't find solution for this problem.

Error Handling Signatures

I was looking at some compiled JS code (due to a bug I had on a "catch" clause) and found out interestingly that fable-promise uses the form .then(success, error) way of handle exceptions
https://github.com/fable-compiler/fable-promise/blob/master/src/Promise.fs#L35-L45

usually the preferred form (afaik) is

.then(success).catch(error)

since this will allow exception bubbling (i.e. pass the exception to the next catch handler in the chain and so on until you get to the last) even if there's a throw inside .catch which sometimes is useful a graceful recovery and continue with async operations.

when you use .then(success, error) if the success handler throws or is rejected, the error handler will not be invoked, this rejection will be sent to the next .catch on the promise chain

I got an example here

https://codesandbox.io/s/promise-errors-cf439?file=/src/index.js

let me know if this is something we can look into I can try to save some time and send a PR later on

Some reading stuff on the matter (the first one is my always go-to resource)
https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html (tl;dr Advanced mistake 2)
https://dmitripavlutin.com/javascript-promises-then-vs-then-catch/#2-whats-the-difference

Feliz.Router.BasePath stopped navigation

After a dotnet paket update I noticed that navigation with Feliz.Router.BasePath stopped working, or better, the hook stopped setting a new state with the current page.

I was able to track it down to Fable.Promise 3.1. When I downgraded to 2.2.2, it worked again.

I still have no idea what is happening, and whether Feliz.Router or the React.useElmish hook is also affected.

What happened to Promise signatures ?

Description

While trying to port Ionide to Fable2 (Still with Fable.Core 2 but 3 seem to have the same problem) I remarked that the signatures of methods of Promise that were previously correct are now missing a big chunk of the functionalities.

Repro code

Let's read MDN and see what Promise.then handlers can do:

  • returns a value, the promise returned by then gets resolved with the returned value as its value;
  • doesn't return anything, the promise returned by then gets resolved with an undefined value;
  • returns an already fulfilled promise, the promise returned by then gets fulfilled with that promise's value as its value;

Ok Fable exposes the javascript API, so given the documentation I wound expect that handlers are 'TBefore -> U3<unit, 'TResult, PromiseLike<'TResult>> but that's not the case:

    and [<AllowNullLiteral>] Promise<'T> =
        abstract ``then``: ?onfulfilled: ('T->'TResult) * ?onrejected: (obj->'TResult) -> Promise<'TResult>

Expected and actual results

Expected: Being able to use JS Api in a typed way
Actual: unbox, unbox, unbox

Related information

  • Fable version: 2.3.7
  • Fable.Core: 2.0.3
  • Operating system: Windows 10

return! failwithf is broken in latest version

image

/home/gitlab-runner/builds/d5cd2d2a/0/a-team/eCarApp/src/Client/Utils.fs(42,22): error FS0041: Eine eindeutige Überladung für Methode 'Source' konnte nicht auf Basis von Typinformationen vor diesem Programmpunkt bestimmt werden. Unter Umständen ist eine Typanmerkung erforderlich.��Bekannter Argumenttyp: 'a��Kandidaten:� - member Promise.PromiseBuilder.Source : p:Fable.Core.JS.Promise<'T1> -> Fable.Core.JS.Promise<'T1>� - member Promise.PromiseBuilder.Source : ps:'a0 -> 'a0 when 'a0 :> seq<'a1> [/home/gitlab-runner/builds/d5cd2d2a/0/a-team/eCarApp/test/ComponentTests/ComponentTests.fsproj]

It says it wants a type hint. Why is that? This used to work.

Update to 3.1.1 is creating compile error

FSC : error FS0193: Das Modul bzw. der Namespace "Promise" aus der Kompilierungseinheit "Fable.Promise" enthielt nicht den Wert "ValLinkagePartialKey(Run)". [/home/gitlab-runner/builds/d5cd2d2a/0/a-team/eCarApp/src/Client/Client.fsproj]

Sorry for german error message. It says it can't find ValLinkagePartialKey

Add race helpers

See MDN. We could have something like:

let race2 (pr1: 'T1) (pr2: 'T2): Promise<Choice<'T1, 'T2>>
let race3 (pr1: 'T1) (pr2: 'T2) (pr3: 'T3): Promise<Choice<'T1, 'T2, 'T3>>
..

Don't publish 3.0.0-beta-001 as stable yet

@alfonsogarciacaro

When upgrading to version 3.0.0-beta-001 in my project, it make Fable compilation fails.

C:/Users/mamangel/Documents/Workspace/Gitlab/fleet-view/fleet-mapping/Medio/Server/Tests/fableBuild/.fable/Fable.Fetch.2.1.0/Fetch.fs(351,12): (351,23) error FSHARP: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved. (code 72)

Yes, the error in Fetch.fs and not fable-promise but that's actually fable-promise which make it fails because if I everything works fine.

Also, when compiling the project via dotnet build I don't have the error so I still trying to find the source of the error.

Support for `and!` (Applicative CE's)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.