origin-js icon indicating copy to clipboard operation
origin-js copied to clipboard

Async JS Guidelines

Open gaboesquivel opened this issue 7 years ago • 1 comments

At some point it will be good to define the Origin's async JS code style / guidelines.

Currently promises and async/await a being used. I personally tend to prefer await/async for readability, it usually requires less identation and less "cleverness" than promises.

For working with promises this is a great resource, has modular package for each need and with good feats like controlling concurrency on Promise.all https://github.com/sindresorhus/promise-fun Bluebird is nice too.

I get what we care about right now is functionality, however standards first is nice too have. It has it's maintainability benefits.

I've also found that error handling is less complex with try/catch await/async style than with chained promises .error() callbacks.

This is good lecture https://zeit.co/blog/async-and-await

gaboesquivel avatar May 12 '18 17:05 gaboesquivel

We are definitely standardizing on the async/await style over the callback style. The code is massively cleaner like this.

The Origin.js API does not present any callbacks to the user, just async/await style. Under the hood, we only use callbacks when talking with web3.js which uses them.

If we've got any leftover callbacks in the DApp, they could be switched over to async style.

DanielVF avatar May 14 '18 13:05 DanielVF