Giter Site home page Giter Site logo

bs-promise-monad's People

Contributors

alias-r avatar baldurh avatar digitake avatar glennsl avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

glennsl baldurh

bs-promise-monad's Issues

Returning errors

Can't seem to understand what this wants me to return;

type idTokenT = {
  idToken,
} and idToken = {jwtToken: string};

let decodeJwt = json => Json.Decode.{jwtToken: json |> field("jwtToken",string)}
let decodeToken = json => Json.Decode.{
  idToken: json |> field("idToken", decodeJwt),
};

type auth;
[@bs.module "@aws-amplify/auth/lib"] external auth: auth = "default";
[@bs.send] external getCurrentSession:(auth,unit)=> Js.Promise.t(Js.Json.t) = "currentSession";

let getJwtToken = () => {
    open PromiseMonad;
    getCurrentSession(auth,())
    >>= (response => {
        let jwtToken = decodeToken(response);
    Js.log(jwtToken);
    return(jwtToken);
  })
>>| (err => {
    let errMsg = err |> Js.Json.stringifyAny |> Js.Option.getWithDefault("");
    Js.log2("Failure!!", err);
    return(errMsg))
  });
};

This is the compiler error:

This has type:
    Js.Promise.t(Js.Promise.error) (defined as
      Js.Promise.t(Js.Promise.error))
  But somewhere wanted:
    Js.Promise.t(idTokenT) (defined as Js.Promise.t(idTokenT))

  The incompatible parts:
    Js.Promise.error (defined as Js.Promise.error)
    vs
    idTokenT

Any guidance would be appreciated. Thank you, sir.

Add auto-return for catch as well

Hi! Digging this stuff, makes it so much cleaner. I've added the following to mine just now:

let (>>/) = (m: Js.Promise.t('a), f: Js.Promise.error => 'a) => Js.Promise.catch(e => return(f(e)), m);

I would have made a PR, but the console is spewing errors at me when I try to compile and I'm not that familiar with Reason just yet :P

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.