Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Ugly Code

  • 29-12-2017 12:45am
    #1
    Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭


    I've been working away converting ES5 -> latest and greatest stuff and one thing I've noticed in a lot of the code are functions that simple say

    [HTML]function getAsset (url) {
    Api.get(url)
    }[/HTML]

    I don't know about anyone else but this gets annoying trying to trace down what exactly URL is especially within a startup environment where documentation is next to 0 on the API side. So I was doing some researching and ended up writing this.

    https://www.npmjs.com/package/fetch-rest-api-wrapper

    So my question and a debate I would like to have is how does everyone else write their API calls within their code, has everyone switched from Promises to Observables, do you think that using decorators with Typescript / Javascript is going to close to becoming Java or Python based in terms of writing code?


Comments

  • Registered Users, Registered Users 2 Posts: 6,289 ✭✭✭Talisman


    Promises are just sugar coated callbacks. A promise can only emit a single value or rejection - this is fine when you are dealing with a pull API.

    If you are dealing with a push API, you need some kind of subscription or notification mechanism for when a future value becomes available. In this scenario an observable is a better fit because it will execute every time a new value becomes available, so it can emit many values over time.


  • Registered Users, Registered Users 2 Posts: 1,298 ✭✭✭off.the.walls


    In total agreement I'm in the process of putting RxJS into the fetch-rest-api-wrapper so it can deal with subscriptions and use observables. Having a little trouble with the config / not having that much time now the holidays are over. Must take a saturday and get stuck into it!


Advertisement