Comments (4)
What's wrong with thenable promises?
from opensubtitles-api.
@vankasteelj nothing wrong with them, it's just a bit more readable IMO. One issue I have with them is the placement of return
statements throughout a function. In a long chain of then
s, especially when there are more nested then
s within it, it can get hard to follow the logic and starts to look similar to Callback Hell.
For example:
search(info) {
let subs = Array()
return this.login()
.then(() => libsearch.optimizeQueryTerms(info))
.then(optimizedQT => {
return Promise.all(optimizedQT.map(op => {
return this.api.SearchSubtitles(this.credentials.status.token, [op]).then(result => subs = subs.concat(result.data))
}))
})
.then(() => libsearch.optimizeSubs(subs, info))
.then(list => libsearch.filter(list, info))
}
The return
is up by the login step, but that's not what returns. It could be:
async search(info) {
let subs = Array()
await this.login()
const optimizedQT = await libsearch.optimizeQueryTerms(info)
await Promise.all(optimizedQT.map(op => {
return this.api.SearchSubtitles(this.credentials.status.token, [op]).then(result_1 => subs = subs.concat(result_1.data));
}))
const list = await libsearch.optimizeSubs(subs, info)
return await libsearch.filter(list, info)
}
which in my opinion is more easy to read and understand.
from opensubtitles-api.
Okay I get the point.
But that isn't readable to me, as I don't get what each term does and it seems counterintuitive (to me, I've never learned await/async. I write ugly js on my spare time so I have the tools I need, I'm not a programmer per se^^), so if I'm to maintain this, I need to follow my own logic.
from opensubtitles-api.
No problem, just a suggestion :)
from opensubtitles-api.
Related Issues (20)
- Don't save file utf-8 char set on local folder with DonwloadSubtitles method HOT 1
- It does not work HOT 5
- [Feature request ] VTT HOT 5
- typescript support HOT 2
- Why results on the API and on the OpenSubtitles portal not always match? HOT 2
- Supported in browsers? HOT 3
- How does GetAvailableTranslations work? HOT 1
- Suggestion: TypeScript HOT 2
- New NPM release HOT 2
- TypeScript type definitions HOT 4
- api limits 5 subtitles per request HOT 1
- Issue: vtt subtitle download not working HOT 4
- OpenSubtitles.search() not returning anything. HOT 11
- Make debug easier
- Episode title parsing TypeError
- TypeError: Cannot read property 'length' of undefined
- Typescript support not found. HOT 1
- Italian translation HOT 1
- Deprecation of XML RPC API by december 2023 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opensubtitles-api.